Skip to content
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
8 changes: 5 additions & 3 deletions bin/seed-database.pl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@

say qq(Creating initial username "$initial_username"...);
my $user = rset('User')->create({
username => $initial_username,
email => $initial_username,
site_id => $site->id,
username => $initial_username,
email => $initial_username,
site_id => $site->id,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be set automatically - this is in /lib/GADS/Schema.pm

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The site_id was already part of the script before these changes - only the indenting was updated on that line.

created => DateTime->now,
created_by => $initial_username,
});

say "Adding all permissions to initial username...";
Expand Down
8 changes: 6 additions & 2 deletions lib/GADS/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ sub _post_add_user_account
$id ? $update_user->update_user(%values, current_user => $logged_in_user)
: schema->resultset('User')->create_user(%values, current_user => $logged_in_user, request_base => request->base);

my $msg = __x"User {type} successfully", type => $id ? 'updated' : 'created';
my $msg = __x"User {type} successfully by {current_user}", type => $id ? 'updated' : 'created', current_user => $logged_in_user->email;
return _success("$msg");
}

Expand Down Expand Up @@ -1362,7 +1362,7 @@ any ['get', 'post'] => '/api/users' => require_any_role [qw/useradmin superadmin
push @cols, 'department' if $site->register_show_department;
push @cols, 'team' if $site->register_show_team;
push @cols, 'freetext1' if $site->register_freetext1_name;
push @cols, qw/created lastlogin/;
push @cols, qw/created lastlogin created_by/;
my @return = map { { name => $_, data => $_ } } @cols;
content_type 'application/json; charset=UTF-8';
return encode_json \@return;
Expand Down Expand Up @@ -1400,6 +1400,10 @@ any ['get', 'post'] => '/api/users' => require_any_role [qw/useradmin superadmin
{
$sort_by = 'me.created';
}
elsif ($sort_by && $sort_by eq 'Created by')
{
$sort_by = 'me.created_by';
}
elsif ($sort_by && $sort_by eq 'ID')
{
$sort_by = 'me.id';
Expand Down
2 changes: 1 addition & 1 deletion lib/GADS/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use base 'DBIx::Class::Schema';

__PACKAGE__->load_namespaces;

our $VERSION = 111;
our $VERSION = 112;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need updating to 113 if it is merged after calc datetime (sorry)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. After that PR is merged, I'll merge the changes into this branch and upgrade the schema.


our $IGNORE_PERMISSIONS;
our $IGNORE_PERMISSIONS_SEARCH;
Expand Down
10 changes: 9 additions & 1 deletion lib/GADS/Schema/Result/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ __PACKAGE__->add_columns(
datetime_undef_if_invalid => 1,
is_nullable => 1,
},
"created_by",
{ data_type => "text", is_nullable => 1 },
"debug_login",
{ data_type => "smallint", default_value => 0, is_nullable => 1 },
# All the following for MFA
Expand Down Expand Up @@ -636,7 +638,7 @@ sub update_user
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};
id => $self->id, username => $params{username} ? $params{username} : $params{email};
$msg .= __x", groups: {groups}", groups => join ', ', @{$params{groups}}
if $params{groups};
$msg .= __x", permissions: {permissions}", permissions => join ', ', @{$params{permissions}}
Expand Down Expand Up @@ -836,6 +838,11 @@ sub for_data_table
name => 'Created',
values => [$self->created ? $self->created->ymd : 'Unknown'],
},
'Created by' => {
type => 'string',
name => 'Created By',
values => [$self->created_by ? $self->created_by : 'Unknown'],
},
'Last login' => {
type => 'string',
name => 'Last login (GMT)',
Expand Down Expand Up @@ -921,6 +928,7 @@ sub export_hash
account_request => $self->account_request,
account_request_notes => $self->account_request_notes,
created => $self->created && $self->created->datetime,
created_by => $self->created_by,
groups => [map $_->id, $self->groups],
permissions => [map $_->permission->name, $self->user_permissions],
};
Expand Down
10 changes: 6 additions & 4 deletions lib/GADS/Schema/ResultSet/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ sub summary
$self->active->search_rs({},{
columns => [
'me.id', 'me.surname', 'me.firstname', 'title.name', 'me.email',
'organisation.name', 'department.name', 'team.name', 'me.created',
'me.freetext1', 'me.freetext2',
'organisation.name', 'department.name', 'team.name', 'me.created',
'me.created_by', 'me.freetext1', 'me.freetext2',
'me.lastlogin', 'me.value',
],
join => [
Expand Down Expand Up @@ -118,14 +118,15 @@ sub create_user
username => $params{email},
resetpw => $code,
created => DateTime->now,
created_by => $params{current_user}->email,
account_request_notes => $params{notes},
});

my $audit = GADS::Audit->new(schema => $self->result_source->schema, user => $params{current_user});

$audit->login_change(
__x"User created, id: {id}, username: {username}",
id => $user->id, username => $params{username}
__x"User created by {current_user}, id: {id}, username: {username}",
current_user => $params{current_user}->email, id => $user->id, username => $params{username} ? $params{username} : $params{email}
);

$user->update_user(%params);
Expand Down Expand Up @@ -358,6 +359,7 @@ sub import_hash
account_request => $user->{account_request},
account_request_notes => $user->{account_request_notes},
created => $user->{created} && DateTime::Format::ISO8601->parse_datetime($user->{created}),
created_by => $user->{created_by},
});
}

Expand Down
7 changes: 6 additions & 1 deletion lib/GADS/Users.pm
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ sub _produce_csv
my $site = $self->schema->resultset('Site')->find($self->schema->site_id);

# Column names
my @columns = qw/ID Surname Forename Email Lastlogin Created/;
my @columns = qw/ID Surname Forename Email Lastlogin Created Createdby/;
push @columns, 'Title' if $site->register_show_title;
push @columns, 'Organisation' if $site->register_show_organisation;
push @columns, $site->department_name if $site->register_show_department;
Expand Down Expand Up @@ -359,6 +359,10 @@ sub _produce_csv
max => 'created',
-as => 'created_max',
},
{
max => 'created_by',
-as => 'created_by_max',
},
{
max => 'title.name',
-as => 'title_max',
Expand Down Expand Up @@ -468,6 +472,7 @@ sub _produce_csv
$user->get_column('email_max'),
$user->get_column('lastlogin_max'),
$user->get_column('created_max'),
$user->get_column('created_by_max'),
);
push @csv, $user->get_column('title_max') if $site->register_show_title;
push @csv, $user->get_column('organisation_max') if $site->register_show_organisation;
Expand Down
Loading
Loading