From d2b251615f42ecda6eb10871b57329ed11b0e57b Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 21 Feb 2012 16:21:49 +0800 Subject: bug 728811: add a report showing group membership --- extensions/BMO/Extension.pm | 10 +- extensions/BMO/lib/Reports.pm | 109 ++++++++++++++++++++- .../en/default/hook/reports/menu-end.html.tmpl | 59 ++++++----- .../en/default/pages/group_membership.html.tmpl | 75 ++++++++++++++ .../en/default/pages/group_membership.txt.tmpl | 16 +++ 5 files changed, 233 insertions(+), 36 deletions(-) create mode 100644 extensions/BMO/template/en/default/pages/group_membership.html.tmpl create mode 100644 extensions/BMO/template/en/default/pages/group_membership.txt.tmpl (limited to 'extensions') 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 + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. #%]

Other Reports

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" ] +%] + +
+ + + + + + + + + + +
User(s): + [% 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)" + %] +   + + + +
+ +
+ +[% IF users.size %] + + + [% FOREACH u = users %] + + + + [% FOREACH g = u.groups %] + + + + + + + [% END %] + [% END %] +
[% u.user.identity FILTER html %]
 [% g.name FILTER html %][% g.desc FILTER html %] + [% IF g.via == '' %] + direct + [% ELSE %] + [% g.via FILTER html %] + [% END %] +
+ +[% 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 %] -- cgit v1.2.3-24-g4f1b