Commit c864af5a authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add support for revocation of institution membership invitations



This change adds 'invited users' to the institution members screen,
and allows the institutional admin to revoke invitations that have
already been sent out.

See bug #799617.

Change-Id: Ic2713a6577bb78af2ad5dd87b43ba1907c983a04
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent bff3e898
......@@ -66,6 +66,7 @@ $usertypeselector = pieform(array(
'requesters' => get_string('institutionusersrequesters', 'admin'),
'nonmembers' => get_string('institutionusersnonmembers', 'admin'),
'members' => get_string('institutionusersmembers', 'admin'),
'invited' => get_string('institutionusersinvited', 'admin'),
),
'defaultvalue' => $usertype
),
......@@ -91,7 +92,8 @@ if ($usertype == 'requesters') {
'searchparams' => array('member' => 1),
);
$submittext = get_string('removeusers', 'admin');
} else { // $usertype == nonmembers
}
else if ($usertype == 'nonmembers') {
// Behaviour depends on whether we allow users to have > 1 institution
// LHS either shows all nonmembers or just users with no institution
// RHS shows users to be invited
......@@ -103,6 +105,16 @@ if ($usertype == 'requesters') {
);
$submittext = get_string('inviteusers', 'admin');
}
else if ($usertype == 'invited') {
// Allow invitations to be revoked
$userlistelement = array(
'title' => get_string('revokeinvitations', 'admin'),
'lefttitle' => get_string('invitedusers', 'admin'),
'righttitle' => get_string('userstobeuninvited', 'admin'),
'searchparams' => array('member' => 0, 'invitedby' => 1),
);
$submittext = get_string('revokeinvitations', 'admin');
}
$userlistelement['type'] = 'userlist';
$userlistelement['filter'] = false;
......@@ -159,7 +171,7 @@ function institutionusers_submit(Pieform $form, $values) {
}
$dataerror = false;
if (!in_array($values['usertype'], array('requesters', 'members', 'nonmembers'))
if (!in_array($values['usertype'], array('requesters', 'members', 'nonmembers', 'invited'))
|| !is_array($values['users'])) {
$dataerror = true;
} else {
......@@ -182,9 +194,13 @@ function institutionusers_submit(Pieform $form, $values) {
$action = 'removeMembers';
} else if ($values['usertype'] == 'requesters') {
$action = !empty($values['reject']) ? 'declineRequestFromUser' : 'addUserAsMember';
} else {
}
else if ($values['usertype'] == 'nonmembers') {
$action = (!empty($values['add']) && $USER->get('admin')) ? 'addUserAsMember' : 'inviteUser';
}
else {
$action = 'uninvite_users';
}
$institution = new Institution($values['institution']);
......@@ -214,6 +230,9 @@ function institutionusers_submit(Pieform $form, $values) {
else if ($action == 'declineRequestFromUser') {
$institution->decline_requests($values['users']);
}
else if ($action == 'uninvite_users') {
$institution->uninvite_users($values['users']);
}
$SESSION->add_ok_msg(get_string('institutionusersupdated_'.$action, 'admin'));
if (!$USER->get('admin') && !$USER->is_institutional_admin()) {
......
......@@ -644,6 +644,7 @@ $string['institutionmemberspagedescription'] = 'On this page you can see users w
$string['institutionusersinstructionsrequesters'] = 'The list of users on the left shows all users who have asked to join your institution. You can use the search box to reduce the number of users displayed. If you would like to add users to the institution, or decline their membership requests, first move some users to the right hand side by selecting one or more users and then clicking on the right arrow. The "Add members" button will add all the users on the right to the institution. The "Decline requests" button will remove the membership requests of the users on the right.';
$string['institutionusersinstructionsnonmembers'] = 'The list of users on the left shows all users who are not yet members of your institution. You can use the search box to reduce the number of users displayed. To invite users to join the institution, first move some users to the right hand side by selecting one or more users and then clicking on the right arrow to move those users to the list on the right. The "Invite Users" button will send invitations to all the users on the right. These users will not be associated with the institution until they accept the invitation.';
$string['institutionusersinstructionsmembers'] = 'The list of users on the left shows all members of the institution. You can use the search box to reduce the number of users displayed. To remove users from the institution, first move some users to the right hand side by selecting one or more users on the left and then clicking on the right arrow. The users you selected will move to the right hand side. The "Remove Users" button will remove all the users on the right from the institution. The users on the left will remain in the institution.';
$string['institutionusersinstructionsinvited'] = 'The list of users on the left shows all users who have been sent an invitation to join the institution and who have not yet accepted or declined. You can use the search box to reduce the number of users displayed. To revoke invitations to the institution, first move some users to the right hand side by selecting one or more users on the left and then clicking on the right arrow. The users you selected will move to the right hand side. The "Revoke Invitations" button will remove all invitations to the users on the right. The users on the left will retain their invitations and will still be able to join at any time.';
$string['editmembers'] = 'Edit Members';
$string['editstaff'] = 'Edit Staff';
......@@ -657,6 +658,7 @@ $string['userstodisplay'] = 'Users to display:';
$string['institutionusersrequesters'] = 'People who have requested institution membership';
$string['institutionusersnonmembers'] = 'People who have not requested membership yet';
$string['institutionusersmembers'] = 'People who are already institution members';
$string['institutionusersinvited'] = 'People who have been invited';
$string['addnewmembers'] = 'Add new members';
$string['usersrequested'] = 'Users who have requested membership';
......@@ -673,11 +675,15 @@ $string['userstoberemoved'] = 'Users to be removed';
$string['removeusers'] = 'Remove Users';
$string['declinerequests'] = 'Decline requests';
$string['nousersupdated'] = 'No users were updated';
$string['revokeinvitations'] = 'Revoke invitations';
$string['invitedusers'] = 'Invited users';
$string['userstobeuninvited'] = 'Users to be uninvited';
$string['institutionusersupdated_addUserAsMember'] = 'Users added';
$string['institutionusersupdated_declineRequestFromUser'] = 'Requests declined';
$string['institutionusersupdated_removeMembers'] = 'Users removed';
$string['institutionusersupdated_inviteUser'] = 'Invitations sent';
$string['institutionusersupdated_uninvite_users'] = 'Invitations removed';
$string['maxuseraccounts'] = 'Maximum User Accounts Allowed';
$string['maxuseraccountsdescription'] = 'The maximum number of user accounts that can be associated with the institution. If there is no limit, this field should be left blank.';
......
......@@ -365,6 +365,27 @@ class Institution {
db_commit();
}
public function uninvite_users($userids) {
global $USER;
if (!$USER->can_edit_institution($this->name)) {
throw new AccessDeniedException("Institution::uninvite_users: access denied");
}
if (!is_array($userids) || empty($userids)) {
return;
}
$ph = array_map('intval', $userids);
$ph[] = $this->name;
delete_records_select(
'usr_institution_request',
'usr IN (' . join(',', array_fill(0, count($userids), '?')) . ') AND institution = ? AND confirmedinstitution = 1',
$ph
);
}
public function removeMembers($userids) {
// Remove self last.
global $USER;
......
......@@ -614,7 +614,7 @@ class PluginSearchInternal extends PluginSearch {
$studentid = ', req.studentid';
}
if (!is_null($institution->invitedby)) {
if ($institution->requested == 1) {
if ($institution->invitedby == 1) {
$where .= ' AND req.confirmedinstitution = 1';
} else {
$where .= ' AND (req.confirmedinstitution = 0 OR req.confirmedinstitution IS NULL)';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment