diff --git a/classes/local/table/interaction_attention_table.php b/classes/local/table/interaction_attention_table.php index 7b7b43c4..9bd92652 100644 --- a/classes/local/table/interaction_attention_table.php +++ b/classes/local/table/interaction_attention_table.php @@ -109,12 +109,24 @@ public function init() { * @throws \invalid_parameter_exception */ public function col_tools($row) { + global $USER; $output = ''; $step = step_manager::get_step_instance($row->stepinstanceid); $tools = interaction_manager::get_action_tools($step->subpluginname, $row->processid); + $toolsstrings = array_map(fn($action) => $action['action'], $tools); + + $availabletoolsstrings = lib_manager::get_step_interactionlib($step->subpluginname)-> + get_available_actions_for_user($toolsstrings, $USER->id, $row->courseid); + foreach ($tools as $tool) { - $output .= $this->format_icon_link($tool['action'], $row->processid, $step->id, $tool['alt']); + // Only show actions which are valid actions and which are available to the current user. + if (in_array($tool['action'], $toolsstrings) && in_array($tool['action'], $availabletoolsstrings)) { + $output .= $this->format_icon_link($tool['action'], $row->processid, $step->id, $tool['alt']); + } + } + if (empty($output)) { + $output = get_string('noactionsavailable', 'tool_lifecycle'); } return $output; } diff --git a/lang/de/tool_lifecycle.php b/lang/de/tool_lifecycle.php index b3f2bcaa..20ecb46d 100644 --- a/lang/de/tool_lifecycle.php +++ b/lang/de/tool_lifecycle.php @@ -162,6 +162,7 @@ $string['coursename'] = 'Kursname'; $string['lastaction'] = 'Letzte Aktion am'; +$string['noactionsavailable'] = 'Sie können keine Aktion ausführen. Warten Sie, bis ein anderer User dies tut.'; $string['workflow_started'] = 'Workflow gestartet.'; $string['workflow_is_running'] = 'Workflow läuft.'; diff --git a/lang/en/tool_lifecycle.php b/lang/en/tool_lifecycle.php index eca85b7d..357a7214 100644 --- a/lang/en/tool_lifecycle.php +++ b/lang/en/tool_lifecycle.php @@ -167,6 +167,7 @@ $string['coursename'] = 'Course name'; $string['lastaction'] = 'Last action on'; +$string['noactionsavailable'] = 'You cannot execute any action but have to wait for another user to handle this course.'; $string['anonymous_user'] = 'Anonymous User'; $string['workflow_started'] = 'Workflow started.'; diff --git a/step/interactionlib.php b/step/interactionlib.php index a4909a52..2870b344 100644 --- a/step/interactionlib.php +++ b/step/interactionlib.php @@ -105,4 +105,23 @@ abstract public function handle_interaction($process, $step, $action = 'default' public function get_due_date($processid, $stepid) { return null; } + + /** + * Method to limit the actions to specific users. Returns all actions by default so if not overwritten all actions are available + * to any user. You can overwrite this method to filter the $actionstrings array according to your needs to limit the actions + * shown to the given user. + * + * Care: When overwriting this method you want to make sure that at least one user can use at least one action or have a timeout + * in your step to avoid any deadlocked workflows. + * + * @param array $actionstrings array of action strings. These should match the strings with the key 'action' + * in {@see get_action_tools} return array. + * @param int $userid the id of the user for whom the returned actions should be visible + * @param int $courseid the id of the currently handled course + * @return array the (possibly) filtered $actions array containing the strings of the actions which should be available to the + * given user + */ + public function get_available_actions_for_user(array $actionstrings, int $userid, int $courseid) : array { + return $actionstrings; + } }