Skip to content

Commit

Permalink
Add change_user_status stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
charsbar committed Apr 27, 2024
1 parent 320246a commit 4ed66e7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/pause_2017/PAUSE/Web/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,25 @@ our %Actions = (
cat => "01usr/01look",
desc => "Admins can look where email should go",
},
change_user_status => {
x_mojo_to => "admin#change_user_status",
verb => "Change user status",
priv => "admin",
cat => "01usr/03",
desc => "Admins can change the ustatus of a user",
x_csrf_protection => 1,
x_form => {
HIDDENNAME => {form_type => "hidden_field"},
pause99_change_user_status_user => {form_type => "text_field"},
pause99_change_user_status_new_ustatus => {form_type => "select_field"},
pause99_change_user_status_sub => {form_type => "submit_button"},
},
},
select_user => {
x_mojo_to => "admin#select_user",
verb => "Select User/Action",
priv => "admin",
cat => "01usr/03",
cat => "01usr/04",
desc => "Admins can access PAUSE as-if they were somebody else. Here they select a user/action pair.",
method => 'POST',
x_form => {
Expand Down
44 changes: 44 additions & 0 deletions lib/pause_2017/PAUSE/Web/Controller/Admin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,50 @@ sub edit_ml {
}
}

sub change_user_status {
my $c = shift;
my $pause = $c->stash(".pause");
my $mgr = $c->app->pause;
my $req = $c->req;
my $u = $c->active_user_record;

my %valid_status = map {$_ => 1} qw(active nologin);

my $user = $req->param("pause99_change_user_status_user");
my $new_ustatus = $req->param("pause99_change_user_status_new_ustatus");
if ($user) {
$pause->{user} = uc $user;
my $dbh = $mgr->connect;
my $sql = qq{SELECT ustatus FROM users WHERE userid = ?};
my $row = $dbh->selectrow_arrayref($sql, undef, uc $user);
if ($row) {
$pause->{ustatus} = $row->[0];
} else {
$pause->{user_not_found} = 1;
return;
}

if ($new_ustatus && $valid_status{$new_ustatus} && $new_ustatus ne $pause->{ustatus}) {
my $sql = qq{UPDATE users SET ustatus = ?, changed = ?, changedby = ? WHERE userid = ?};
my $sth = $dbh->prepare($sql);
my $ret = $sth->execute($new_ustatus, time, $u->{userid}, uc $user);
$sth->finish;
if ($ret) {
$pause->{changed} = 1;
$pause->{new_ustatus} = $new_ustatus;
my $mailblurb = $c->render_to_string("email/admin/change_user_status", format => "email");
my @to = ($u->{secretemail}||$u->{email}, $mgr->config->mailto_admins);
warn "sending to[@to]";
warn "mailblurb[$mailblurb]";
my $header = {
Subject => "User status update for $user"
};
$mgr->send_mail_multi(\@to, $header, $mailblurb);
}
}
}
}

sub select_user {
my $c = shift;
my $pause = $c->stash(".pause");
Expand Down
19 changes: 19 additions & 0 deletions lib/pause_2017/templates/admin/change_user_status.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
% layout 'layout';
% my $pause = stash(".pause") || {};

<input type="hidden" name="HIDDENNAME" value="<%= $pause->{HiddenUser}{userid} %>">

% if ($pause->{user_not_found}) {
<div class="messagebox error">
<p>User <%= $pause->{user} %> is not found.</p>
</div>
% } elsif ($pause->{changed}) {
<div class="messagebox info">
<p><%= $pause->{user} %>'s status has changed from <%= $pause->{ustatus} %> to <%= $pause->{new_ustatus} %>.</p>
</div>
% }

%= csrf_field
%= text_field "pause99_change_user_status_user" => $pause->{user};
%= select_field "pause99_change_user_status_new_ustatus" => ['nologin', 'active'];
%= submit_button "Change", name => "pause99_change_user_status_sub";
13 changes: 13 additions & 0 deletions lib/pause_2017/templates/email/admin/change_user_status.email.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
% my $pause = stash(".pause") || {};
%
%#------------------------------------------------------------------
%
Record update in the PAUSE users database:

The ustatus of <%= $pause->{user} %> has changed from <%= $pause->{ustatus} %> to <%= $pause->{new_ustatus} %>.

Data entered by <%= $pause->{User}{fullname} %>.

Thanks,
--
The PAUSE Team

0 comments on commit 4ed66e7

Please sign in to comment.