Skip to content

Commit

Permalink
TMS StudyProgramme: 8290 add new config option search recursive
Browse files Browse the repository at this point in the history
TMS StudyProgramme: 8290 be secure there is a tree path

TMS OrgUnit: 8290 move position events after action is executed

TMS StudyProgramme: 8290 check on automatism euqlas sry is not necessary

TMS StudyProgramme: 8291 use assignment of process to check user should be removed or not
  • Loading branch information
shecken authored and klees committed Aug 23, 2024
1 parent 63bd058 commit ebe4db7
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

class ilStudyProgrammeAutoMembershipTableUpdateSteps implements ilDatabaseUpdateSteps
{
public const TABLE_NAME = 'prg_auto_membership';

protected ilDBInterface $db;

public function prepare(ilDBInterface $db): void
{
$this->db = $db;
}

public function step_1(): void
{
$this->db->addTableColumn(
self::TABLE_NAME,
'search_recursive',
[
'type' => 'integer',
'length' => 1,
'default' => 0,
'notnull' => false
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public function getChildren(bool $include_references = false): array
array_unique(
array_map(
static function ($data) {
return (int)$data['child'];
return (int) $data['child'];
},
array_filter($ref_child_ref_ids, static function ($data) {
return $data["deleted"] === null;
Expand Down Expand Up @@ -1351,11 +1351,21 @@ public function getAutomaticMembershipSources(): array
/**
* Store a source to be monitored for automatic memberships.
*/
public function storeAutomaticMembershipSource(string $type, int $src_id): void
// cat-tms-patch start #8290
public function storeAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive): void
{
$ams = $this->auto_memberships_repository->create($this->getId(), $type, $src_id, false);
$ams = $this->auto_memberships_repository->create(
$this->getId(),
$type,
$src_id,
false,
null,
null,
$search_recursive
);
$this->auto_memberships_repository->update($ams);
}
// cat-tms-patch end #8290

/**
* Delete a membership source.
Expand All @@ -1376,17 +1386,26 @@ public function deleteAllAutomaticMembershipSources(): void
/**
* Disable a membership source.
*/
public function disableAutomaticMembershipSource(string $type, int $src_id): void
// cat-tms-patch start #8290
public function disableAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive): void
{
$ams = $this->auto_memberships_repository->create($this->getId(), $type, $src_id, false);
$ams = $this->auto_memberships_repository->create(
$this->getId(),
$type,
$src_id,
false,
null,
null,
$search_recursive
);
$this->auto_memberships_repository->update($ams);
}

/**
* Enable a membership source.
* @throws ilException
*/
public function enableAutomaticMembershipSource(string $type, int $src_id, bool $assign_now = false): void
public function enableAutomaticMembershipSource(string $type, int $src_id, bool $search_recursive, $assign_now = false): void
{
if ($assign_now) {
$assigned_by = ilStudyProgrammeAutoMembershipSource::SOURCE_MAPPING[$type];
Expand All @@ -1397,7 +1416,15 @@ public function enableAutomaticMembershipSource(string $type, int $src_id, bool
}
}
}
$ams = $this->auto_memberships_repository->create($this->getId(), $type, $src_id, true);
$ams = $this->auto_memberships_repository->create(
$this->getId(),
$type,
$src_id,
true,
null,
null,
$search_recursive
);
$this->auto_memberships_repository->update($ams);
}

Expand All @@ -1406,12 +1433,12 @@ public function enableAutomaticMembershipSource(string $type, int $src_id, bool
* @return int[]
* @throws InvalidArgumentException if $src_type is not in AutoMembershipSource-types
*/
protected function getMembersOfMembershipSource(string $src_type, int $src_id): array
protected function getMembersOfMembershipSource(ilStudyProgrammeAutoMembershipSource $ams): array
{
$source_reader = $this->membersourcereader_factory->getReaderFor($src_type, $src_id);
$source_reader = $this->membersourcereader_factory->getReaderFor($ams);
return $source_reader->getMemberIds();
}

// cat-tms-patch end #8290

/**
* Get all StudyProgrammes monitoring this membership-source.
Expand Down Expand Up @@ -1478,11 +1505,8 @@ public function getApplicableMembershipSourceForUser(
?int $exclude_id
): ?ilStudyProgrammeAutoMembershipSource {
foreach ($this->getAutomaticMembershipSources() as $ams) {
$src_id = $ams->getSourceId();
if ($src_id !== $exclude_id
&& $ams->isEnabled()
) {
$source_members = $this->getMembersOfMembershipSource($ams->getSourceType(), $src_id);
if ($ams->isEnabled()) {
$source_members = $this->getMembersOfMembershipSource($ams);
if (in_array($usr_id, $source_members)) {
return $ams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class ilObjStudyProgrammeAutoMembershipsGUI
private const F_SOURCE_ID = 'f_sid';
private const F_ORIGINAL_SOURCE_TYPE = 'f_st_org';
private const F_ORIGINAL_SOURCE_ID = 'f_sid_org';
// cat-tms-patch start #8290
private const F_SEARCH_RECURSIVE = "f_search_recursive";
// cat-tms-patch end #8290

private const CMD_VIEW = 'view';
private const CMD_SAVE = 'save';
Expand Down Expand Up @@ -169,11 +172,10 @@ protected function view(bool $profile_not_public = false): void
$data = [];
foreach ($this->getObject()->getAutomaticMembershipSources() as $ams) {
$title = $this->getTitleRepresentation($ams);
$usr = $this->getUserRepresentation($ams->getLastEditorId());
$modal = $this->getModal($ams->getSourceType(), $ams->getSourceId());
$usr = $this->getUserRepresentation($ams->getLastEditorId()) ?? $this->ui_factory->legacy('-');
$modal = $this->getModal($ams->getSourceType(), $ams->getSourceId(), $ams->isSearchRecursive());
$collected_modals[] = $modal;

$src_id = $ams->getSourceType() . '-' . $ams->getSourceId();
$src_id = $ams->getSourceType() . '-' . $ams->getSourceId() . '-' . $ams->isSearchRecursive();
$actions = $this->getItemAction(
$src_id,
$modal->getShowSignal(),
Expand Down Expand Up @@ -204,6 +206,7 @@ protected function save(): void
$form->setValuesByArray($post);
$src_type = $post[self::F_SOURCE_TYPE];
$src_id = $post[self::F_SOURCE_ID . $src_type];
$search_recursive = (bool) $post[self::F_SEARCH_RECURSIVE];

if (
(is_null($src_type) || $src_type === "") ||
Expand All @@ -229,7 +232,7 @@ protected function save(): void
);
}

$this->getObject()->storeAutomaticMembershipSource($src_type, (int) $src_id);
$this->getObject()->storeAutomaticMembershipSource($src_type, (int) $src_id, $search_recursive);
$this->tpl->setOnScreenMessage("success", $this->txt("auto_add_success"), true);
$this->ctrl->redirect($this, self::CMD_VIEW);
}
Expand Down Expand Up @@ -308,8 +311,10 @@ protected function enable(): void
$get = $this->request->getQueryParams();
$field = self::CHECKBOX_SOURCE_IDS;
if (array_key_exists($field, $get)) {
[$type, $id] = explode('-', $get[$field]);
$this->getObject()->enableAutomaticMembershipSource((string) $type, (int) $id);
// cat-tms-patch start #8290
[$type, $id, $search_recursive] = explode('-', $get[$field]);
$this->getObject()->enableAutomaticMembershipSource((string) $type, (int) $id, (bool) $search_recursive);
// cat-tms-patch end #8290
}
$this->ctrl->redirect($this, self::CMD_VIEW);
}
Expand All @@ -322,8 +327,8 @@ protected function disable(): void
$get = $this->request->getQueryParams();
$field = self::CHECKBOX_SOURCE_IDS;
if (array_key_exists($field, $get)) {
[$type, $id] = explode('-', $get[$field]);
$this->getObject()->disableAutomaticMembershipSource((string) $type, (int) $id);
[$type, $id, $search_recursive] = explode('-', $get[$field]);
$this->getObject()->disableAutomaticMembershipSource((string) $type, (int) $id, (bool) $search_recursive);
}
$this->ctrl->redirect($this, self::CMD_VIEW);
}
Expand Down Expand Up @@ -357,13 +362,18 @@ protected function getObject(): ilObjStudyProgramme
return $this->object;
}

protected function getModal(string $source_type = null, int $source_id = null): RoundTrip
{
protected function getModal(
string $source_type = null,
int $source_id = null,
bool $search_recursive = false
): RoundTrip {
$this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_TYPE, $source_type);
$this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_ID, $source_id);
$this->ctrl->setParameter($this, self::F_SEARCH_RECURSIVE, $search_recursive);
$link = $this->ctrl->getLinkTarget($this, "getAsynchModalOutput", "", true);
$this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_TYPE, null);
$this->ctrl->setParameter($this, self::F_ORIGINAL_SOURCE_ID, null);
$this->ctrl->setParameter($this, self::F_SEARCH_RECURSIVE, null);

return $this->ui_factory->modal()->roundtrip(
'',
Expand All @@ -388,6 +398,14 @@ protected function getAsynchModalOutput(): void
}

$form = $this->getForm($current_src_type, $current_src_id);
$search_recursive = false;
if (
array_key_exists(self::F_SEARCH_RECURSIVE, $_GET) &&
!is_null($_GET[self::F_SEARCH_RECURSIVE])
) {
$search_recursive = (bool) $_GET[self::F_SEARCH_RECURSIVE];
}
$form = $this->getForm($current_src_type, $current_src_id, $search_recursive);
$form_id = "form_" . $form->getId();

$modal = $this->ui_factory->modal()->roundtrip(
Expand Down Expand Up @@ -453,8 +471,13 @@ function ($id) use ($form) {
exit;
}

protected function getForm(string $source_type = null, ?string $source_id = ''): ilPropertyFormGUI
{
protected function getForm(
string $source_type = null,
int $source_id = null,
// cat-tms-patch start #8290
bool $search_recursive = false
// cat-tms-patch end #8290
): ilPropertyFormGUI {
$form = new ilPropertyFormGUI();

if (is_null($source_type)) {
Expand Down Expand Up @@ -517,6 +540,13 @@ protected function getForm(string $source_type = null, ?string $source_id = ''):
$orgu->getExplorerGUI()->setRootId(ilObjOrgUnit::getRootOrgRefId());
$orgu->getExplorerGUI()->setAjax(false);
$radio_orgu->addSubItem($orgu);

// cat-tms-patch start #8290
$recurse = new ilCheckboxInputGUI($this->txt('search_for_orgu_members_recursive'), self::F_SEARCH_RECURSIVE);
$recurse->setValue(1);
$recurse->setChecked($search_recursive);
$radio_orgu->addSubItem($recurse);
// cat-tms-patch end #8290
$rgroup->addOption($radio_orgu);
if (
!is_null($source_type) &&
Expand Down Expand Up @@ -727,7 +757,7 @@ static function (array $c): string {
case ilStudyProgrammeAutoMembershipSource::TYPE_ORGU:
$hops = array_map(
static function (array $c): string {
return ilObject::_lookupTitle((int)$c["obj_id"]);
return ilObject::_lookupTitle((int) $c["obj_id"]);
},
$this->tree->getPathFull($src_id)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function __construct(
$this->addColumn($this->lng->txt('last_edited_by'), 'editor');
$this->addColumn($this->lng->txt('last_edited'), 'last');
$this->addColumn($this->lng->txt('status'), 'status');
// cat-tms-patch start #8290
$this->addColumn($this->lng->txt('search_for_orgu_members_recursive'), 'search_recursive');
// cat-tms-patch end #8290
$this->addColumn($this->lng->txt('actions'), 'actions');
$this->setSelectAllCheckbox(ilObjStudyProgrammeAutoMembershipsGUI::CHECKBOX_SOURCE_IDS . '[]');
$this->setEnableAllCommand(true);
Expand All @@ -57,18 +60,36 @@ public function __construct(

protected function fillRow(array $a_set): void
{
[$ams, $title, $usr, $actions] = $a_set;
/** @var ilStudyProgrammeAutoMembershipSource $ams */
list($ams, $title, $usr, $actions) = $a_set;

$username = ilObjUser::_lookupName($ams->getLastEditorId());
$editor = implode(' ', [
$username['firstname'],
$username['lastname'],
'(' . $username['login'] . ')'
]);

$id = $ams->getSourceType() . '-' . $ams->getSourceId();
$status = $ams->isEnabled() ? $this->lng->txt('active') : $this->lng->txt('inactive');
$date = $this->getDatePresentation($ams->getLastEdited()->getTimestamp());

// cat-tms-patch start #8290
$search_recursive = $this->lng->txt("no");
if ($ams->isSearchRecursive()) {
$search_recursive = $this->lng->txt("yes");
}
// cat-tms-patch end #8290

$this->tpl->setVariable("ID", $id);
$this->tpl->setVariable("TYPE", $this->lng->txt($ams->getSourceType()));
$this->tpl->setVariable("TITLE", $title);
$this->tpl->setVariable("EDITOR", $usr);
$this->tpl->setVariable("LAST_EDITED", $date);
$this->tpl->setVariable("STATUS", $status);
// cat-tms-patch start #8290
$this->tpl->setVariable("SEARCH_RECURSIVE", $search_recursive);
// cat-tms-patch end #8290
$this->tpl->setVariable("ACTIONS", $actions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ class ilStudyProgrammeAutoMembershipSource
protected int $last_edited_usr_id;
protected DateTimeImmutable $last_edited;

// cat-tms-patch start #8290
protected bool $search_recursive;

public function __construct(
int $prg_obj_id,
string $source_type,
int $source_id,
bool $enabled,
int $last_edited_usr_id,
DateTimeImmutable $last_edited
DateTimeImmutable $last_edited,
bool $search_recursive
) {
if (!in_array($source_type, [
self::TYPE_ROLE,
Expand All @@ -67,7 +71,9 @@ public function __construct(
$this->enabled = $enabled;
$this->last_edited_usr_id = $last_edited_usr_id;
$this->last_edited = $last_edited;
$this->search_recursive = $search_recursive;
}
// cat-tms-patch end #8290

public function getPrgObjId(): int
{
Expand Down Expand Up @@ -98,4 +104,11 @@ public function getLastEdited(): DateTimeImmutable
{
return $this->last_edited;
}

// cat-tms-patch start #8290
public function isSearchRecursive(): bool
{
return $this->search_recursive;
}
// cat-tms-patch end #8290
}
Loading

0 comments on commit ebe4db7

Please sign in to comment.