From b3deb4270794cb36369f3c60d727faf5d9b7ef3a Mon Sep 17 00:00:00 2001 From: ferishili Date: Tue, 26 Mar 2024 10:48:11 +0100 Subject: [PATCH] fix hidden visibility change for duplicated videos, fixes #371 --- classes/local/apibridge.php | 25 ++++++++++++++++--- ...ess_duplicated_event_visibility_change.php | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/classes/local/apibridge.php b/classes/local/apibridge.php index f20a89c1..2fdee247 100644 --- a/classes/local/apibridge.php +++ b/classes/local/apibridge.php @@ -1573,12 +1573,13 @@ private function get_non_permanent_acl_rules_for_status($courseid, $visibility, * @param int $courseid id of the course the event belongs to. * @param int $visibility visibility of the event. * @param array|null $groups array of group ids used for replacing the placeholders + * @param bool $forceonhidden flag to force return the acls when hidden. * @return array of objects representing acl rules, each with the fields 'allow', 'action' and 'role'. * @throws dml_exception * @throws coding_exception In case of an invalid visibility status. Only [0,1,2] are allowed. */ - private function get_permanent_acl_rules_for_status($courseid, $visibility, $groups = null) { - return $this->get_acl_rules_for_status($courseid, $visibility, true, $groups); + private function get_permanent_acl_rules_for_status($courseid, $visibility, $groups = null, $forceonhidden = false) { + return $this->get_acl_rules_for_status($courseid, $visibility, true, $groups, $forceonhidden); } /** @@ -1588,11 +1589,12 @@ private function get_permanent_acl_rules_for_status($courseid, $visibility, $gro * @param int $visibility visibility of the event. * @param bool $permanent whether to get permanent or non-permanent acl rules. * @param array|null $groups array of group ids used for replacing the placeholders + * @param bool $forceonhidden flag to force return the acls when hidden. * @return array of objects representing acl rules, each with the fields 'allow', 'action' and 'role'. * @throws dml_exception * @throws coding_exception In case of an invalid visibility status. Only [0,1,2] are allowed. */ - private function get_acl_rules_for_status($courseid, $visibility, $permanent, $groups = null) { + private function get_acl_rules_for_status($courseid, $visibility, $permanent, $groups = null, $forceonhidden = false) { $roles = $this->getroles($permanent ? 1 : 0); $result = []; @@ -1614,6 +1616,21 @@ private function get_acl_rules_for_status($courseid, $visibility, $permanent, $g } break; case block_opencast_renderer::HIDDEN: + if ($permanent && $forceonhidden) { + foreach ($roles as $role) { + foreach ($role->actions as $action) { + $rolenameformatted = self::replace_placeholders($role->rolename, $courseid)[0]; + // Might return null if USERNAME cannot be replaced. + if ($rolenameformatted) { + $result[] = (object)[ + 'allow' => true, + 'action' => $action, + 'role' => $rolenameformatted, + ]; + } + } + } + } break; case block_opencast_renderer::GROUP: foreach ($roles as $role) { @@ -2881,7 +2898,7 @@ public function set_duplicated_event_visibility($duplicatedeventid, $sourceevent $event = new event(); // Gathering acls for the duplicated event. $newacls = $this->get_non_permanent_acl_rules_for_status($courseid, $targetvisibiltiy, $groups); - $newacls = array_merge($newacls, $this->get_permanent_acl_rules_for_status($courseid, $targetvisibiltiy, $groups)); + $newacls = array_merge($newacls, $this->get_permanent_acl_rules_for_status($courseid, $targetvisibiltiy, $groups, true)); foreach ($newacls as $acl) { $event->add_acl($acl->allow, $acl->action, $acl->role); } diff --git a/classes/task/process_duplicated_event_visibility_change.php b/classes/task/process_duplicated_event_visibility_change.php index 66d7dd22..1a2a6792 100644 --- a/classes/task/process_duplicated_event_visibility_change.php +++ b/classes/task/process_duplicated_event_visibility_change.php @@ -113,7 +113,7 @@ public function execute() { $event = $apibridge->get_already_existing_event([$data->duplicatedeventid]); if (!$event || !in_array($event->status, ['EVENTS.EVENTS.STATUS.PROCESSED', 'EVENTS.EVENTS.STATUS.PROCESSING_FAILURE']) || count($event->publication_status) == 0 - || count($event->publication_status) == 1 && $event->publication_status[0] === 'internal') { + || (count($event->publication_status) == 1 && $event->publication_status[0] === 'internal')) { throw new moodle_exception('error_duplicated_event_id_not_ready', 'block_opencast', '', $a); }