Skip to content

Commit

Permalink
[GT-182] Add restriction on who can create SG's
Browse files Browse the repository at this point in the history
  • Loading branch information
Sae126V committed Sep 11, 2023
1 parent 6cd738d commit a50e258
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
/*====================================================== */
use Exception;

require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
require_once __DIR__ . '/../../components/Get_User_Principle.php';
require_once __DIR__ . '/../utils.php';
Expand Down Expand Up @@ -74,9 +76,23 @@ function draw($user) {
throw new \Exception("Unregistered users can't create service groups.");
}

$hasAdminCredentials = $user->isAdmin();
$roleService = \Factory::getRoleService();
$userRoles = $roleService->getUserRoles($user);

$isUserValid = $hasAdminCredentials ? true : !empty($userRoles);

if (!$isUserValid) {
throw new Exception(
"You do not have permission to add a new "
. "Service Group. To add a new Service Group, you require "
. "atleast one role assigned over an entity in GOCDB."
);
}

// can user assign reserved scopes ?
$disableReservedScopes = true;
if ($user->isAdmin()) {
if ($hasAdminCredentials) {
$disableReservedScopes = false;
}

Expand Down

0 comments on commit a50e258

Please sign in to comment.