Replace the base authorization manager with an extended one with a runCallback method
This commit is contained in:
@@ -14,6 +14,7 @@ use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use UserFrosting\Sprinkle\Organisations\Database\Models\Interfaces\OrganisationInterface as OrganisationInterface;
|
||||
use UserFrosting\Sprinkle\Organisations\Authorize\AuthorizationManager;
|
||||
|
||||
/**
|
||||
* Registers services for the organisation sprinkle.
|
||||
@@ -51,6 +52,9 @@ class ServicesProvider
|
||||
* @return \UserFrosting\Sprinkle\Core\Util\ClassMapper
|
||||
*/
|
||||
$container->extend('authorizer', function ($authorizer, $c) {
|
||||
|
||||
$new_authorizer = new AuthorizationManager($c, $authorizer->getCallbacks());
|
||||
|
||||
/*
|
||||
* Check if all $user is a member of $organisation.
|
||||
*
|
||||
@@ -58,7 +62,7 @@ class ServicesProvider
|
||||
* @param int $organisation_id the id of the target organisation.
|
||||
* @return bool true if $user is a member of $organisation.
|
||||
*/
|
||||
$authorizer->addCallback('is_organisation_member', function ($user_id, $organisation_id) {
|
||||
$new_authorizer->addCallback('is_organisation_member', function ($user_id, $organisation_id) {
|
||||
return Capsule::table('organisation_members')
|
||||
->where('user_id', $user_id)
|
||||
->where('organisation_id', $organisation_id)
|
||||
@@ -72,15 +76,15 @@ class ServicesProvider
|
||||
* @param int $organisation_id the id of the target organisation.
|
||||
* @return bool true if $user is an administrator of $organisation.
|
||||
*/
|
||||
$authorizer->addCallback('is_organisation_admin', function ($user_id, $organisation_id) {
|
||||
$new_authorizer->addCallback('is_organisation_admin', function ($user_id, $organisation_id) {
|
||||
return Capsule::table('organisation_members')
|
||||
->where('user_id', $user_id)
|
||||
->where('organisation_id', $organisation_id)
|
||||
->where('flag_admin', true)
|
||||
->count() > 0;
|
||||
});
|
||||
|
||||
return $authorizer;
|
||||
|
||||
return $new_authorizer;
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user