From 85b1cec060d34197895f354ce81ed0a981f0b98d Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 18 Jul 2023 13:28:50 +0100 Subject: [PATCH] Added a has_organisation authorizer check --- src/ServicesProvider/ServicesProvider.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ServicesProvider/ServicesProvider.php b/src/ServicesProvider/ServicesProvider.php index ff65fed..9cce2f1 100644 --- a/src/ServicesProvider/ServicesProvider.php +++ b/src/ServicesProvider/ServicesProvider.php @@ -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. *