Compare commits
1 Commits
4f8c26fc66
...
v1.0.4a
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a2e59a7e1 |
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace UserFrosting\Sprinkle\UFTweaks\ServicesProvider;
|
namespace UserFrosting\Sprinkle\UFTweaks\ServicesProvider;
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
use Monolog\Formatter\LineFormatter;
|
use Monolog\Formatter\LineFormatter;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@@ -150,6 +151,25 @@ class ServicesProvider
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if the specified user (by user_id) has a particular permission.
|
||||||
|
*
|
||||||
|
* @param int $user_id the id of the user.
|
||||||
|
* @param int $permission_slug slug of the permission to check.
|
||||||
|
* @return bool true if the user has the permission, false otherwise.
|
||||||
|
*/
|
||||||
|
$authorizer->addCallback(
|
||||||
|
'has_permission',
|
||||||
|
function ($user_id, $permission_slug) {
|
||||||
|
return Capsule::table('role_users')
|
||||||
|
->join('permission_roles', 'role_users.role_id', '=', 'permission_roles.role_id')
|
||||||
|
->join('permissions', 'permission_roles.permission_id', '=', 'permissions.id')
|
||||||
|
->where('user_id', $user_id)
|
||||||
|
->where('slug', $permission_slug)
|
||||||
|
->count() > 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return $authorizer;
|
return $authorizer;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user