Added a has_organisation authorizer check

This commit is contained in:
2023-07-18 13:28:50 +01:00
parent 7f9d329295
commit 85b1cec060

View File

@@ -59,6 +59,20 @@ class ServicesProvider
* @return \UserFrosting\Sprinkle\Core\Util\ClassMapper
*/
$container->extend('authorizer', function ($authorizer, $c) {
/*
* Check if all $user has an $organisation.
*
* @param int $user_id the id of the requesting user (normally currentUser->id).
* @return bool true if $user is a verified member of any organisation.
*/
$authorizer->addCallback('has_organisation', function ($user_id) {
$query = Capsule::table('organisation_members')
->where('user_id', $user_id)
->where('flag_approved', true);
return $query->count() > 0;
});
/*
* Check if all $user is a member of $organisation.
*