Skip to content

Commit 9765ff1

Browse files
committed
Fixing checkPermissions method
1 parent 5c4397d commit 9765ff1

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/models/User.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,35 @@ public function resetPreferenceToDefault($id)
258258
* @param $keyName The keyname of the action you are checking
259259
* @return bool
260260
*/
261-
public function checkPermission($actions)
261+
public function checkPermission($actions, $matchAll = false)
262262
{
263263
if (Auth::user()->roles->contains(\BaseModel::ROLE_DEVELOPER)) {
264264
return true;
265265
}
266266

267-
// If the user has the permission or is a developer return true.
268-
return in_array($actions, $this->actions->keyName->toArray() );
267+
if (!is_array($actions)) {
268+
$actions = array($actions);
269+
}
270+
271+
$matchedActions = 0;
272+
273+
if ($this->actions && $this->actions->count() > 0) {
274+
$userActions = $this->actions->keyName->toArray();
275+
276+
foreach ($actions as $action) {
277+
if (in_array($action, $userActions)) {
278+
if (!$matchAll) {
279+
return true;
280+
}
281+
282+
$matchedActions++;
283+
}
284+
}
285+
286+
if ($matchedActions) {
287+
if (count($actions) == $matchedActions) return true;
288+
}
289+
}
269290

270291
return false;
271292
}

0 commit comments

Comments
 (0)