Allow users to see their own organisation pages
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace UserFrosting\Sprinkle\Organisations\ServicesProvider;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
@@ -38,10 +39,49 @@ class ServicesProvider
|
||||
$container->extend('classMapper', function ($classMapper, $c) {
|
||||
$classMapper->setClassMapping('organisation', 'UserFrosting\Sprinkle\Organisations\Database\Models\Organisation');
|
||||
$classMapper->setClassMapping('organisation_sprunje', 'UserFrosting\Sprinkle\Organisations\Sprunje\OrganisationSprunje');
|
||||
$classMapper->setClassMapping('user', 'UserFrosting\Sprinkle\Organisations\Database\Models\User');
|
||||
$classMapper->setClassMapping('user_sprunje', 'UserFrosting\Sprinkle\Organisations\Sprunje\UserSprunje');
|
||||
|
||||
return $classMapper;
|
||||
});
|
||||
|
||||
/*
|
||||
* Extend the 'authorizer' service to add extra access condition callbacks.
|
||||
*
|
||||
* @return \UserFrosting\Sprinkle\Core\Util\ClassMapper
|
||||
*/
|
||||
$container->extend('authorizer', function ($authorizer, $c) {
|
||||
/*
|
||||
* Check if all $user is a member of $organisation.
|
||||
*
|
||||
* @param int $user_id the id of the requesting user (normally currentUser->id).
|
||||
* @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) {
|
||||
return Capsule::table('organisation_members')
|
||||
->where('user_id', $user_id)
|
||||
->where('organisation_id', $organisation_id)
|
||||
->count() > 0;
|
||||
});
|
||||
|
||||
/*
|
||||
* Check if all $user is an administrator of $organisation.
|
||||
*
|
||||
* @param int $user_id the id of the requesting user (normally currentUser->id).
|
||||
* @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) {
|
||||
return Capsule::table('organisation_members')
|
||||
->where('user_id', $user_id)
|
||||
->where('organisation_id', $organisation_id)
|
||||
->where('flag_admin', true)
|
||||
->count() > 0;
|
||||
});
|
||||
|
||||
return $authorizer;
|
||||
});
|
||||
|
||||
/*
|
||||
* Returns a callback that handles merging any organisation objects.
|
||||
@@ -79,6 +119,5 @@ class ServicesProvider
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user