Commit cc73e8e4 authored by erik%dasbistro.com's avatar erik%dasbistro.com

Bug 253721: Add group-based lists to whining

Patch by Erik Stambaugh <erik@dasbistro.com> r=joel, r,a=justdave
parent 1ab7c9d7
...@@ -62,6 +62,9 @@ use base qw(Exporter); ...@@ -62,6 +62,9 @@ use base qw(Exporter);
GROUP_BLESS GROUP_BLESS
GROUP_VISIBLE GROUP_VISIBLE
MAILTO_USER
MAILTO_GROUP
DEFAULT_COLUMN_LIST DEFAULT_COLUMN_LIST
DEFAULT_QUERY_NAME DEFAULT_QUERY_NAME
...@@ -206,6 +209,9 @@ use constant GROUP_MEMBERSHIP => 0; ...@@ -206,6 +209,9 @@ use constant GROUP_MEMBERSHIP => 0;
use constant GROUP_BLESS => 1; use constant GROUP_BLESS => 1;
use constant GROUP_VISIBLE => 2; use constant GROUP_VISIBLE => 2;
use constant MAILTO_USER => 0;
use constant MAILTO_GROUP => 1;
# The default list of columns for buglist.cgi # The default list of columns for buglist.cgi
use constant DEFAULT_COLUMN_LIST => ( use constant DEFAULT_COLUMN_LIST => (
"bug_severity", "priority", "rep_platform","assigned_to", "bug_severity", "priority", "rep_platform","assigned_to",
......
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# 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/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Joel Peshkin <bugreport@peshkin.net>
# Erik Stambaugh <erik@dasbistro.com>
use strict;
package Bugzilla::Group;
use Bugzilla::Config;
# ValidateGroupName checks to see if ANY of the users in the provided list
# of user objects can see the named group. It returns the group id if
# successful and undef otherwise.
sub ValidateGroupName {
my ($name, @users) = (@_);
my $dbh = Bugzilla->dbh;
my $query = "SELECT id FROM groups " .
"WHERE name = ?";
if (Param('usevisibilitygroups')) {
my @visible = (-1);
foreach my $user (@users) {
$user && push @visible, @{$user->visible_groups_direct};
}
my $visible = join(', ', @visible);
$query .= " AND id IN($visible)";
}
my $sth = $dbh->prepare($query);
$sth->execute($name);
my ($ret) = $sth->fetchrow_array();
return $ret;
}
1;
...@@ -40,6 +40,7 @@ use Bugzilla::Config; ...@@ -40,6 +40,7 @@ use Bugzilla::Config;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Group;
use Date::Format; use Date::Format;
use Date::Parse; use Date::Parse;
...@@ -382,7 +383,7 @@ sub init { ...@@ -382,7 +383,7 @@ sub init {
( (
"^(?:assigned_to|reporter|qa_contact),(?:notequals|equals|anyexact),%group\\.(\\w+)%" => sub { "^(?:assigned_to|reporter|qa_contact),(?:notequals|equals|anyexact),%group\\.(\\w+)%" => sub {
my $group = $1; my $group = $1;
my $groupid = ValidateGroupName( $group, ($user)); my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user));
$groupid || ThrowUserError('invalid_group_name',{name => $group}); $groupid || ThrowUserError('invalid_group_name',{name => $group});
my @childgroups = @{$user->flatten_group_membership($groupid)}; my @childgroups = @{$user->flatten_group_membership($groupid)};
my $table = "user_group_map_$chartid"; my $table = "user_group_map_$chartid";
...@@ -419,7 +420,7 @@ sub init { ...@@ -419,7 +420,7 @@ sub init {
"^(?:cc),(?:notequals|equals|anyexact),%group\\.(\\w+)%" => sub { "^(?:cc),(?:notequals|equals|anyexact),%group\\.(\\w+)%" => sub {
my $group = $1; my $group = $1;
my $groupid = ValidateGroupName( $group, ($user)); my $groupid = Bugzilla::Group::ValidateGroupName( $group, ($user));
$groupid || ThrowUserError('invalid_group_name',{name => $group}); $groupid || ThrowUserError('invalid_group_name',{name => $group});
my @childgroups = @{$user->flatten_group_membership($groupid)}; my @childgroups = @{$user->flatten_group_membership($groupid)};
my $chartseq = $chartid; my $chartseq = $chartid;
...@@ -1495,24 +1496,6 @@ sub pronoun { ...@@ -1495,24 +1496,6 @@ sub pronoun {
return 0; return 0;
} }
# ValidateGroupName checks to see if ANY of the users in the provided list
# of user objects can see the named group. It returns the group id if
# successful and undef otherwise.
sub ValidateGroupName {
my ($name, @users) = (@_);
my @visible = (-1);
foreach my $user (@users) {
$user && push @visible, @{$user->visible_groups_direct};
}
my $visible = join(', ', @visible);
my $dbh = Bugzilla->dbh;
my $sth = $dbh->prepare("SELECT id FROM groups " .
"WHERE name = ? AND id IN($visible)");
$sth->execute($name);
my ($ret) = $sth->fetchrow_array();
return $ret;
}
# Validate that the query type is one we can deal with # Validate that the query type is one we can deal with
sub IsValidQueryType sub IsValidQueryType
{ {
......
...@@ -2108,7 +2108,8 @@ $table{whine_schedules} = ...@@ -2108,7 +2108,8 @@ $table{whine_schedules} =
run_day varchar(32), run_day varchar(32),
run_time varchar(32), run_time varchar(32),
run_next datetime, run_next datetime,
mailto_userid mediumint not null, mailto mediumint not null,
mailto_type smallint not null default 0,
index(run_next), index(run_next),
index(eventid)'; index(eventid)';
...@@ -4223,6 +4224,11 @@ AddField("profiles", "extern_id", "varchar(64)"); ...@@ -4223,6 +4224,11 @@ AddField("profiles", "extern_id", "varchar(64)");
AddField('flagtypes', 'grant_group_id', 'mediumint null'); AddField('flagtypes', 'grant_group_id', 'mediumint null');
AddField('flagtypes', 'request_group_id', 'mediumint null'); AddField('flagtypes', 'request_group_id', 'mediumint null');
# 2004-01-03 - bug 253721 erik@dasbistro.com
# mailto is no longer just userids
RenameField('whine_schedules', 'mailto_userid', 'mailto');
AddField('whine_schedules', 'mailto_type', 'smallint not null default 0');
# 2005-01-29 - mkanat@kerio.com # 2005-01-29 - mkanat@kerio.com
if (!GetFieldDef('longdescs', 'already_wrapped')) { if (!GetFieldDef('longdescs', 'already_wrapped')) {
AddField('longdescs', 'already_wrapped', 'tinyint not null default 0'); AddField('longdescs', 'already_wrapped', 'tinyint not null default 0');
......
...@@ -424,6 +424,9 @@ if ($action eq 'delete') { ...@@ -424,6 +424,9 @@ if ($action eq 'delete') {
SendSQL("DELETE FROM group_group_map WHERE grantor_id = $gid"); SendSQL("DELETE FROM group_group_map WHERE grantor_id = $gid");
SendSQL("DELETE FROM bug_group_map WHERE group_id = $gid"); SendSQL("DELETE FROM bug_group_map WHERE group_id = $gid");
SendSQL("DELETE FROM group_control_map WHERE group_id = $gid"); SendSQL("DELETE FROM group_control_map WHERE group_id = $gid");
SendSQL("DELETE FROM whine_schedules WHERE " .
"mailto_type = " . MAILTO_GROUP . " " .
"AND mailto = $gid");
SendSQL("DELETE FROM groups WHERE id = $gid"); SendSQL("DELETE FROM groups WHERE id = $gid");
} }
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
# schedule: array of hashes containing schedule info: # schedule: array of hashes containing schedule info:
# day: value in day column # day: value in day column
# time: value selected in time column # time: value selected in time column
# mailto: recipient's email address # mailto_type: 0=user 1=group
# mailto: recipient's id (profile or group)
# queries: as with schedule, an anonymous array containing hashes of: # queries: as with schedule, an anonymous array containing hashes of:
# name: the named query's name # name: the named query's name
# title: title to be displayed on the results # title: title to be displayed on the results
...@@ -158,6 +159,16 @@ ...@@ -158,6 +159,16 @@
</td> </td>
<td align="left"> <td align="left">
[% IF mail_others %] [% IF mail_others %]
<input type="hidden" name="orig_mailto_type_[% schedule.id %]"
value="[% schedule.mailto_type FILTER html %]">
<select name="mailto_type_[% schedule.id %]">
<option value="0" [% IF schedule.mailto_type == 0 %]
selected
[% END %]>User</option>
<option value="1" [% IF schedule.mailto_type == 1 %]
selected
[% END %]>Group</option>
</select>
<input type="hidden" name="orig_mailto_[% schedule.id %]" <input type="hidden" name="orig_mailto_[% schedule.id %]"
value="[% schedule.mailto FILTER html %]"> value="[% schedule.mailto FILTER html %]">
<input type="text" name="mailto_[% schedule.id %]" <input type="text" name="mailto_[% schedule.id %]"
......
...@@ -75,7 +75,7 @@ my $sth_next_scheduled_event = $dbh->prepare( ...@@ -75,7 +75,7 @@ my $sth_next_scheduled_event = $dbh->prepare(
# get all pending schedules matching an eventid # get all pending schedules matching an eventid
my $sth_schedules_by_event = $dbh->prepare( my $sth_schedules_by_event = $dbh->prepare(
"SELECT id, mailto_userid " . "SELECT id, mailto_type, mailto " .
"FROM whine_schedules " . "FROM whine_schedules " .
"WHERE eventid=? AND run_next <= NOW()" "WHERE eventid=? AND run_next <= NOW()"
); );
...@@ -245,18 +245,42 @@ sub get_next_event { ...@@ -245,18 +245,42 @@ sub get_next_event {
# Add the users from those schedules to the list # Add the users from those schedules to the list
while (my $row = $sth_schedules_by_event->fetch) { while (my $row = $sth_schedules_by_event->fetch) {
my ($sid, $mailto) = @{$row}; my ($sid, $mailto_type, $mailto) = @{$row};
# Only bother doing any work if this user has whine permission # Only bother doing any work if this user has whine permission
if ($owner->in_group('bz_canusewhines')) { if ($owner->in_group('bz_canusewhines')) {
if (not defined $user_objects{$mailto}) {
if ($mailto == $owner_id) { if ($mailto_type == MAILTO_USER) {
$user_objects{$mailto} = $owner; if (not defined $user_objects{$mailto}) {
if ($mailto == $owner_id) {
$user_objects{$mailto} = $owner;
}
elsif ($whineatothers) {
$user_objects{$mailto} = Bugzilla::User->new($mailto);
}
} }
elsif ($whineatothers) { }
$user_objects{$mailto} = Bugzilla::User->new($mailto); elsif ($mailto_type == MAILTO_GROUP) {
my $sth = $dbh->prepare("SELECT name FROM groups " .
"WHERE id=?");
$sth->execute($mailto);
my $groupname = $sth->fetch->[0];
my $group_id = Bugzilla::Group::ValidateGroupName(
$groupname, $owner);
if ($group_id) {
$sth = $dbh->prepare("SELECT user_id FROM " .
"user_group_map " .
"WHERE group_id=?");
$sth->execute($group_id);
for my $row (@{$sth->fetchall_arrayref}) {
if (not defined $user_objects{$row->[0]}) {
$user_objects{$row->[0]} =
Bugzilla::User->new($row->[0]);
}
}
} }
} }
} }
reset_timer($sid); reset_timer($sid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment