Skip to content

Commit

Permalink
Fix clearing groups input field after user submit error
Browse files Browse the repository at this point in the history
  • Loading branch information
abeverley committed Oct 20, 2023
1 parent c950d0c commit 865c7db
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions lib/GADS/Schema/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,8 @@ sub graphs

# Used to check if a user has a group
has has_group => (
is => 'lazy',
is => 'lazy',
clearer => 1,
);

sub _build_has_group
Expand Down Expand Up @@ -854,19 +855,6 @@ sub update_user
delete $params{team_id} if !$params{team_id};
delete $params{title} if !$params{title};

length $params{firstname} <= 128
or error __"Forename must be less than 128 characters";
length $params{surname} <= 128
or error __"Surname must be less than 128 characters";
!defined $params{organisation} || $params{organisation} =~ /^[0-9]+$/
or error __x"Invalid organisation {id}", id => $params{organisation};
!defined $params{department_id} || $params{department_id} =~ /^[0-9]+$/
or error __x"Invalid department {id}", id => $params{department_id};
!defined $params{team_id} || $params{team_id} =~ /^[0-9]+$/
or error __x"Invalid team {id}", id => $params{team_id};
GADS::Util->email_valid($params{email})
or error __x"The email address \"{email}\" is invalid", email => $params{email};

my $site = $self->result_source->schema->resultset('Site')->next;

my $values = {
Expand Down Expand Up @@ -905,8 +893,13 @@ sub update_user

$self->update($values);

$self->groups($current_user, $params{groups})
if $params{groups};
if ($params{groups})
{
$self->groups($current_user, $params{groups});
$self->clear_has_group;
$self->has_group;
}

if ($params{permissions} && ref $params{permissions} eq 'ARRAY')
{
error __"You do not have permission to set global user permissions"
Expand Down Expand Up @@ -938,6 +931,19 @@ sub update_user
error __x"Please select a {name} for the user", name => $site->department_name
if !$params{department_id} && $site->register_department_mandatory;

length $params{firstname} <= 128
or error __"Forename must be less than 128 characters";
length $params{surname} <= 128
or error __"Surname must be less than 128 characters";
!defined $params{organisation} || $params{organisation} =~ /^[0-9]+$/
or error __x"Invalid organisation {id}", id => $params{organisation};
!defined $params{department_id} || $params{department_id} =~ /^[0-9]+$/
or error __x"Invalid department {id}", id => $params{department_id};
!defined $params{team_id} || $params{team_id} =~ /^[0-9]+$/
or error __x"Invalid team {id}", id => $params{team_id};
GADS::Util->email_valid($params{email})
or error __x"The email address \"{email}\" is invalid", email => $params{email};

my $msg = __x"User updated: ID {id}, username: {username}",
id => $self->id, username => $params{username};
$msg .= __x", groups: {groups}", groups => join ', ', @{$params{groups}}
Expand Down

0 comments on commit 865c7db

Please sign in to comment.