Commit cf73073a authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Fixing warning messages for institution full (Bug #1311458)

1) When adding a user via admin/users/edit.php page
2) When self-registering

Also got places where we check institution isFull() to send out an
email to the institution admins to alert them of this problem.

Change-Id: I70a1025651a6e093c51e99bbcbce781c72d7f890
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent e4b7480c
......@@ -165,6 +165,7 @@ function adduser_validate(Pieform $form, $values) {
// Don't exceed max user accounts for the institution
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
$form->set_error('authinstance', get_string('institutionmaxusersexceeded', 'admin'));
return;
}
......
......@@ -658,7 +658,7 @@ $allinstitutions = get_records_assoc('institution', '', '', 'displayname', 'name
foreach ($institutions as $i) {
$elements[$i->institution.'_settings'] = array(
'type' => 'fieldset',
'legend' => $allinstitutions[$i->institution]->displayname,
'legend' => $i->displayname,
'elements' => array(
$i->institution.'_expiry' => array(
'type' => 'date',
......@@ -732,6 +732,26 @@ $institutionform = pieform(array(
'elements' => $elements,
));
function edituser_institution_validate(Pieform $form, $values) {
$user = new User;
if (!$user->find_by_id($values['id'])) {
return false;
}
global $USER;
$userinstitutions = $user->get('institutions');
if (isset($values['add']) && $USER->get('admin')
&& (empty($userinstitutions) || get_config('usersallowedmultipleinstitutions'))) {
// check if the institution is full
require_once(get_config('docroot') . 'lib/institution.php');
$institution = new Institution($values['addinstitution']);
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
$form->set_error(null,get_string('institutionmaxusersexceeded', 'admin'));
}
}
}
function edituser_institution_submit(Pieform $form, $values) {
$user = new User;
if (!$user->find_by_id($values['id'])) {
......
......@@ -1494,6 +1494,7 @@ function login_submit(Pieform $form, $values) {
require_once('institution.php');
$institution = new Institution($authinstance->institution);
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
throw new AuthUnknownUserException('Institution has too many users');
}
......@@ -2275,7 +2276,7 @@ function auth_register_validate(Pieform $form, $values) {
$institution = get_record_sql('
SELECT
i.name, i.maxuseraccounts, i.registerallowed, COUNT(u.id)
i.name, i.maxuseraccounts, i.registerallowed, COUNT(u.id) AS count
FROM {institution} i
LEFT OUTER JOIN {usr_institution} ui ON ui.institution = i.name
LEFT OUTER JOIN {usr} u ON (ui.usr = u.id AND u.deleted = 0)
......@@ -2285,7 +2286,12 @@ function auth_register_validate(Pieform $form, $values) {
i.name, i.maxuseraccounts, i.registerallowed', array($institution));
if (!empty($institution->maxuseraccounts) && $institution->count >= $institution->maxuseraccounts) {
$form->set_error($hashed['institution'], get_string('institutionfull'));
// the institution is full so we need to alert the admins of the institution to this fact so
// they can either increase the maxusers or turn off the public registration.
require_once(get_config('docroot') . 'lib/institution.php');
$institutionobj = new Institution($institution->name);
$institutionobj->send_admin_institution_is_full_message();
$form->set_error('institution', get_string('institutionfull'));
}
if (!$institution || !$institution->registerallowed) {
......
......@@ -146,6 +146,7 @@ class AuthSaml extends Auth {
if (!empty($this->config['weautocreateusers'])) {
$institution = new Institution($this->institution);
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
throw new XmlrpcClientException('SSO attempt from ' . $institution->displayname . ' failed - institution is full');
}
$user = new User;
......
......@@ -162,6 +162,7 @@ class AuthXmlrpc extends Auth {
if (!empty($this->config['weautocreateusers'])) {
$institution = new Institution($this->institution);
if ($institution->isFull()) {
$institution->send_admin_institution_is_full_message();
throw new XmlrpcClientException('SSO attempt from ' . $institution->displayname . ' failed - institution is full');
}
$user = new User;
......
......@@ -284,7 +284,8 @@ class Institution {
public function addUserAsMember($user) {
global $USER;
if ($this->isFull()) {
throw new SystemException('Trying to add a user to an institution that already has a full quota of members');
$this->send_admin_institution_is_full_message();
die_info(get_string('institutionmaxusersexceeded', 'admin'));
}
if (is_numeric($user)) {
$user = get_record('usr', 'id', $user);
......
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