Skip to content

Commit

Permalink
feat: Enable Org Admins to View and Modify Member Admin Status (#8840)
Browse files Browse the repository at this point in the history
Fixes #8780

---------
Co-authored-by: Pierre Slamich <[email protected]>
Co-authored-by: Stéphane Gigandet <[email protected]>
Co-authored-by: Alex Garel <[email protected]>
  • Loading branch information
MonalikaPatnaik authored and alexgarel committed Nov 21, 2023
1 parent 81505b3 commit d2fc609
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
39 changes: 37 additions & 2 deletions cgi/org.pl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
use Storable qw/dclone/;
use Encode;
use Log::Any qw($log);

use Array::Diff;
my @org_members;
my %user_is_admin;
my $type = single_param('type') || 'edit';
my $action = single_param('action') || 'display';

Expand Down Expand Up @@ -384,6 +386,31 @@
}
}

elsif ($type eq 'admin_status') {
# verify right to change status
if (is_user_in_org_group($org_ref, $User_id, "admins") or $admin or $User{pro_moderator}) {
# inputs are in the form admin_status_<user_id>, get them among param and extract the user_id
my @user_ids = sort map {$_ =~ /^admin_status_/ ? $' : ()} param();
my @existing_admins = sort grep {is_user_in_org_group($org_ref, $_, "admins")} keys %{$org_ref->{members}};
my $diff = Array::Diff->diff(\@existing_admins, \@user_ids);

$log->debug("my user ids", {user_ids => @user_ids, difference => $diff})
if $log->is_debug();

foreach my $user_id (@{$diff->added}) {
add_user_to_org($org_ref, $user_id, ["admins"]);
}

foreach my $user_id (@{$diff->deleted}) {
# never remove current user from admin list
next if ($user_id eq $User_id);
remove_user_from_org($org_ref, $user_id, ["admins"]);
}

store_org($org_ref);
$template_data_ref->{result} = lang("admin_status_updated");
}
}
$template_data_ref->{profile_url} = canonicalize_tag_link("editors", "org-" . $orgid);
$template_data_ref->{profile_name} = sprintf(lang('user_s_page'), $org_ref->{name});
}
Expand All @@ -396,12 +423,20 @@
$log->debug("org form - template data", {template_data_ref => $template_data_ref}) if $log->is_debug();

# allow org admins to view the list of users associated with their org
my @org_members;

foreach my $member_id (sort keys %{$org_ref->{members}}) {
if (is_user_in_org_group($org_ref, $member_id, "admins")) {
$user_is_admin{$member_id} = 1;
}
else {
$user_is_admin{$member_id} = 0;
}
my $member_user_ref = retrieve_user($member_id);
push @org_members, $member_user_ref;
}
$template_data_ref->{org_members} = \@org_members;
$template_data_ref->{user_is_admin} = \%user_is_admin;
$template_data_ref->{current_user_id} = $User_id;

$tt->process('web/pages/org_form/org_form.tt.html', $template_data_ref, \$html)
or $html = "<p>template error: " . $tt->error() . "</p>";
Expand Down
2 changes: 1 addition & 1 deletion cpanfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Should also be available as Debian packages
# If a minimum version number is specified, "cpanm --skip-satisfied" will install a newer version than apt if one is available in cpan.

requires 'Array::Diff';
requires 'CGI', '>= 4.53, < 5.0'; # libcgi-pm-perl
requires 'Tie::IxHash'; # libtie-ixhash-perl
requires 'LWP::Authen::Digest'; # libwww-perl
Expand Down
16 changes: 16 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ msgctxt "add_user_existing_org_pending"
msgid "Your request to join the organization is pending approval of the organization administrator."
msgstr "Your request to join the organization is pending approval of the organization administrator."

msgctxt "admin_status_updated"
msgid "Admin Status Updated"
msgstr "Admin Status Updated"

msgctxt "admin_status"
msgid "Admin Status"
msgstr "Admin Status"

msgctxt "grant_remove_admin_status"
msgid "Grant/Remove Admin status"
msgstr "Grant/Remove Admin status"

msgctxt "please_email_producers"
msgid "Please e-mail <a href=\"mailto:[email protected]\">[email protected]</a> if you have any question."
msgstr "Please e-mail <a href=\"mailto:[email protected]\">[email protected]</a> if you have any question."
Expand Down Expand Up @@ -4181,6 +4193,10 @@ msgctxt "remove_products"
msgid "Remove all the products"
msgstr "Remove all the products"

msgctxt "remove_user"
msgid "Remove user"
msgstr "Remove user"

msgctxt "remove_products_from_producers_platform"
msgid "Remove all your products from the platform for producers"
msgstr "Remove all your products from the platform for producers"
Expand Down
16 changes: 16 additions & 0 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ msgctxt "add_user_existing_org_pending"
msgid "Your request to join the organization is pending approval of the organization administrator."
msgstr "Your request to join the organization is pending approval of the organization administrator."

msgctxt "admin_status_updated"
msgid "Admin Status Updated"
msgstr "Admin Status Updated"

msgctxt "admin_status"
msgid "Admin Status"
msgstr "Admin Status"

msgctxt "grant_remove_admin_status"
msgid "Grant/Remove Admin status"
msgstr "Grant/Remove Admin status"

msgctxt "please_email_producers"
msgid "Please e-mail <a href=\"mailto:[email protected]\">[email protected]</a> if you have any question."
msgstr "Please e-mail <a href=\"mailto:[email protected]\">[email protected]</a> if you have any question."
Expand Down Expand Up @@ -4205,6 +4217,10 @@ msgctxt "remove_products"
msgid "Remove all the products"
msgstr "Remove all the products"

msgctxt "remove_user"
msgid "Remove user"
msgstr "Remove user"

msgctxt "remove_products_from_producers_platform"
msgid "Remove all your products from the platform for producers"
msgstr "Remove all your products from the platform for producers"
Expand Down
14 changes: 14 additions & 0 deletions templates/web/pages/org_form/org_form.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h2>[% lang("organization_members") %]</h2>
<thead>
<tr>
<th>[% lang("serial_no") %]</th>
<th>[% lang("admin_status") %]</th>
<th>[% lang("username") %]</th>
<th>[% lang("name") %]</th>
<th>[% lang("email") %]</th>
Expand All @@ -32,6 +33,11 @@ <h2>[% lang("organization_members") %]</h2>
[% FOREACH users IN org_members %]
<tr>
<td>[% count %].</td>
<td>
[% SET userid = users.userid %]
[% SET user_in_admin_status = user_is_admin.$userid %]
<input form="admin_users_form" type="checkbox" name="admin_status_[% users.userid %]" value="1" class="admin-checkbox" [% IF user_in_admin_status %]checked[% END %] [% IF current_user_id == userid %]disabled[% END %]>
</td>
<td>[% users.userid %]</td>
<td>[% users.name %]</td>
<td>[% users.email %]</td>
Expand All @@ -51,6 +57,14 @@ <h2>[% lang("organization_members") %]</h2>
[% END %]
</tbody>
</table>
<div>
<form id='admin_users_form' method="post" action="/cgi/org.pl">
<!-- admin_status_xxxx elements above are also part of it, thanks to form attribute -->
<input type="hidden" name="action" value="process" />
<input type="hidden" name="type" value="admin_status" />
<input type="submit" name="grant_remove_admin_status" class="button" style="margin-bottom: 10px;" value="[% lang("grant_remove_admin_status") %]"/>
</form>
</div>
</div>
[% END %]

Expand Down

0 comments on commit d2fc609

Please sign in to comment.