Skip to content

Commit

Permalink
Allow Service Group level roles to be created
Browse files Browse the repository at this point in the history
- creates new file to allow the creation of service group level roles
- adds new file to DeploySampleDataRunner
  • Loading branch information
rowan04 committed Aug 17, 2023
1 parent b99687f commit 899b061
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
86 changes: 86 additions & 0 deletions lib/Doctrine/deploy/AddServiceGroupRoles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

require_once __DIR__."/../bootstrap.php";
require_once __DIR__."/AddUtils.php";

$usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml";
$usersRoles = simplexml_load_file($usersRolesFileName);

foreach($usersRoles as $user) {
foreach($user->USER_ROLE as $role) {
// Check for blank role, skip if it's blank
if((string) $role->USER_ROLE == "") {
continue;
}

// Skip all non-serviceGroup roles
if ((string) $role->ENTITY_TYPE !== "serviceGroup") {
continue;
}

// get roletype entity
$userRole = (string) $role->USER_ROLE;
$dql = "SELECT rt FROM RoleType rt WHERE rt.name = :roleType";
$roleTypes = $entityManager->createQuery($dql)
->setParameter(':roleType', $userRole)
->getResult();

/*
* Error checking: ensure each role type refers to exactly
* one role type
*/
if(count($roleTypes) !== 1) {
throw new Exception(count($roleTypes) . " role types found with name: " .
$userRole);
}

foreach($roleTypes as $result) {
$roleType = $result;
}

// Get user entity
$userDN = (string) $user->CERTDN;
$dql = "SELECT u FROM User u JOIN u.userIdentifiers up WHERE up.keyValue = :keyValue";
$users = $entityManager->createQuery($dql)
->setParameter('keyValue', trim($userDN))
->getResult();

/*
* Error checking: ensure each "user" refers to exactly
* one user
*/
if(count($users) !== 1) {
throw new Exception(count($users) . " users found with DN: " .
$userDN);
}

foreach($users as $doctrineUser) {
$doctrineUser = $doctrineUser;
}

// get serviceGroup entity
$sgName = (string) $role->ON_ENTITY;
$dql = "SELECT sg FROM ServiceGroup sg WHERE sg.name = :service_group";
$serviceGroups = $entityManager->createQuery($dql)
->setParameter('service_group', $sgName)
->getResult();

/*
* Error checking: ensure each "service group" refers to exactly
* one service group
*/
if(count($serviceGroups) !== 1) {
throw new Exception(count($serviceGroups) . " Service Groups found name: " .
$sgName);
}

foreach($serviceGroups as $serviceGroup) {
$serviceGroup = $serviceGroup;
}

$doctrineRole = new Role($roleType, $doctrineUser, $serviceGroup, 'STATUS_GRANTED');
$entityManager->persist($doctrineRole);
}
}

$entityManager->flush();
3 changes: 3 additions & 0 deletions lib/Doctrine/deploy/DeploySampleDataRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@

require __DIR__."/AddProjectRoles.php";
echo "Added EGI level Roles OK\n";

require __DIR__."/AddServiceGroupRoles.php";
echo "Added Service Group level Roles OK\n";

0 comments on commit 899b061

Please sign in to comment.