Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-9808: Allow tenant manager to confirm terms of use #38

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions classes/form/rights_config_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@
*/
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';

/** @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.
*/
Expand All @@ -48,19 +65,42 @@ 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'),
self::ACTION_CHANGE_CONFIRM_STATE => get_string('changeconfirmstate', '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);

$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);

$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');
Expand Down
3 changes: 3 additions & 0 deletions classes/local/rights_config_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ';
}
}

Expand Down
8 changes: 6 additions & 2 deletions db/subplugins.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
11 changes: 8 additions & 3 deletions lang/de/local_ai_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@
$string['basicsettings'] = 'Grundeinstellungen';
$string['basicsettingsdesc'] = 'Grundeinstellungen des AI-Managers konfigurieren';
$string['cachedef_googleauth'] = 'Cache für Google-OAuth2-Access-Token';
$string['changeconfirmstate'] = 'Zustimmung der Nutzungsbedingungen ändern';
$string['changelockstate'] = 'Gesperrt-Zustand verändern';
$string['configure_instance'] = 'KI-Tool-Instanzen konfigurieren';
$string['configureaitool'] = 'KI-Tool konfigurieren';
$string['configurepurposes'] = 'Einsatzzwecke konfigurieren';
$string['confirm'] = 'Bestätigen';
$string['confirmaitoolsusage_heading'] = 'KI-Nutzung bestätigen';
$string['confirmed'] = 'akzeptiert';
$string['confirmed'] = 'Akzeptiert';
$string['currentlyusedaitools'] = 'Aktuell konfigurierte KI-Tools';
$string['defaultrole'] = 'Standard-Rolle';
$string['defaulttenantname'] = 'Standard-Tenant';
Expand Down Expand Up @@ -105,6 +107,8 @@
$string['exception_tenantaccessdenied'] = 'Sie dürfen nicht auf diesen Tenant ({$a}) zugreifen.';
$string['exception_tenantnotallowed'] = 'Der Tenant wurde vom Administrator gesperrt.';
$string['exception_usernotexists'] = 'Der Nutzer existiert nicht.';
$string['executeaction'] = 'Aktion ausführen';
$string['executebulkuseractions'] = 'Aktion für ausgewählte Nutzer ausführen';
$string['female'] = 'Weiblich';
$string['filterroles'] = 'Rollen filtern';
$string['formvalidation_editinstance_azureapiversion'] = 'Sie müssen die API-Version Ihrer Azure-Resource eingeben';
Expand All @@ -129,8 +133,8 @@
$string['instancename'] = 'Interne Bezeichnung';
$string['landscape'] = 'Querformat';
$string['large'] = 'groß';
$string['lock'] = 'Sperren';
$string['locked'] = 'Gesperrt';
$string['lockuser'] = 'Benutzer sperren';
$string['male'] = 'Männlich';
$string['max_request_time_window'] = 'Zeitfenster für maximale Anzahlen an Anfragen';
$string['max_requests_purpose'] = 'Maximale Anzahl an Anfragen pro Zeitfenster ({$a})';
Expand Down Expand Up @@ -210,9 +214,10 @@
$string['tenantnotallowed'] = 'Das Feature ist für Ihren Tenant zentral deaktiviert und daher nicht nutzbar.';
$string['termsofusesetting'] = 'Nutzungsbedingungen';
$string['termsofusesettingdesc'] = 'Hier können Sie Nutzungsbedingungen hinterlegen, die der Nutzer akzeptieren muss.';
$string['unconfirmed'] = 'Nicht akzeptiert';
$string['unit_count'] = 'Anfrage(n)';
$string['unit_token'] = 'Token';
$string['unlockuser'] = 'Benutzer entsperren';
$string['unlock'] = 'Entsperren';
$string['usage'] = 'Verbrauch';
$string['use_openai_by_azure_apiversion'] = 'API-Version der Azure-Resource';
$string['use_openai_by_azure_deploymentid'] = 'Deployment-ID (Deployment-Name) der Azure-Resource';
Expand Down
11 changes: 8 additions & 3 deletions lang/en/local_ai_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +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['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';
Expand Down Expand Up @@ -105,6 +107,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';
Expand All @@ -129,16 +133,16 @@
$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})';
$string['max_requests_purpose_heading'] = 'Purpose {$a}';
$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';
Expand Down Expand Up @@ -210,9 +214,10 @@
$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['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';
Expand Down
20 changes: 13 additions & 7 deletions rights_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@
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;
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);
}
$userinfo->store();
}
Expand Down