From 152f61366bd9b268cd838307c1e58399003ef2c7 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 8 Aug 2007 18:58:19 +0000 Subject: Bug 332149: Ability to have symbols placed next to user names based on group membership - Patch by Frédéric Buclin r=myk a=LpSolit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Bug.pm | 6 ++---- Bugzilla/BugMail.pm | 7 ++++--- Bugzilla/DB/Schema.pm | 1 + Bugzilla/Group.pm | 8 ++++++++ Bugzilla/Install/DB.pm | 3 +++ Bugzilla/User.pm | 23 +++++++++++++++++++++++ editgroups.cgi | 16 +++++++++++++--- 7 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 5f37e9ff4..0a2770a65 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -2251,8 +2251,7 @@ sub GetComments { my @comments; my @args = ($id); - my $query = 'SELECT longdescs.comment_id AS id, profiles.realname AS name, - profiles.login_name AS email, ' . + my $query = 'SELECT longdescs.comment_id AS id, profiles.userid, ' . $dbh->sql_date_format('longdescs.bug_when', '%Y.%m.%d %H:%i:%s') . ' AS time, longdescs.thetext AS body, longdescs.work_time, isprivate, already_wrapped, type, extra_data @@ -2271,8 +2270,7 @@ sub GetComments { while (my $comment_ref = $sth->fetchrow_hashref()) { my %comment = %$comment_ref; - - $comment{'email'} .= Bugzilla->params->{'emailsuffix'}; + $comment{'author'} = new Bugzilla::User($comment{'userid'}); # If raw data is requested, do not format 'special' comments. $comment{'body'} = format_comment(\%comment) unless $raw; diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm index acc12556d..0d5d3fd78 100644 --- a/Bugzilla/BugMail.pm +++ b/Bugzilla/BugMail.pm @@ -703,11 +703,12 @@ sub prepare_comments { my $result = ""; foreach my $comment (@$raw_comments) { if ($count) { + my $author = $comment->{'author'}; $result .= "\n\n--- Comment #$count from "; - if ($comment->{'name'}) { - $result .= $comment->{'name'} . " <" . $comment->{'email'} . ">"; + if ($author->name) { + $result .= $author->name . " <" . $author->email . ">"; } else { - $result .= $comment->{'email'}; + $result .= $author->email; } $result .= " " . format_time($comment->{'time'}) . " ---\n"; } diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 35e786c51..f8c1588e4 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -873,6 +873,7 @@ use constant ABSTRACT_SCHEMA => { DEFAULT => "''"}, isactive => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'}, + icon_url => {TYPE => 'TINYTEXT'}, ], INDEXES => [ groups_name_idx => {FIELDS => ['name'], TYPE => 'UNIQUE'}, diff --git a/Bugzilla/Group.pm b/Bugzilla/Group.pm index 9e5a601c7..6bdacbe6d 100644 --- a/Bugzilla/Group.pm +++ b/Bugzilla/Group.pm @@ -43,6 +43,7 @@ use constant DB_COLUMNS => qw( groups.isbuggroup groups.userregexp groups.isactive + groups.icon_url ); use constant DB_TABLE => 'groups'; @@ -55,6 +56,7 @@ use constant VALIDATORS => { userregexp => \&_check_user_regexp, isactive => \&_check_is_active, isbuggroup => \&_check_is_bug_group, + icon_url => \&_check_icon_url, }; use constant REQUIRED_CREATE_FIELDS => qw(name description isbuggroup); @@ -64,6 +66,7 @@ use constant UPDATE_COLUMNS => qw( description userregexp isactive + icon_url ); # Parameters that are lists of groups. @@ -78,6 +81,7 @@ sub description { return $_[0]->{'description'}; } sub is_bug_group { return $_[0]->{'isbuggroup'}; } sub user_regexp { return $_[0]->{'userregexp'}; } sub is_active { return $_[0]->{'isactive'}; } +sub icon_url { return $_[0]->{'icon_url'}; } sub members_direct { my ($self) = @_; @@ -134,6 +138,7 @@ sub set_description { $_[0]->set('description', $_[1]); } sub set_is_active { $_[0]->set('isactive', $_[1]); } sub set_name { $_[0]->set('name', $_[1]); } sub set_user_regexp { $_[0]->set('userregexp', $_[1]); } +sub set_icon_url { $_[0]->set('icon_url', $_[1]); } sub update { my $self = shift; @@ -324,6 +329,8 @@ sub _check_is_bug_group { return $_[1] ? 1 : 0; } +sub _check_icon_url { return $_[1] ? clean_text($_[1]) : undef; } + 1; __END__ @@ -344,6 +351,7 @@ Bugzilla::Group - Bugzilla group class. my $description = $group->description; my $user_reg_exp = $group->user_reg_exp; my $is_active = $group->is_active; + my $icon_url = $group->icon_url; my $is_active_bug_group = $group->is_active_bug_group; my $group_id = Bugzilla::Group::ValidateGroupName('admin', @users); diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 99b405736..5106fd525 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -510,6 +510,9 @@ sub update_table_definitions { # 2007-05-17 LpSolit@gmail.com - Bug 344965 _initialize_workflow($old_params); + # 2007-07-11 LpSolit@gmail.com - Bug 332149 + $dbh->bz_add_column('groups', 'icon_url', {TYPE => 'TINYTEXT'}); + ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index f73dd06df..cf8de0274 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -800,6 +800,24 @@ sub can_set_flag { || $self->in_group_id($flag_type->grant_group->id)) ? 1 : 0; } +sub direct_group_membership { + my $self = shift; + my $dbh = Bugzilla->dbh; + + if (!$self->{'direct_group_membership'}) { + my $gid = $dbh->selectcol_arrayref('SELECT id + FROM groups + INNER JOIN user_group_map + ON groups.id = user_group_map.group_id + WHERE user_id = ? + AND isbless = 0', + undef, $self->id); + $self->{'direct_group_membership'} = Bugzilla::Group->new_from_list($gid); + } + return $self->{'direct_group_membership'}; +} + + # visible_groups_inherited returns a reference to a list of all the groups # whose members are visible to this user. sub visible_groups_inherited { @@ -2026,6 +2044,11 @@ is in any of the groups input to flatten_group_membership by querying the user_group_map for any user with DIRECT or REGEXP membership IN() the list of groups returned. +=item C + +Returns a reference to an array of group objects. Groups the user belong to +by group inheritance are excluded from the list. + =item C Returns a list of all groups whose members should be visible to this user. diff --git a/editgroups.cgi b/editgroups.cgi index 5e2a3baf6..b9503426b 100755 --- a/editgroups.cgi +++ b/editgroups.cgi @@ -244,12 +244,18 @@ if ($action eq 'new') { my $desc = CheckGroupDesc($cgi->param('desc')); my $regexp = CheckGroupRegexp($cgi->param('regexp')); my $isactive = $cgi->param('isactive') ? 1 : 0; + # This is an admin page. The URL is considered safe. + my $icon_url; + if ($cgi->param('icon_url')) { + $icon_url = clean_text($cgi->param('icon_url')); + trick_taint($icon_url); + } # Add the new group $dbh->do('INSERT INTO groups - (name, description, isbuggroup, userregexp, isactive) - VALUES (?, ?, 1, ?, ?)', - undef, ($name, $desc, $regexp, $isactive)); + (name, description, isbuggroup, userregexp, isactive, icon_url) + VALUES (?, ?, 1, ?, ?, ?)', + undef, ($name, $desc, $regexp, $isactive, $icon_url)); my $gid = $dbh->bz_last_key('groups', 'id'); my $admin = Bugzilla::Group->new({name => 'admin'})->id(); @@ -565,6 +571,10 @@ sub doGroupChanges { } } + if (defined $cgi->param('icon_url')) { + $group->set_icon_url($cgi->param('icon_url')); + } + my $changes = $group->update(); my $sth_insert = $dbh->prepare('INSERT INTO group_group_map -- cgit v1.2.3-24-g4f1b