Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable Org Admins to View and Modify Member Admin Status #8840

Merged
Show file tree
Hide file tree
Changes from 7 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
30 changes: 30 additions & 0 deletions cgi/org.pl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

my $orgid = $Org_id;

my @admin_status;

if (defined single_param('orgid')) {
$orgid = get_fileid(single_param('orgid'), 1);
}
Expand Down Expand Up @@ -384,6 +386,30 @@
}
}

elsif ($type eq 'admin_status') {
if (is_user_in_org_group($org_ref, $User_id, "admins") or $admin or $User{pro_moderator}) {
foreach my $user_id (sort keys %{$org_ref->{members}}) {
my $checkbox_name = "admin_status_hidden_" . $user_id;
my $is_admin = single_param($checkbox_name) ? 1 : 0;
$log->debug("checkbox name", {checkss => $checkbox_name, statuss => $is_admin}) if $log->is_debug();
MonalikaPatnaik marked this conversation as resolved.
Show resolved Hide resolved

if ($is_admin) {
add_user_to_org($org_ref, $user_id, ["admins"]);
unless (grep {$_ == $user_id} @admin_status) {
push @admin_status, $user_id;

}
}
else {
remove_user_from_org($org_ref, $user_id, ["admins"]);
@admin_status = grep {$_ != $user_id} @admin_status;
}
store_org($org_ref);
Copy link
Contributor

Choose a reason for hiding this comment

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

store_org() should be outside the for loop, otherwise we will save the org as many times as there are users

}
MonalikaPatnaik marked this conversation as resolved.
Show resolved Hide resolved

$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 @@ -398,10 +424,14 @@
# 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")) {
push @admin_status, $member_id;
}
my $member_user_ref = retrieve_user($member_id);
push @org_members, $member_user_ref;
}
$template_data_ref->{org_members} = \@org_members;
$template_data_ref->{admin_status} = \@admin_status;

$tt->process('web/pages/org_form/org_form.tt.html', $template_data_ref, \$html)
or $html = "<p>template error: " . $tt->error() . "</p>";
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 @@ -4177,6 +4189,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 @@ -4201,6 +4213,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
35 changes: 35 additions & 0 deletions templates/web/pages/org_form/org_form.tt.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- start templates/[% template.name %] -->

<script>
[% INCLUDE web/pages/org_form/org_form.tt.js %]
</script>

[% IF action == 'display' || action == 'none' %]
[% INCLUDE 'web/common/includes/error_list.tt.html' %]
[% END %]
Expand All @@ -18,6 +22,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 +37,18 @@ <h2>[% lang("organization_members") %]</h2>
[% FOREACH users IN org_members %]
<tr>
<td>[% count %].</td>
<td>
[% SET user_in_admin_status = 0 %]
[% FOREACH admin_id IN admin_status %]
[% IF admin_id == users.userid %]
[% SET user_in_admin_status = 1 %]
[% END %]
[% END %]
MonalikaPatnaik marked this conversation as resolved.
Show resolved Hide resolved

<input type="checkbox" name="admin_status_[% users.userid %]" value="1" class="admin-checkbox" [% IF user_in_admin_status %]checked[% END %]>
<input type="hidden" name="admin_status_hidden_[% users.userid %]" value="0">

</td>
<td>[% users.userid %]</td>
<td>[% users.name %]</td>
<td>[% users.email %]</td>
Expand All @@ -51,6 +68,24 @@ <h2>[% lang("organization_members") %]</h2>
[% END %]
</tbody>
</table>
<div>
<form id='hiddenInputForm' method="post" action="/cgi/org.pl">
MonalikaPatnaik marked this conversation as resolved.
Show resolved Hide resolved
<input type="hidden" name="action" value="process" />
<input type="hidden" name="type" value="admin_status" />

[% FOREACH users IN org_members %]
[% SET initial_hidden_value = '0' %]
[% FOREACH admin_id IN admin_status %]
[% IF admin_id == users.userid %]
[% SET initial_hidden_value = '1' %]
[% END %]
[% END %]
<input type="hidden" name="admin_status_hidden_[% users.userid %]" value="[% initial_hidden_value %]">
[% END %]

<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
11 changes: 11 additions & 0 deletions templates/web/pages/org_form/org_form.tt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
document.addEventListener('DOMContentLoaded', function() {
var checkboxForm =document.querySelectorAll('.admin-checkbox');
var hiddenInputForm = document.getElementById('hiddenInputForm');

checkboxForm.forEach(function(checkbox) {
checkbox.addEventListener('change', function() {
var hiddenInput = hiddenInputForm.querySelector('input[name="admin_status_hidden_' + checkbox.name.split('_')[2] + '"]');
hiddenInput.value = checkbox.checked ? '1' : '0';
});
});
});
Loading