diff options
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/BMO/Extension.pm | 10 | ||||
-rw-r--r-- | extensions/BMO/lib/Reports.pm | 109 | ||||
-rw-r--r-- | extensions/BMO/template/en/default/hook/reports/menu-end.html.tmpl | 59 | ||||
-rw-r--r-- | extensions/BMO/template/en/default/pages/group_membership.html.tmpl | 75 | ||||
-rw-r--r-- | extensions/BMO/template/en/default/pages/group_membership.txt.tmpl | 16 |
5 files changed, 233 insertions, 36 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 3de85dbec..f34579e34 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -56,9 +56,10 @@ use Bugzilla::Extension::BMO::Data qw($cf_visible_in_products %product_sec_groups); use Bugzilla::Extension::BMO::Reports qw(user_activity_report triage_reports - group_admins + group_admins_report email_queue_report - release_tracking_report); + release_tracking_report + group_membership_report); our $VERSION = '0.1'; @@ -169,7 +170,10 @@ sub page_before_template { Bugzilla->request_cache->{'bmo_fields_page'} = 1; } elsif ($page eq 'group_admins.html') { - group_admins($vars); + group_admins_report($vars); + } + elsif ($page eq 'group_membership.html' or $page eq 'group_membership.txt') { + group_membership_report($page, $vars); } elsif ($page eq 'email_queue.html') { email_queue_report($vars); diff --git a/extensions/BMO/lib/Reports.pm b/extensions/BMO/lib/Reports.pm index 8d8dc3c0e..89debbf08 100644 --- a/extensions/BMO/lib/Reports.pm +++ b/extensions/BMO/lib/Reports.pm @@ -25,9 +25,10 @@ use base qw(Exporter); our @EXPORT_OK = qw(user_activity_report triage_reports - group_admins + group_admins_report email_queue_report - release_tracking_report); + release_tracking_report + group_membership_report); sub user_activity_report { my ($vars) = @_; @@ -541,7 +542,7 @@ sub triage_reports { $vars->{'input'} = $input; } -sub group_admins { +sub group_admins_report { my ($vars) = @_; my $dbh = Bugzilla->dbh; my $user = Bugzilla->user; @@ -578,6 +579,108 @@ sub group_admins { $vars->{'groups'} = \@groups; } +sub group_membership_report { + my ($page, $vars) = @_; + my $dbh = Bugzilla->dbh; + my $user = Bugzilla->user; + my $cgi = Bugzilla->cgi; + + ($user->in_group('editusers') || $user->in_group('infrasec')) + || ThrowUserError('auth_failure', { group => 'editusers', + action => 'run', + object => 'group_admins' }); + + my $who = $cgi->param('who'); + if (!defined($who) || $who eq '') { + if ($page eq 'group_membership.txt') { + print $cgi->redirect("page.cgi?id=group_membership.html&output=txt"); + exit; + } + $vars->{'output'} = $cgi->param('output'); + return; + } + + Bugzilla::User::match_field({ 'who' => {'type' => 'multi'} }); + $who = Bugzilla->input_params->{'who'}; + $who = ref($who) ? $who : [ $who ]; + + my @users; + foreach my $login (@$who) { + my $u = Bugzilla::User->new(login_to_id($login, 1)); + + # this is lifted from $user->groups() + # we need to show which groups are direct and which are inherited + + my $groups_to_check = $dbh->selectcol_arrayref( + q{SELECT DISTINCT group_id + FROM user_group_map + WHERE user_id = ? AND isbless = 0}, undef, $u->id); + + my $rows = $dbh->selectall_arrayref( + "SELECT DISTINCT grantor_id, member_id + FROM group_group_map + WHERE grant_type = " . GROUP_MEMBERSHIP); + + my %group_membership; + foreach my $row (@$rows) { + my ($grantor_id, $member_id) = @$row; + push (@{ $group_membership{$member_id} }, $grantor_id); + } + + my %checked_groups; + my %direct_groups; + my %indirect_groups; + my %groups; + + foreach my $member_id (@$groups_to_check) { + $direct_groups{$member_id} = 1; + } + + while (scalar(@$groups_to_check) > 0) { + my $member_id = shift @$groups_to_check; + if (!$checked_groups{$member_id}) { + $checked_groups{$member_id} = 1; + my $members = $group_membership{$member_id}; + my @new_to_check = grep(!$checked_groups{$_}, @$members); + push(@$groups_to_check, @new_to_check); + foreach my $id (@new_to_check) { + $indirect_groups{$id} = $member_id; + } + $groups{$member_id} = 1; + } + } + + my @groups; + my $ra_groups = Bugzilla::Group->new_from_list([keys %groups]); + foreach my $group (@$ra_groups) { + my $via; + if ($direct_groups{$group->id}) { + $via = ''; + } else { + foreach my $g (@$ra_groups) { + if ($g->id == $indirect_groups{$group->id}) { + $via = $g->name; + last; + } + } + } + push @groups, { + name => $group->name, + desc => $group->description, + via => $via, + }; + } + + push @users, { + user => $u, + groups => \@groups, + }; + } + + $vars->{'who'} = $who; + $vars->{'users'} = \@users; +} + sub email_queue_report { my ($vars, $filter) = @_; my $dbh = Bugzilla->dbh; diff --git a/extensions/BMO/template/en/default/hook/reports/menu-end.html.tmpl b/extensions/BMO/template/en/default/hook/reports/menu-end.html.tmpl index 7c2b2d753..852ed6cc4 100644 --- a/extensions/BMO/template/en/default/hook/reports/menu-end.html.tmpl +++ b/extensions/BMO/template/en/default/hook/reports/menu-end.html.tmpl @@ -1,49 +1,48 @@ -[%# The contents of this file are subject to the Mozilla Public - # License Version 1.1 (the "License"); you may not use this file - # except in compliance with the License. You may obtain a copy of - # the License at http://www.mozilla.org/MPL/ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. # - # Software distributed under the License is distributed on an "AS - # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - # implied. See the License for the specific language governing - # rights and limitations under the License. - # - # The Original Code is the BMO Extension - # - # The Initial Developer of the Original Code is the Mozilla Foundation - # Portions created by the Initial Developers are Copyright (C) 2011 the - # Initial Developer. All Rights Reserved. - # - # Contributor(s): - # Byron Jones <bjones@mozilla.com> + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. #%] <h2>Other Reports</h2> <ul> <li> - <strong><a href="[% urlbase FILTER none - %]page.cgi?id=user_activity.html">User Changes</a></strong> - Show changes - made by an individual user. + <strong> + <a href="[% urlbase FILTER none %]page.cgi?id=user_activity.html">User Changes</a> + </strong> - Show changes made by an individual user. </li> <li> - <strong><a href="[% urlbase FILTER none - %]page.cgi?id=triage_reports.html">Triage Report</a></strong> - Report - on UNCONFIRMED [% terms.bugs %] to assist triage. + <strong> + <a href="[% urlbase FILTER none %]page.cgi?id=triage_reports.html">Triage Report</a> + </strong> - Report on UNCONFIRMED [% terms.bugs %] to assist triage. </li> <li> - <strong><a href="[% urlbase FILTER none - %]page.cgi?id=release_tracking_report.html">Release Tracking Report</a></strong> - - For triaging release-train flag information. + <strong> + <a href="[% urlbase FILTER none %]page.cgi?id=release_tracking_report.html">Release Tracking Report</a> + </strong> - For triaging release-train flag information. </li> [% IF user.in_group('editusers') %] <li> - <strong><a href="[% urlbase FILTER none - %]page.cgi?id=group_admins.html">Group Admins</a></strong> - Group Admins Report + <strong> + <a href="[% urlbase FILTER none %]page.cgi?id=group_admins.html">Group Admins</a> + </strong> - Group Admins Report </li> + [% END %] + [% IF user.in_group('editusers') || user.in_group('infrasec') %] + <li> + <strong> + <a href="[% urlbase FILTER none %]page.cgi?id=group_membership.html">Group Membership Report</a> + </strong> - Lists the groups a user is a member of. + </li> + [% END %] + [% IF user.in_group('admin') %] <li> - <strong><a href="[% urlbase FILTER none - %]page.cgi?id=email_queue.html">Email Queue</a></strong> - TheSchwartz queue + <strong> + <a href="[% urlbase FILTER none %]page.cgi?id=email_queue.html">Email Queue</a> + </strong> - TheSchwartz queue </li> [% END %] </ul> diff --git a/extensions/BMO/template/en/default/pages/group_membership.html.tmpl b/extensions/BMO/template/en/default/pages/group_membership.html.tmpl new file mode 100644 index 000000000..2680c7da2 --- /dev/null +++ b/extensions/BMO/template/en/default/pages/group_membership.html.tmpl @@ -0,0 +1,75 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% PROCESS global/header.html.tmpl + title = "Group Membership Report" + yui = [ 'autocomplete' ] + style_urls = [ "extensions/BMO/web/styles/reports.css" ] + javascript_urls = [ "js/field.js" ] +%] + +<form method="GET" action="page.cgi"> +<input type="hidden" name="id" id="id" value="group_membership.html"> + +<table id="parameters"> +<tr> + <th>User(s):</th> + <td> + [% INCLUDE global/userselect.html.tmpl + id => "who" + name => "who" + value => who.join(', ') + size => 40 + classes => ["bz_userfield"] + multiple => 5 + field_title => "One or more email address (comma delimited)" + %] + </td> + <td> </td> + <td> + <select name="output" + onchange="document.getElementById('id').value = 'group_membership.' + this.value"> + <option value="html" [% 'selected' IF output == 'html' %]>HTML</option> + <option value="txt" [% 'selected' IF output == 'txt' %]>Text</option> + </select> + </td> + <td> + <input type="submit" value="Generate"> + </td> +</tr> +</table> + +</form> + +[% IF users.size %] + + <table border="0" cellspacing="0" id="report" width="100%"> + [% FOREACH u = users %] + <tr> + <th colspan="3">[% u.user.identity FILTER html %]</th> + </tr> + [% FOREACH g = u.groups %] + <tr> + <td> </td> + <td>[% g.name FILTER html %]</td> + <td>[% g.desc FILTER html %]</td> + <td> + [% IF g.via == '' %] + direct + [% ELSE %] + <i>[% g.via FILTER html %]</i> + [% END %] + </td> + </tr> + [% END %] + [% END %] + </table> + +[% END %] + +[% INCLUDE global/footer.html.tmpl %] diff --git a/extensions/BMO/template/en/default/pages/group_membership.txt.tmpl b/extensions/BMO/template/en/default/pages/group_membership.txt.tmpl new file mode 100644 index 000000000..9958f0877 --- /dev/null +++ b/extensions/BMO/template/en/default/pages/group_membership.txt.tmpl @@ -0,0 +1,16 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% FOREACH u = users %] +[% u.user.login FILTER none%]: + [% FOREACH g = u.groups %] + [% g.name FILTER none %] + [% ',' UNLESS loop.last %] + [% END %] + [% "\n" %] +[% END %] |