@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param $event Event; |
91 | 91 | */ |
92 | 92 | |
93 | - public function beforeSave($event){ |
|
93 | + public function beforeSave($event) { |
|
94 | 94 | $this->protectAttributes(); |
95 | 95 | } |
96 | 96 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute) |
110 | 110 | continue; |
111 | 111 | |
112 | - if(!$this->isAuthorised($user, $attribute, $value)){ |
|
112 | + if (!$this->isAuthorised($user, $attribute, $value)) { |
|
113 | 113 | $this->createConfirmationRequest(); |
114 | 114 | $this->resetAttribute($attribute); |
115 | 115 | } |
@@ -124,17 +124,17 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return bool |
126 | 126 | */ |
127 | - protected function isAuthorised($user, $attribute, $value){ |
|
127 | + protected function isAuthorised($user, $attribute, $value) { |
|
128 | 128 | |
129 | 129 | //Check for pre-defined administration roles |
130 | 130 | if ($this->userIsAuthorised($user)) |
131 | 131 | return true; |
132 | 132 | |
133 | 133 | //Check for valid release token , eg that the token exists and is for the same record as this |
134 | - if($this->releaseToken != null){ |
|
135 | - $confirmation = ConfirmationRequest::findOne(['release_token' => $this->releaseToken]); |
|
134 | + if ($this->releaseToken != null) { |
|
135 | + $confirmation = ConfirmationRequest::findOne(['release_token' => $this->releaseToken]); |
|
136 | 136 | |
137 | - if($confirmation == null) |
|
137 | + if ($confirmation == null) |
|
138 | 138 | return false; |
139 | 139 | |
140 | 140 | $model = $confirmation->constructObject(); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | //Check to see if any protected attributes have been altered |
147 | 147 | foreach ($this->protectedAttributes as $attribute) |
148 | - if($this->hasChanged($attribute)) |
|
148 | + if ($this->hasChanged($attribute)) |
|
149 | 149 | return false; |
150 | 150 | |
151 | 151 | return true; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return bool |
159 | 159 | */ |
160 | - protected function userIsAuthorised($user){ |
|
160 | + protected function userIsAuthorised($user) { |
|
161 | 161 | foreach ($this->allow as $role) |
162 | - if($user->can($role)) |
|
162 | + if ($user->can($role)) |
|
163 | 163 | return true; |
164 | 164 | |
165 | 165 | return false; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * Business logic handling the creation of the Confirmation Request, and sending the second factor message. |
170 | 170 | */ |
171 | - protected function createConfirmationRequest(){ |
|
171 | + protected function createConfirmationRequest() { |
|
172 | 172 | |
173 | 173 | $model = $this->owner; |
174 | 174 | $changedValues = $this->getChangedValues(); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return bool |
195 | 195 | */ |
196 | - protected function hasChanged($attribute){ |
|
196 | + protected function hasChanged($attribute) { |
|
197 | 197 | return $this->owner->oldAttributes[$attribute] != $this->owner->{$attribute}; |
198 | 198 | } |
199 | 199 | |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | * Fetches all values which have changed, expect for the timestamp attribute. |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function getChangedValues(){ |
|
204 | + public function getChangedValues() { |
|
205 | 205 | $changedAttributes = []; |
206 | 206 | |
207 | 207 | foreach ($this->owner->attributes() as $attribute) |
208 | - if($this->hasChanged($attribute)) |
|
208 | + if ($this->hasChanged($attribute)) |
|
209 | 209 | $changedAttributes[$attribute] = $this->owner->$attribute; |
210 | 210 | |
211 | 211 | unset($changedAttributes[$this->timestampAttribute]); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * Sets an attribute back to it's original value when it was fetched. |
218 | 218 | * @param string $attribute |
219 | 219 | */ |
220 | - protected function resetAttribute($attribute){ |
|
220 | + protected function resetAttribute($attribute) { |
|
221 | 221 | $this->owner->$attribute = $this->owner->oldAttributes[$attribute]; |
222 | 222 | } |
223 | 223 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * Adds a flash message to the interface stating the change has been held over pending confirmation. |
226 | 226 | * @param $model |
227 | 227 | */ |
228 | - public function createFeedbackMessage($model){ |
|
228 | + public function createFeedbackMessage($model) { |
|
229 | 229 | $this->displayMessage($model); |
230 | 230 | } |
231 | 231 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * Business logic around displaying an appropriate feedback message to the user regbarding the change. |
234 | 234 | * @param $model |
235 | 235 | */ |
236 | - protected function displayMessage($model){ |
|
236 | + protected function displayMessage($model) { |
|
237 | 237 | Yii::$app->session->setFlash('warning', 'Your update is pending confirmation. Please check your email for a confirmation link.'); |
238 | 238 | } |
239 | 239 | |
@@ -241,8 +241,8 @@ discard block |
||
241 | 241 | * Business logic around transmitting the second factor message. |
242 | 242 | * @param ConfirmationRequest $model |
243 | 243 | */ |
244 | - public function sendSecondFactorMessage($model){ |
|
245 | - switch ($this->secondFactor){ |
|
244 | + public function sendSecondFactorMessage($model) { |
|
245 | + switch ($this->secondFactor) { |
|
246 | 246 | case 'email': |
247 | 247 | Yii::$app->mailer |
248 | 248 | ->compose($this->confirmationViewPath, ['model' => $model]) |
@@ -265,29 +265,29 @@ discard block |
||
265 | 265 | * @return string |
266 | 266 | * @throws InvalidCallException |
267 | 267 | */ |
268 | - protected function getEmail($model){ |
|
268 | + protected function getEmail($model) { |
|
269 | 269 | |
270 | 270 | $values = unserialize($model->values); |
271 | - $email = ArrayHelper::getValue($values,'email'); |
|
271 | + $email = ArrayHelper::getValue($values, 'email'); |
|
272 | 272 | $object = $model->constructObject(); |
273 | 273 | |
274 | - if($email == null){ |
|
275 | - $email = ArrayHelper::getValue($values,'email_address'); |
|
274 | + if ($email == null) { |
|
275 | + $email = ArrayHelper::getValue($values, 'email_address'); |
|
276 | 276 | } |
277 | 277 | |
278 | - if($email == null){ |
|
279 | - $email = ArrayHelper::getValue($object,'email'); |
|
278 | + if ($email == null) { |
|
279 | + $email = ArrayHelper::getValue($object, 'email'); |
|
280 | 280 | } |
281 | 281 | |
282 | - if($email == null){ |
|
283 | - $email = ArrayHelper::getValue($object,'email_address'); |
|
282 | + if ($email == null) { |
|
283 | + $email = ArrayHelper::getValue($object, 'email_address'); |
|
284 | 284 | } |
285 | 285 | |
286 | - if($email == null){ |
|
287 | - $email = ArrayHelper::getValue($object,$this->createdByAttribute.'.email'); |
|
286 | + if ($email == null) { |
|
287 | + $email = ArrayHelper::getValue($object, $this->createdByAttribute . '.email'); |
|
288 | 288 | } |
289 | 289 | |
290 | - if($email == null){ |
|
290 | + if ($email == null) { |
|
291 | 291 | throw new InvalidCallException('Unable to locate email address via record, changed values, or user account'); |
292 | 292 | } |
293 | 293 |
@@ -106,8 +106,9 @@ discard block |
||
106 | 106 | |
107 | 107 | foreach ($changedValues as $attribute => $value) { |
108 | 108 | |
109 | - if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute) |
|
110 | - continue; |
|
109 | + if ($this->skipOnNull && $value === null || $attribute == $this->timestampAttribute) { |
|
110 | + continue; |
|
111 | + } |
|
111 | 112 | |
112 | 113 | if(!$this->isAuthorised($user, $attribute, $value)){ |
113 | 114 | $this->createConfirmationRequest(); |
@@ -127,15 +128,17 @@ discard block |
||
127 | 128 | protected function isAuthorised($user, $attribute, $value){ |
128 | 129 | |
129 | 130 | //Check for pre-defined administration roles |
130 | - if ($this->userIsAuthorised($user)) |
|
131 | - return true; |
|
131 | + if ($this->userIsAuthorised($user)) { |
|
132 | + return true; |
|
133 | + } |
|
132 | 134 | |
133 | 135 | //Check for valid release token , eg that the token exists and is for the same record as this |
134 | 136 | if($this->releaseToken != null){ |
135 | 137 | $confirmation = ConfirmationRequest::findOne(['release_token' => $this->releaseToken]); |
136 | 138 | |
137 | - if($confirmation == null) |
|
138 | - return false; |
|
139 | + if($confirmation == null) { |
|
140 | + return false; |
|
141 | + } |
|
139 | 142 | |
140 | 143 | $model = $confirmation->constructObject(); |
141 | 144 | |
@@ -144,9 +147,10 @@ discard block |
||
144 | 147 | } |
145 | 148 | |
146 | 149 | //Check to see if any protected attributes have been altered |
147 | - foreach ($this->protectedAttributes as $attribute) |
|
148 | - if($this->hasChanged($attribute)) |
|
150 | + foreach ($this->protectedAttributes as $attribute) { |
|
151 | + if($this->hasChanged($attribute)) |
|
149 | 152 | return false; |
153 | + } |
|
150 | 154 | |
151 | 155 | return true; |
152 | 156 | } |
@@ -158,9 +162,10 @@ discard block |
||
158 | 162 | * @return bool |
159 | 163 | */ |
160 | 164 | protected function userIsAuthorised($user){ |
161 | - foreach ($this->allow as $role) |
|
162 | - if($user->can($role)) |
|
165 | + foreach ($this->allow as $role) { |
|
166 | + if($user->can($role)) |
|
163 | 167 | return true; |
168 | + } |
|
164 | 169 | |
165 | 170 | return false; |
166 | 171 | } |
@@ -204,9 +209,10 @@ discard block |
||
204 | 209 | public function getChangedValues(){ |
205 | 210 | $changedAttributes = []; |
206 | 211 | |
207 | - foreach ($this->owner->attributes() as $attribute) |
|
208 | - if($this->hasChanged($attribute)) |
|
212 | + foreach ($this->owner->attributes() as $attribute) { |
|
213 | + if($this->hasChanged($attribute)) |
|
209 | 214 | $changedAttributes[$attribute] = $this->owner->$attribute; |
215 | + } |
|
210 | 216 | |
211 | 217 | unset($changedAttributes[$this->timestampAttribute]); |
212 | 218 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | [['object_id'], 'integer'], |
52 | 52 | [['object', 'values'], 'string'], |
53 | 53 | [['model', 'release_token'], 'string', 'max' => 255], |
54 | - [['release_token'], 'default', 'value' => function ($model, $attribute){ return $this->generateReleaseToken();}], |
|
54 | + [['release_token'], 'default', 'value' => function($model, $attribute) { return $this->generateReleaseToken(); }], |
|
55 | 55 | [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['created_by' => 'id']], |
56 | 56 | [['updated_by'], 'exist', 'skipOnError' => true, 'targetClass' => $this->getUserClassName(), 'targetAttribute' => ['updated_by' => 'id']], |
57 | 57 | ]; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | ]); |
98 | 98 | } |
99 | 99 | |
100 | - public function getViewLink(){ |
|
101 | - return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token],true); |
|
100 | + public function getViewLink() { |
|
101 | + return Url::to(['@web/confirmation-requests', 'release_token' => $this->release_token], true); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | /** |
130 | 130 | * @return string ActiveRecord user class, as per application implementation |
131 | 131 | */ |
132 | - protected function getUserClassName(){ |
|
132 | + protected function getUserClassName() { |
|
133 | 133 | return Yii::$app->user->identityClass; |
134 | 134 | } |
135 | 135 | |
136 | - public function release(){ |
|
136 | + public function release() { |
|
137 | 137 | |
138 | 138 | $model = $this->constructObject(); |
139 | 139 | $changedValues = $model->getChangedValues(); |
140 | 140 | $current = clone $model; |
141 | 141 | $current->refresh(); |
142 | 142 | |
143 | - foreach ($changedValues as $field => $value){ |
|
143 | + foreach ($changedValues as $field => $value) { |
|
144 | 144 | $oldValue = $model->oldAttributes[$field]; |
145 | - if($current->$field !== $oldValue && $current->$field !== $value){ |
|
145 | + if ($current->$field !== $oldValue && $current->$field !== $value) { |
|
146 | 146 | throw new ErrorException( |
147 | 147 | sprintf('Unable to release change, protected field %s has been updated since this request.' |
148 | 148 | . ' Expected to find %s or %s, found %s', $field, $value, $oldValue, $current->$field)); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | /** |
160 | 160 | * @return \enigmatix\core\Model |
161 | 161 | */ |
162 | - public function constructObject(){ |
|
162 | + public function constructObject() { |
|
163 | 163 | return unserialize($this->object); |
164 | 164 | } |
165 | 165 |