From 629a1dea2960fdb5896fe0e73fe36769a9a22b21 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Fri, 20 Dec 2024 20:53:51 +0100 Subject: [PATCH 1/4] MBS-9808: Update subplugins.json because of MDL-83705 --- db/subplugins.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/db/subplugins.json b/db/subplugins.json index a30e7a0..dc73406 100755 --- a/db/subplugins.json +++ b/db/subplugins.json @@ -1,6 +1,10 @@ { + "subplugintypes": { + "aitool": "tools", + "aipurpose": "purposes" + }, "plugintypes": { - "aitool": "local\/ai_manager\/tools", - "aipurpose": "local\/ai_manager\/purposes" + "aitool": "local/ai_manager/tools", + "aipurpose": "local/ai_manager/purposes" } } \ No newline at end of file From eddacaf78aa094ceb1d29919bcf5250793ccc5f1 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Fri, 20 Dec 2024 21:35:49 +0100 Subject: [PATCH 2/4] MBS-9808: Fix role filter in case of no users exist with filtered role(s) --- classes/local/rights_config_table.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/classes/local/rights_config_table.php b/classes/local/rights_config_table.php index 52448e4..4822b04 100644 --- a/classes/local/rights_config_table.php +++ b/classes/local/rights_config_table.php @@ -94,6 +94,9 @@ public function __construct( if (!empty($roleuserids)) { [$insql, $roleparams] = $DB->get_in_or_equal($roleuserids, SQL_PARAMS_NAMED); $rolewhere = ' AND u.id ' . $insql; + } else { + // We could not find any user with the roles in the filter, so we need to return no entries. + $rolewhere = ' AND FALSE '; } } From f568d4cc9236f8339536c05c20b81d6fa62438d5 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Fri, 20 Dec 2024 21:39:09 +0100 Subject: [PATCH 3/4] MBS-9808: Refactor bulk actions UI of rights table --- classes/form/rights_config_form.php | 36 ++++++++++++++++++++++++----- lang/en/local_ai_manager.php | 7 ++++-- rights_config.php | 17 ++++++++------ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/classes/form/rights_config_form.php b/classes/form/rights_config_form.php index 8916158..f980914 100644 --- a/classes/form/rights_config_form.php +++ b/classes/form/rights_config_form.php @@ -35,6 +35,16 @@ */ class rights_config_form extends \moodleform { + /** @var string Constant for defining the action "assign role". */ + const ACTION_ASSIGN_ROLE = 'assignrole'; + + /** @var string Constant for defining the action "change lock status". */ + const ACTION_CHANGE_LOCK_STATE = 'changelockstate'; + /** @var string Constant for defining the action option "locked" for the action {@see self::ACTION_CHANGE_LOCK_STATE}. */ + const ACTIONOPTION_CHANGE_LOCK_STATE_LOCKED = 'locked'; + /** @var string Constant for defining the action option "unlocked" for the action {@see self::ACTION_CHANGE_LOCK_STATE}. */ + const ACTIONOPTION_CHANGE_LOCK_STATE_UNLOCKED = 'unlocked'; + /** * Form definition. */ @@ -48,19 +58,33 @@ public function definition() { $mform->addElement('hidden', 'userids', '', ['id' => 'rights-table-userids']); $mform->setType('userids', PARAM_TEXT); - $roleelementsarray = []; - $roleelementsarray[] = $mform->createElement('select', 'role', '', [ + $actionselectsgroup[] = $mform->createElement('select', 'action', '', + [ + self::ACTION_ASSIGN_ROLE => get_string('assignrole', 'local_ai_manager'), + self::ACTION_CHANGE_LOCK_STATE => get_string('changelockstate', 'local_ai_manager'), + ]); + + $actionselectsgroup[] = $mform->createElement('select', 'role', '', [ userinfo::ROLE_BASIC => get_string(userinfo::get_role_as_string(userinfo::ROLE_BASIC), 'local_ai_manager'), userinfo::ROLE_EXTENDED => get_string(userinfo::get_role_as_string(userinfo::ROLE_EXTENDED), 'local_ai_manager'), userinfo::ROLE_UNLIMITED => get_string(userinfo::get_role_as_string(userinfo::ROLE_UNLIMITED), 'local_ai_manager'), userinfo::ROLE_DEFAULT => get_string('defaultrole', 'local_ai_manager'), ]); - $roleelementsarray[] = $mform->createElement('submit', 'changerole', get_string('assignrole', 'local_ai_manager')); - $mform->addGroup($roleelementsarray, 'buttonarrayrole', '', [' '], false); + $mform->hideif('role', 'action', 'neq', self::ACTION_ASSIGN_ROLE); + + $actionselectsgroup[] = $mform->createElement('select', 'lockstate', '', + [ + self::ACTIONOPTION_CHANGE_LOCK_STATE_LOCKED => get_string('lock', 'local_ai_manager'), + self::ACTIONOPTION_CHANGE_LOCK_STATE_UNLOCKED => get_string('unlock', 'local_ai_manager'), + ] + ); + $mform->hideif('lockstate', 'action', 'neq', self::ACTION_CHANGE_LOCK_STATE); + + $mform->addGroup($actionselectsgroup, 'actiongroup', get_string('executebulkuseractions', 'local_ai_manager') . ':', [' '], + false); $buttonarray = []; - $buttonarray[] = $mform->createElement('submit', 'lockusers', get_string('lockuser', 'local_ai_manager')); - $buttonarray[] = $mform->createElement('submit', 'unlockusers', get_string('unlockuser', 'local_ai_manager')); + $buttonarray[] = $mform->createElement('submit', 'executeaction', get_string('executeaction', 'local_ai_manager')); $buttonarray[] = $mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->closeHeaderBefore('buttonar'); diff --git a/lang/en/local_ai_manager.php b/lang/en/local_ai_manager.php index 34882bc..bf22f82 100644 --- a/lang/en/local_ai_manager.php +++ b/lang/en/local_ai_manager.php @@ -54,6 +54,7 @@ $string['basicsettings'] = 'Basic settings'; $string['basicsettingsdesc'] = 'Configure basic settings for the AI manager plugin'; $string['cachedef_googleauth'] = 'Cache for Google OAuth2 access token'; +$string['changelockstate'] = 'Change lock state'; $string['configure_instance'] = 'Configure AI Tool Instances'; $string['configureaitool'] = 'Configure AI tool'; $string['configurepurposes'] = 'Configure the purposes'; @@ -105,6 +106,8 @@ $string['exception_tenantaccessdenied'] = 'You must not access this tenant ({$a}).'; $string['exception_tenantnotallowed'] = 'The tenant is not allowed by the administrator'; $string['exception_usernotexists'] = 'The user does not exist'; +$string['executeaction'] = 'Execute action'; +$string['executebulkuseractions'] = 'Execute action for selected users'; $string['female'] = 'Female'; $string['filterroles'] = 'Filter roles'; $string['formvalidation_editinstance_azureapiversion'] = 'You must provide the api version of your Azure Resource'; @@ -129,8 +132,8 @@ $string['instancename'] = 'Internal identifier'; $string['landscape'] = 'landscape'; $string['large'] = 'large'; +$string['lock'] = 'Lock'; $string['locked'] = 'Locked'; -$string['lockuser'] = 'Lock user'; $string['male'] = 'Male'; $string['max_request_time_window'] = 'Time window for maximum number of requests'; $string['max_requests_purpose'] = 'Maximum number of requests per time window ({$a})'; @@ -212,7 +215,7 @@ $string['termsofusesettingdesc'] = 'Here you can add your specific terms of use for the AI manager. These will have to be accepted by the user before he/she will be able to use the AI tools.'; $string['unit_count'] = 'request(s)'; $string['unit_token'] = 'token'; -$string['unlockuser'] = 'Unlock user'; +$string['unlock'] = 'Unlock'; $string['usage'] = 'Usage'; $string['use_openai_by_azure_apiversion'] = 'API version of the Azure resource'; $string['use_openai_by_azure_deploymentid'] = 'Deployment ID of the Azure resource'; diff --git a/rights_config.php b/rights_config.php index f968ee3..8ecc3d5 100644 --- a/rights_config.php +++ b/rights_config.php @@ -58,13 +58,16 @@ throw new moodle_exception('exception_changestatusnotallowed', 'local_ai_manager', '', '', 'User ID: ' . $userid); } $userinfo = new userinfo($userid); - if (isset($data->lockusers)) { - $userinfo->set_locked(true); - } else if (isset($data->unlockusers)) { - $userinfo->set_locked(false); - } else if (isset($data->changerole) && isset($data->role)) { - $role = intval($data->role); - $userinfo->set_role($role); + switch ($data->action) { + case rights_config_form::ACTION_CHANGE_LOCK_STATE: + $userinfo->set_locked($data->lockstate === rights_config_form::ACTIONOPTION_CHANGE_LOCK_STATE_LOCKED); + break; + case rights_config_form::ACTION_ASSIGN_ROLE: + $role = intval($data->role); + $userinfo->set_role($role); + break; + default: + throw new \coding_exception('Unknown action: ' . $data->action); } $userinfo->store(); } From 170f08fd8ac9b90b2eba9e2eb2e94e80c91dc4ba Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Fri, 20 Dec 2024 21:57:22 +0100 Subject: [PATCH 4/4] MBS-9808: Allow tenant manager to confirm/unconfirm terms of use --- classes/form/rights_config_form.php | 16 ++++++++++++++++ lang/en/local_ai_manager.php | 6 ++++-- rights_config.php | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/classes/form/rights_config_form.php b/classes/form/rights_config_form.php index f980914..8ffd8d1 100644 --- a/classes/form/rights_config_form.php +++ b/classes/form/rights_config_form.php @@ -45,6 +45,13 @@ class rights_config_form extends \moodleform { /** @var string Constant for defining the action option "unlocked" for the action {@see self::ACTION_CHANGE_LOCK_STATE}. */ const ACTIONOPTION_CHANGE_LOCK_STATE_UNLOCKED = 'unlocked'; + /** @var string Constant for defining the action "change confirm status of terms of use". */ + const ACTION_CHANGE_CONFIRM_STATE = 'changeconfirmstate'; + /** @var string Constant for defining the action option "confirm" for the action {@see self::ACTION_CHANGE_CONFIRM_STATUS}. */ + const ACTIONOPTION_CHANGE_CONFIRM_STATE_CONFIRM = 'confirm'; + /** @var string Constant for defining the action option "confirm" for the action {@see self::ACTION_CHANGE_CONFIRM_STATUS}. */ + const ACTIONOPTION_CHANGE_CONFIRM_STATE_UNCONFIRM = 'unconfirm'; + /** * Form definition. */ @@ -62,6 +69,7 @@ public function definition() { [ self::ACTION_ASSIGN_ROLE => get_string('assignrole', 'local_ai_manager'), self::ACTION_CHANGE_LOCK_STATE => get_string('changelockstate', 'local_ai_manager'), + self::ACTION_CHANGE_CONFIRM_STATE => get_string('changeconfirmstate', 'local_ai_manager'), ]); $actionselectsgroup[] = $mform->createElement('select', 'role', '', [ @@ -80,6 +88,14 @@ public function definition() { ); $mform->hideif('lockstate', 'action', 'neq', self::ACTION_CHANGE_LOCK_STATE); + $actionselectsgroup[] = $mform->createElement('select', 'confirmstate', '', + [ + self::ACTIONOPTION_CHANGE_CONFIRM_STATE_CONFIRM => get_string('confirmed', 'local_ai_manager'), + self::ACTIONOPTION_CHANGE_CONFIRM_STATE_UNCONFIRM => get_string('unconfirmed', 'local_ai_manager'), + ] + ); + $mform->hideif('confirmstate', 'action', 'neq', self::ACTION_CHANGE_CONFIRM_STATE); + $mform->addGroup($actionselectsgroup, 'actiongroup', get_string('executebulkuseractions', 'local_ai_manager') . ':', [' '], false); diff --git a/lang/en/local_ai_manager.php b/lang/en/local_ai_manager.php index bf22f82..2833ab2 100644 --- a/lang/en/local_ai_manager.php +++ b/lang/en/local_ai_manager.php @@ -54,7 +54,8 @@ $string['basicsettings'] = 'Basic settings'; $string['basicsettingsdesc'] = 'Configure basic settings for the AI manager plugin'; $string['cachedef_googleauth'] = 'Cache for Google OAuth2 access token'; -$string['changelockstate'] = 'Change lock state'; +$string['changeconfirmstate'] = 'Change confirmation of terms of use'; +$string['changelockstate'] = 'Change lock status'; $string['configure_instance'] = 'Configure AI Tool Instances'; $string['configureaitool'] = 'Configure AI tool'; $string['configurepurposes'] = 'Configure the purposes'; @@ -141,7 +142,7 @@ $string['medium'] = 'medium'; $string['model'] = 'Model'; $string['nodata'] = 'No data to show'; -$string['notconfirmed'] = 'Not confirmed'; +$string['notconfirmed'] = 'Not accepted'; $string['notselected'] = 'Disabled'; $string['per'] = 'per'; $string['pluginname'] = 'AI Manager'; @@ -213,6 +214,7 @@ $string['tenantnotallowed'] = 'The feature is globally disabled for your tenant and thus not usable.'; $string['termsofusesetting'] = 'Terms of use'; $string['termsofusesettingdesc'] = 'Here you can add your specific terms of use for the AI manager. These will have to be accepted by the user before he/she will be able to use the AI tools.'; +$string['unconfirmed'] = 'not confirmed'; $string['unit_count'] = 'request(s)'; $string['unit_token'] = 'token'; $string['unlock'] = 'Unlock'; diff --git a/rights_config.php b/rights_config.php index 8ecc3d5..2eb5cad 100644 --- a/rights_config.php +++ b/rights_config.php @@ -66,6 +66,9 @@ $role = intval($data->role); $userinfo->set_role($role); break; + case rights_config_form::ACTION_CHANGE_CONFIRM_STATE: + $userinfo->set_confirmed($data->confirmstate === rights_config_form::ACTIONOPTION_CHANGE_CONFIRM_STATE_CONFIRM); + break; default: throw new \coding_exception('Unknown action: ' . $data->action); }