|
@@ 80-107 (lines=28) @@
|
| 77 |
|
* @param \SS_HTTPRequest $request |
| 78 |
|
* @return \SS_HTTPResponse |
| 79 |
|
*/ |
| 80 |
|
public function approve(SS_HTTPRequest $request) { |
| 81 |
|
if ($request->httpMethod() !== 'POST') { |
| 82 |
|
return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
$deployment = DNDeployment::get()->byId($request->param('ID')); |
| 86 |
|
$errorResponse = $this->validateDeployment($deployment); |
| 87 |
|
if ($errorResponse instanceof \SS_HTTPResponse) { |
| 88 |
|
return $errorResponse; |
| 89 |
|
} |
| 90 |
|
if (!$this->canApprove()) { |
| 91 |
|
return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
try { |
| 95 |
|
$deployment->getMachine()->apply(DNDeployment::TR_APPROVE); |
| 96 |
|
} catch (\Exception $e) { |
| 97 |
|
return $this->getAPIResponse([ |
| 98 |
|
'status' => 'FAILED', |
| 99 |
|
'message' => $e->getMessage() |
| 100 |
|
], 400); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
return $this->getAPIResponse([ |
| 104 |
|
'status' => 'OK', |
| 105 |
|
'id' => $deployment->ID |
| 106 |
|
], 200); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
/** |
| 110 |
|
* @param \SS_HTTPRequest $request |
|
@@ 113-142 (lines=30) @@
|
| 110 |
|
* @param \SS_HTTPRequest $request |
| 111 |
|
* @return \SS_HTTPResponse |
| 112 |
|
*/ |
| 113 |
|
public function reject(SS_HTTPRequest $request) { |
| 114 |
|
if ($request->httpMethod() !== 'POST') { |
| 115 |
|
return $this->getAPIResponse(['message' => 'Method not allowed, requires POST'], 405); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
$deployment = DNDeployment::get()->byId($request->param('ID')); |
| 119 |
|
$errorResponse = $this->validateDeployment($deployment); |
| 120 |
|
if ($errorResponse instanceof \SS_HTTPResponse) { |
| 121 |
|
return $errorResponse; |
| 122 |
|
} |
| 123 |
|
// can reject permissions are the same as can approve |
| 124 |
|
if (!$this->canApprove()) { |
| 125 |
|
return $this->getAPIResponse(['message' => 'You are not authorised to reject this deployment'], 403); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
try { |
| 129 |
|
$deployment->getMachine()->apply(DNDeployment::TR_REJECT); |
| 130 |
|
} catch (\Exception $e) { |
| 131 |
|
return $this->getAPIResponse([ |
| 132 |
|
'status' => 'FAILED', |
| 133 |
|
'message' => $e->getMessage() |
| 134 |
|
], 400); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
return $this->getAPIResponse([ |
| 138 |
|
'status' => 'OK', |
| 139 |
|
'message' => 'Deployment has been rejected', |
| 140 |
|
'id' => $deployment->ID, |
| 141 |
|
], 200); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
/** |
| 145 |
|
* Check if a DNDeployment exists and do permission checks on it. If there is something wrong it will return |