Skip to content
Snippets Groups Projects
Commit 6e15a2bc authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

add user lookup filter for roles and use that for auto inserting, fixes #2029

Closes #2029

Merge request studip/studip!1323
parent 99e6757b
No related branches found
No related tags found
No related merge requests found
......@@ -157,7 +157,6 @@ class Admin_AutoinsertController extends AuthenticatedController
PageLayout::postError(_('Keine Filterkriterien gewählt'));
} else {
$seminar = Seminar::GetInstance(Request::option('sem_id'));
$group = select_group($seminar->getSemesterStartTime());
$userlookup = new UserLookup();
foreach ($filters as $type => $values) {
......@@ -231,7 +230,8 @@ class Admin_AutoinsertController extends AuthenticatedController
'fachsemester' => _('Studienfachsemester'),
'institut' => _('Einrichtung'),
'status' => _('Statusgruppe'),
'domain' => _('Domäne')
'domain' => _('Domäne'),
'role' => _('Rolle'),
];
$links = new ActionsWidget();
......
......@@ -89,7 +89,7 @@ class AutoInsert
/**
* Trägt den Benutzer in den Eingestellten veranstaltungen automatisch ein.
* @param string $user_id
* @param bool $status Wenn Status nicht angegeben wird, wird der Status des Users aus user_id genommen
* @param string|bool $status Wenn Status nicht angegeben wird, wird der Status des Users aus user_id genommen
* @return array 'added' Namen der Seminare in die der User eingetragen wurde
* array 'removed' Namen der Seminare aus denen der User ausgetragen wurde
*/
......@@ -112,7 +112,6 @@ class AutoInsert
$key = $domain . '.' . $status;
if (is_array($this->settings[$key])) {
$id = key($this->settings[$key]);
foreach ($this->settings[$key] as $id => $value) {
$settings[$id] = $value;
}
......@@ -241,13 +240,15 @@ class AutoInsert
* Removes a seminar from the autoinsertion process.
* @param string $seminar_id Id of the seminar
*/
public static function deleteSeminar($seminar_id)
public static function deleteSeminar($seminar_id): bool
{
$query = "DELETE FROM auto_insert_sem WHERE seminar_id = ?";
$statement = DBManager::get()->prepare($query);
$statement->execute([$seminar_id]);
$result = $statement->execute([$seminar_id]);
unset(self::getSeminarCache()[$seminar_id]);
return $result > 0;
}
/**
......
......@@ -67,8 +67,12 @@ class UserLookup
'values' => 'UserLookup::statusValues',
],
'domain' => [
'filter' =>'UserLookup::domainFilter',
'values' =>'UserLookup::domainValues'
'filter' => 'UserLookup::domainFilter',
'values' => 'UserLookup::domainValues',
],
'role' => [
'filter' => 'UserLookup::roleFilter',
'values' => 'UserLookup::roleValues',
],
];
......@@ -457,4 +461,43 @@ class UserLookup
return $domains;
}
/**
* Return all users with a matching assigned role given in $needles
*
* @param array $needles List of domain ids to filter against
* @return array List of user ids matching the given filter
*/
protected static function roleFilter($needles): array
{
if (!$needles) {
return [];
}
$user_ids = [];
foreach ($needles as $role_id) {
$users = RolePersistence::getUsersWithRoleById($role_id, false);
foreach ($users as $user) {
$user_ids[$user->id] = $user->id;
}
}
return array_values($user_ids);
}
/**
* Return all valid roles
*
* @return array Associative array of domain id and name
*/
protected static function roleValues(): array
{
$roles = [];
$roles['keine'] = _('Ohne Rollenzuweisung');
foreach (RolePersistence::getAllRoles() as $role) {
$roles[$role->getRoleid()] = $role->getRolename();
}
return $roles;
}
}
......@@ -22,6 +22,7 @@ class RolePersistence
/**
* Returns all available roles.
*
* @param bool $grouped Return the roles grouped by system type or other
* @return Role[]|array{system: Role[], other: Role[]}
*/
public static function getAllRoles(bool $grouped = false): array
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment