summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Group.pm
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@mozilla.com>2015-09-02 08:40:56 +0200
committerByron Jones <glob@mozilla.com>2015-09-02 08:40:56 +0200
commit3d463f780fd2051751f276f71e27bb47e96dc2aa (patch)
tree26c7c6f2e745dc2ace396396ed03c7ef8c8f3b7e /Bugzilla/Group.pm
parente1c42c8fcdf74f5a810aae1384808b635cdc51a4 (diff)
downloadbugzilla-3d463f780fd2051751f276f71e27bb47e96dc2aa.tar.gz
bugzilla-3d463f780fd2051751f276f71e27bb47e96dc2aa.tar.xz
Bug 1196618 - add support for group owners
Diffstat (limited to 'Bugzilla/Group.pm')
-rw-r--r--Bugzilla/Group.pm32
1 files changed, 32 insertions, 0 deletions
diff --git a/Bugzilla/Group.pm b/Bugzilla/Group.pm
index bb84ca229..37d4acf90 100644
--- a/Bugzilla/Group.pm
+++ b/Bugzilla/Group.pm
@@ -33,6 +33,8 @@ use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::Config qw(:admin);
+use Scalar::Util qw(blessed);
+
###############################
##### Module Initialization ###
###############################
@@ -47,6 +49,7 @@ use constant DB_COLUMNS => qw(
groups.userregexp
groups.isactive
groups.icon_url
+ groups.owner_user_id
);
use constant DB_TABLE => 'groups';
@@ -60,6 +63,7 @@ use constant VALIDATORS => {
isactive => \&_check_is_active,
isbuggroup => \&_check_is_bug_group,
icon_url => \&_check_icon_url,
+ owner_user_id => \&_check_owner,
};
use constant UPDATE_COLUMNS => qw(
@@ -68,6 +72,7 @@ use constant UPDATE_COLUMNS => qw(
userregexp
isactive
icon_url
+ owner_user_id
);
# Parameters that are lists of groups.
@@ -205,6 +210,15 @@ sub products {
return $self->{products};
}
+sub owner {
+ my $self = shift;
+ return $self->{owner} if exists $self->{owner};
+ if ($self->{owner_user_id}) {
+ $self->{owner} = Bugzilla::User->check({ id => $self->{owner_user_id}, cache => 1 });
+ }
+ return $self->{owner} || undef;
+}
+
###############################
#### Methods ####
###############################
@@ -227,6 +241,13 @@ 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 set_owner {
+ my ($self, $owner_id) = @_;
+ $self->set('owner_user_id', $owner_id);
+ # Reset the default owner object.
+ delete $self->{owner};
+}
+
sub update {
my $self = shift;
my $dbh = Bugzilla->dbh;
@@ -519,6 +540,16 @@ sub _check_is_bug_group {
sub _check_icon_url { return $_[1] ? clean_text($_[1]) : undef; }
+sub _check_owner {
+ my ($invocant, $owner, undef, $params) = @_;
+ return Bugzilla::User->check({ name => $owner, cache => 1 })->id if $owner;
+ # We require an owner if the group is a not a system group
+ if (blessed($invocant) && !$invocant->is_bug_group) {
+ return undef;
+ }
+ ThrowUserError('group_needs_owner');
+}
+
1;
__END__
@@ -541,6 +572,7 @@ Bugzilla::Group - Bugzilla group class.
my $is_active = $group->is_active;
my $icon_url = $group->icon_url;
my $is_active_bug_group = $group->is_active_bug_group;
+ my $owner = $group->owner;
my $group_id = Bugzilla::Group::ValidateGroupName('admin', @users);
my @groups = Bugzilla::Group->get_all;