diff options
Diffstat (limited to 'Bugzilla/User')
-rw-r--r-- | Bugzilla/User/APIKey.pm | 143 | ||||
-rw-r--r-- | Bugzilla/User/Session.pm | 70 | ||||
-rw-r--r-- | Bugzilla/User/Setting.pm | 454 | ||||
-rw-r--r-- | Bugzilla/User/Setting/Lang.pm | 6 | ||||
-rw-r--r-- | Bugzilla/User/Setting/Skin.pm | 28 | ||||
-rw-r--r-- | Bugzilla/User/Setting/Timezone.pm | 22 |
6 files changed, 465 insertions, 258 deletions
diff --git a/Bugzilla/User/APIKey.pm b/Bugzilla/User/APIKey.pm index d268a0a93..f267b31f1 100644 --- a/Bugzilla/User/APIKey.pm +++ b/Bugzilla/User/APIKey.pm @@ -13,68 +13,116 @@ use warnings; use parent qw(Bugzilla::Object); +use Bugzilla::Constants; use Bugzilla::User; -use Bugzilla::Util qw(generate_random_password trim); +use Bugzilla::Util qw(generate_random_password trim bz_crypt); ##################################################################### # Overriden Constants that are used as methods ##################################################################### -use constant DB_TABLE => 'user_api_keys'; -use constant DB_COLUMNS => qw( - id - user_id - api_key - description - revoked - last_used +use constant DB_TABLE => 'user_api_keys'; +use constant DB_COLUMNS => qw( + id + user_id + api_key + description + revoked + last_used + banned ); -use constant UPDATE_COLUMNS => qw(description revoked last_used); +use constant UPDATE_COLUMNS => qw(description revoked last_used banned); use constant VALIDATORS => { - api_key => \&_check_api_key, - description => \&_check_description, - revoked => \&Bugzilla::Object::check_boolean, + api_key => \&_check_api_key, + description => \&_check_description, + revoked => \&Bugzilla::Object::check_boolean, + banned => \&Bugzilla::Object::check_boolean, }; -use constant LIST_ORDER => 'id'; -use constant NAME_FIELD => 'api_key'; +use constant LIST_ORDER => 'id'; +use constant NAME_FIELD => 'api_key'; # turn off auditing and exclude these objects from memcached -use constant { AUDIT_CREATES => 0, - AUDIT_UPDATES => 0, - AUDIT_REMOVES => 0, - USE_MEMCACHED => 0 }; +use constant { + AUDIT_CREATES => 0, + AUDIT_UPDATES => 0, + AUDIT_REMOVES => 0, + USE_MEMCACHED => 0 +}; # Accessors -sub id { return $_[0]->{id} } -sub user_id { return $_[0]->{user_id} } -sub api_key { return $_[0]->{api_key} } -sub description { return $_[0]->{description} } -sub revoked { return $_[0]->{revoked} } -sub last_used { return $_[0]->{last_used} } +sub id { return $_[0]->{id} } +sub user_id { return $_[0]->{user_id} } +sub api_key { return $_[0]->{api_key} } +sub description { return $_[0]->{description} } +sub revoked { return $_[0]->{revoked} } +sub last_used { return $_[0]->{last_used} } +sub banned { return $_[0]->{banned} } # Helpers sub user { - my $self = shift; - $self->{user} //= Bugzilla::User->new({name => $self->user_id, cache => 1}); - return $self->{user}; + my $self = shift; + $self->{user} //= Bugzilla::User->new({id => $self->user_id, cache => 1}); + return $self->{user}; } sub update_last_used { - my $self = shift; - my $timestamp = shift - || Bugzilla->dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); - $self->set('last_used', $timestamp); - $self->update; + my $self = shift; + my $timestamp + = shift || Bugzilla->dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)'); + + ## RED HAT EXTENSION START 1660438 + # This does not need to be protected from serialization conflicts + my $dbh = Bugzilla->dbh; + $dbh->bz_start_transaction(1); + $self->set('last_used', $timestamp); + $self->update; + $dbh->bz_commit_transaction(); + ## RED HAT EXTENSION END 1660438 + return; } # Setters sub set_description { $_[0]->set('description', $_[1]); } sub set_revoked { $_[0]->set('revoked', $_[1]); } +sub set_banned { + my($self, $input) = @_; + + Bugzilla->user->in_group('admin') + || ThrowUserError("auth_failure", + {group => "admin", action => "run", object => "apikey"}); + + ThrowUserError("api_key_cannot_unban") if($self->banned() && !$input); + $self->set('banned', $input); +} + # Validators -sub _check_api_key { return generate_random_password(40); } -sub _check_description { return trim($_[1]) || ''; } +sub _check_api_key { return $_[1]; } +sub _check_description { return trim($_[1]) || ''; } + +sub create { + my $class = shift; + my $dbh = Bugzilla->dbh; + + $dbh->bz_start_transaction(); + + $class->check_required_create_fields(@_); + + my $key = generate_random_password(40); + $_[0]->{api_key} = bz_crypt($key, Bugzilla->localconfig->{'site_wide_secret'}, + PASSWORD_DIGEST_ALGORITHM); + + my $params = $class->run_create_validators(@_); + + my $api_key = $class->insert_create_data($params); + + $api_key->{key} = $key; + $dbh->bz_commit_transaction(); + + return $api_key; +} + 1; __END__ @@ -134,6 +182,10 @@ For example: "Dashboard key", "Application X key". If true, this api key cannot be used. +=item C<banned> + +If true, this api key has been revoked by an admin and cannot be used. + =item C<last_used> The date that this key was last used. undef if never used. @@ -152,4 +204,25 @@ Sets the new description Sets the revoked flag +=item C<set_banned> + +Sets the banned flag, you must be in the admin group to set this field. + +=back + + +=head1 CLASS FUNCTIONS + +These are functions that are not called on a User object, but instead are +called "statically," just like a normal procedural function. + +=over 4 + +=item C<create> + +The same as L<Bugzilla::Object/create>. + +Params: description - What the key is used for + user_id - The uid of the user this key belongs to. + =back diff --git a/Bugzilla/User/Session.pm b/Bugzilla/User/Session.pm new file mode 100644 index 000000000..8e42d6725 --- /dev/null +++ b/Bugzilla/User/Session.pm @@ -0,0 +1,70 @@ +# 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. + +package Bugzilla::User::Session; + +use 5.10.1; +use strict; +use warnings; + +use parent qw(Bugzilla::Object); + +##################################################################### +# Overriden Constants that are used as methods +##################################################################### + +use constant DB_TABLE => 'logincookies'; +use constant DB_COLUMNS => qw( + cookie + userid + lastused + ipaddr + id +); +# restrict_ipaddr +#); + +use constant UPDATE_COLUMNS => qw(); +use constant VALIDATORS => {}; +use constant LIST_ORDER => 'lastused DESC'; +use constant NAME_FIELD => 'cookie'; + +# turn off auditing and exclude these objects from memcached +use constant { AUDIT_CREATES => 0, + AUDIT_UPDATES => 0, + AUDIT_REMOVES => 0, + USE_MEMCACHED => 0 }; + +# Accessors +sub id { return $_[0]->{id} } +sub userid { return $_[0]->{userid} } +sub cookie { return $_[0]->{cookie} } +sub lastused { return $_[0]->{lastused} } +sub ipaddr { return $_[0]->{ipaddr} } +#sub restrict_ipaddr { return $_[0]->{restrict_ipaddr} } + +1; + +__END__ + +BMO just don't like commenting their code :( + +=head1 B<Methods in need of POD> + +=over + +=item id + +=item userid + +=item cookie + +=item lastused + +=item ipaddr + +=back
\ No newline at end of file diff --git a/Bugzilla/User/Setting.pm b/Bugzilla/User/Setting.pm index aece3b7de..dc0cf5ddf 100644 --- a/Bugzilla/User/Setting.pm +++ b/Bugzilla/User/Setting.pm @@ -17,10 +17,10 @@ use parent qw(Exporter); # Module stuff @Bugzilla::User::Setting::EXPORT = qw( - get_all_settings - get_defaults - add_setting - clear_settings_cache + get_all_settings + get_defaults + add_setting + clear_settings_cache ); use Bugzilla::Error; @@ -31,88 +31,96 @@ use Bugzilla::Util qw(trick_taint get_text); ############################### sub new { - my $invocant = shift; - my $setting_name = shift; - my $user_id = shift; - - my $class = ref($invocant) || $invocant; - my $subclass = ''; - - # Create a ref to an empty hash and bless it - my $self = {}; - - my $dbh = Bugzilla->dbh; - - # Confirm that the $setting_name is properly formed; - # if not, throw a code error. - # - # NOTE: due to the way that setting names are used in templates, - # they must conform to to the limitations set for HTML NAMEs and IDs. - # - if ( !($setting_name =~ /^[a-zA-Z][-.:\w]*$/) ) { - ThrowCodeError("setting_name_invalid", { name => $setting_name }); - } - - # If there were only two parameters passed in, then we need - # to retrieve the information for this setting ourselves. - if (scalar @_ == 0) { - - my ($default, $is_enabled, $value); - ($default, $is_enabled, $value, $subclass) = - $dbh->selectrow_array( - q{SELECT default_value, is_enabled, setting_value, subclass + my $invocant = shift; + my $setting_name = shift; + my $user_id = shift; + + my $class = ref($invocant) || $invocant; + my $subclass = ''; + + # Create a ref to an empty hash and bless it + my $self = {}; + + my $dbh = Bugzilla->dbh; + + # Confirm that the $setting_name is properly formed; + # if not, throw a code error. + # + # NOTE: due to the way that setting names are used in templates, + # they must conform to to the limitations set for HTML NAMEs and IDs. + # + if (!($setting_name =~ /^[a-zA-Z][-.:\w]*$/)) { + ThrowCodeError("setting_name_invalid", {name => $setting_name}); + } + + # If there were only two parameters passed in, then we need + # to retrieve the information for this setting ourselves. + if (scalar @_ == 0) { + +## REDHAT EXTENSION BEGIN 653915 + my ($default, $is_enabled, $value, $required_groups); + ($default, $is_enabled, $value, $subclass, $required_groups) + = $dbh->selectrow_array( + q{SELECT default_value, is_enabled, setting_value, subclass, required_groups FROM setting LEFT JOIN profile_setting ON setting.name = profile_setting.setting_name WHERE name = ? - AND profile_setting.user_id = ?}, - undef, - $setting_name, $user_id); - - # if not defined, then grab the default value - if (! defined $value) { - ($default, $is_enabled, $subclass) = - $dbh->selectrow_array( - q{SELECT default_value, is_enabled, subclass + AND profile_setting.user_id = ?}, undef, $setting_name, $user_id + ); +## REDHAT EXTENSION END 653915 + + # if not defined, then grab the default value + if (!defined $value) { + ($default, $is_enabled, $subclass) = $dbh->selectrow_array( + q{SELECT default_value, is_enabled, subclass FROM setting - WHERE name = ?}, - undef, - $setting_name); - } - - $self->{'is_enabled'} = $is_enabled; - $self->{'default_value'} = $default; - - # IF the setting is enabled, AND the user has chosen a setting - # THEN return that value - # ELSE return the site default, and note that it is the default. - if ( ($is_enabled) && (defined $value) ) { - $self->{'value'} = $value; - } else { - $self->{'value'} = $default; - $self->{'isdefault'} = 1; - } - } - else { - # If the values were passed in, simply assign them and return. - $self->{'is_enabled'} = shift; - $self->{'default_value'} = shift; - $self->{'value'} = shift; - $self->{'is_default'} = shift; - $subclass = shift; + WHERE name = ?}, undef, $setting_name + ); } - if ($subclass) { - eval('require ' . $class . '::' . $subclass); - $@ && ThrowCodeError('setting_subclass_invalid', - {'subclass' => $subclass}); - $class = $class . '::' . $subclass; - } - bless($self, $class); - $self->{'_setting_name'} = $setting_name; - $self->{'_user_id'} = $user_id; + $self->{'is_enabled'} = $is_enabled; + $self->{'default_value'} = $default; + +## REDHAT EXTENSION BEGIN 653915 + my $visible = _is_setting_visible($setting_name, $required_groups, $user_id); +## REDHAT EXTENSION END 653915 - return $self; + # IF the setting is enabled, AND the user has chosen a setting + # THEN return that value + # ELSE return the site default, and note that it is the default. +## REDHAT EXTENSION BEGIN 653915 + if (($is_enabled) && (defined $value) && ($visible)) { +## REDHAT EXTENSION END 653915 + $self->{'value'} = $value; + } + else { + $self->{'value'} = $default; + $self->{'isdefault'} = 1; + } + } + else { + # If the values were passed in, simply assign them and return. + $self->{'is_enabled'} = shift; + $self->{'default_value'} = shift; + $self->{'value'} = shift; + $self->{'is_default'} = shift; + $subclass = shift; +## REDHAT EXTENSION BEGIN 653915 + $self->{'visible'} = shift; +## REDHAT EXTENSION END 653915 + } + if ($subclass) { + eval('require ' . $class . '::' . $subclass); + $@ && ThrowCodeError('setting_subclass_invalid', {'subclass' => $subclass}); + $class = $class . '::' . $subclass; + } + bless($self, $class); + + $self->{'_setting_name'} = $setting_name; + $self->{'_user_id'} = $user_id; + + return $self; } ############################### @@ -120,191 +128,243 @@ sub new { ############################### sub add_setting { - my ($name, $values, $default_value, $subclass, $force_check, - $silently) = @_; - my $dbh = Bugzilla->dbh; - - my $exists = _setting_exists($name); - return if ($exists && !$force_check); - - ($name && length( $default_value // '' )) - || ThrowCodeError("setting_info_invalid"); - - if ($exists) { - # If this setting exists, we delete it and regenerate it. - $dbh->do('DELETE FROM setting_value WHERE name = ?', undef, $name); - $dbh->do('DELETE FROM setting WHERE name = ?', undef, $name); - # Remove obsolete user preferences for this setting. - if (defined $values && scalar(@$values)) { - my $list = join(', ', map {$dbh->quote($_)} @$values); - $dbh->do("DELETE FROM profile_setting - WHERE setting_name = ? AND setting_value NOT IN ($list)", - undef, $name); - } - } - elsif (!$silently) { - print get_text('install_setting_new', { name => $name }) . "\n"; - } - $dbh->do(q{INSERT INTO setting (name, default_value, is_enabled, subclass) - VALUES (?, ?, 1, ?)}, - undef, ($name, $default_value, $subclass)); + my ($name, $values, $default_value, $subclass, $force_check, $silently) = @_; + my $dbh = Bugzilla->dbh; - my $sth = $dbh->prepare(q{INSERT INTO setting_value (name, value, sortindex) - VALUES (?, ?, ?)}); + my $exists = _setting_exists($name); + return if ($exists && !$force_check); + + ($name && length($default_value // '')) + || ThrowCodeError("setting_info_invalid"); + + if ($exists) { - my $sortindex = 5; - foreach my $key (@$values){ - $sth->execute($name, $key, $sortindex); - $sortindex += 5; + # If this setting exists, we delete it and regenerate it. + $dbh->do('DELETE FROM setting_value WHERE name = ?', undef, $name); + $dbh->do('DELETE FROM setting WHERE name = ?', undef, $name); + + # Remove obsolete user preferences for this setting. + if (defined $values && scalar(@$values)) { + my $list = join(', ', map { $dbh->quote($_) } @$values); + $dbh->do( + "DELETE FROM profile_setting + WHERE setting_name = ? AND setting_value NOT IN ($list)", undef, + $name + ); } + } + elsif (!$silently) { + print get_text('install_setting_new', {name => $name}) . "\n"; + } + $dbh->do( + q{INSERT INTO setting (name, default_value, is_enabled, subclass) + VALUES (?, ?, 1, ?)}, undef, ($name, $default_value, $subclass) + ); + + my $sth = $dbh->prepare(q{INSERT INTO setting_value (name, value, sortindex) + VALUES (?, ?, ?)}); + + my $sortindex = 5; + foreach my $key (@$values) { + $sth->execute($name, $key, $sortindex); + $sortindex += 5; + } } sub get_all_settings { - my ($user_id) = @_; - my $settings = {}; - my $dbh = Bugzilla->dbh; - - my $cache_key = "user_settings.$user_id"; - my $rows = Bugzilla->memcached->get_config({ key => $cache_key }); - if (!$rows) { - $rows = $dbh->selectall_arrayref( - q{SELECT name, default_value, is_enabled, setting_value, subclass + my ($user_id) = @_; + my $settings = {}; + my $dbh = Bugzilla->dbh; + + my $cache_key = "user_settings.$user_id"; + my $rows = Bugzilla->memcached->get_config({key => $cache_key}); + if (!$rows) { + $rows = $dbh->selectall_arrayref( + q{SELECT name, default_value, is_enabled, setting_value, subclass, required_groups FROM setting LEFT JOIN profile_setting ON setting.name = profile_setting.setting_name - AND profile_setting.user_id = ?}, undef, ($user_id)); - Bugzilla->memcached->set_config({ key => $cache_key, data => $rows }); - } + AND profile_setting.user_id = ?}, undef, ($user_id) + ); + Bugzilla->memcached->set_config({key => $cache_key, data => $rows}); + } - foreach my $row (@$rows) { - my ($name, $default_value, $is_enabled, $value, $subclass) = @$row; + foreach my $row (@$rows) { + my ($name, $default_value, $is_enabled, $value, $subclass, $required_groups) + = @$row; - my $is_default; + my $visible = _is_setting_visible($name, $required_groups, $user_id); - if ( ($is_enabled) && (defined $value) ) { - $is_default = 0; - } else { - $value = $default_value; - $is_default = 1; - } + my $is_default; - $settings->{$name} = new Bugzilla::User::Setting( - $name, $user_id, $is_enabled, - $default_value, $value, $is_default, $subclass); + if (($is_enabled) && (defined $value) && $visible) { + $is_default = 0; } + else { + $value = $default_value; + $is_default = 1; + } + + $settings->{$name} + = new Bugzilla::User::Setting($name, $user_id, $is_enabled, $default_value, + $value, $is_default, $subclass, $visible); +## REDHAT EXTENSION END 653915 + } - return $settings; + return $settings; } sub clear_settings_cache { - my ($user_id) = @_; - Bugzilla->memcached->clear_config({ key => "user_settings.$user_id" }); + my ($user_id) = @_; + Bugzilla->memcached->clear_config({key => "user_settings.$user_id"}); } sub get_defaults { - my ($user_id) = @_; - my $dbh = Bugzilla->dbh; - my $default_settings = {}; + my ($user_id) = @_; + my $dbh = Bugzilla->dbh; + my $default_settings = {}; - $user_id ||= 0; + $user_id ||= 0; - my $rows = $dbh->selectall_arrayref(q{SELECT name, default_value, is_enabled, subclass - FROM setting}); +## REDHAT EXTENSION BEGIN 653915 + my $rows = $dbh->selectall_arrayref( + q{SELECT name, default_value, is_enabled, subclass, required_groups + FROM setting} + ); - foreach my $row (@$rows) { - my ($name, $default_value, $is_enabled, $subclass) = @$row; + foreach my $row (@$rows) { + my ($name, $default_value, $is_enabled, $subclass, $required_groups) = @$row; - $default_settings->{$name} = new Bugzilla::User::Setting( - $name, $user_id, $is_enabled, $default_value, $default_value, 1, - $subclass); - } + my $visible = _is_setting_visible($name, $required_groups, $user_id); + + $default_settings->{$name} + = new Bugzilla::User::Setting($name, $user_id, $is_enabled, $default_value, + $default_value, 1, $subclass, $visible); +## REDHAT EXTENSION END 653915 + + } - return $default_settings; + return $default_settings; } sub set_default { - my ($setting_name, $default_value, $is_enabled) = @_; - my $dbh = Bugzilla->dbh; + my ($setting_name, $default_value, $is_enabled) = @_; + my $dbh = Bugzilla->dbh; - my $sth = $dbh->prepare(q{UPDATE setting + my $sth = $dbh->prepare(q{UPDATE setting SET default_value = ?, is_enabled = ? WHERE name = ?}); - $sth->execute($default_value, $is_enabled, $setting_name); + $sth->execute($default_value, $is_enabled, $setting_name); } sub _setting_exists { - my ($setting_name) = @_; - my $dbh = Bugzilla->dbh; - return $dbh->selectrow_arrayref( - "SELECT 1 FROM setting WHERE name = ?", undef, $setting_name) || 0; + my ($setting_name) = @_; + my $dbh = Bugzilla->dbh; + return $dbh->selectrow_arrayref("SELECT 1 FROM setting WHERE name = ?", + undef, $setting_name) + || 0; } +## REDHAT EXTENSION BEGIN 653915 +sub _is_setting_visible { + my $setting_name = shift; + my $required_groups = shift; + my $user_id = shift; + + if (!$required_groups) { + + # Setting is visible for everyone + return 1; + } + elsif (!$user_id) { + + # Not visible if they are not logged in + return 0; + } + + # Lets check if the user is in one of the required groups + my @groups = split /,\s*/, $required_groups; + my $user = new Bugzilla::User($user_id); + use Data::Dumper; + foreach my $group (@groups) { + if ($user->in_group($group)) { + + # They are in the group. The setting is visible + return 1; + } + } + + # The user cannot see this setting, they are not in an appropriate group + return 0; +} +## REDHAT EXTENSION END 653915 sub legal_values { - my ($self) = @_; + my ($self) = @_; - return $self->{'legal_values'} if defined $self->{'legal_values'}; + return $self->{'legal_values'} if defined $self->{'legal_values'}; - my $dbh = Bugzilla->dbh; - $self->{'legal_values'} = $dbh->selectcol_arrayref( - q{SELECT value + my $dbh = Bugzilla->dbh; + $self->{'legal_values'} = $dbh->selectcol_arrayref( + q{SELECT value FROM setting_value WHERE name = ? - ORDER BY sortindex}, - undef, $self->{'_setting_name'}); + ORDER BY sortindex}, undef, $self->{'_setting_name'} + ); - return $self->{'legal_values'}; + return $self->{'legal_values'}; } sub validate_value { - my $self = shift; - - if (grep(/^$_[0]$/, @{$self->legal_values()})) { - trick_taint($_[0]); - } - else { - ThrowCodeError('setting_value_invalid', - {'name' => $self->{'_setting_name'}, - 'value' => $_[0]}); - } + my $self = shift; + + if (grep(/^$_[0]$/, @{$self->legal_values()})) { + trick_taint($_[0]); + } + else { + ThrowCodeError('setting_value_invalid', + {'name' => $self->{'_setting_name'}, 'value' => $_[0]}); + } } sub reset_to_default { - my ($self) = @_; + my ($self) = @_; - my $dbh = Bugzilla->dbh; - my $sth = $dbh->do(q{ DELETE + my $dbh = Bugzilla->dbh; + my $sth = $dbh->do( + q{ DELETE FROM profile_setting WHERE setting_name = ? - AND user_id = ?}, - undef, $self->{'_setting_name'}, $self->{'_user_id'}); - $self->{'value'} = $self->{'default_value'}; - $self->{'is_default'} = 1; + AND user_id = ?}, undef, $self->{'_setting_name'}, + $self->{'_user_id'} + ); + $self->{'value'} = $self->{'default_value'}; + $self->{'is_default'} = 1; } sub set { - my ($self, $value) = @_; - my $dbh = Bugzilla->dbh; - my $query; + my ($self, $value) = @_; + my $dbh = Bugzilla->dbh; + my $query; - if ($self->{'is_default'}) { - $query = q{INSERT INTO profile_setting + if ($self->{'is_default'}) { + $query = q{INSERT INTO profile_setting (setting_value, setting_name, user_id) VALUES (?,?,?)}; - } else { - $query = q{UPDATE profile_setting + } + else { + $query = q{UPDATE profile_setting SET setting_value = ? WHERE setting_name = ? AND user_id = ?}; - } - $dbh->do($query, undef, $value, $self->{'_setting_name'}, $self->{'_user_id'}); + } + $dbh->do($query, undef, $value, $self->{'_setting_name'}, $self->{'_user_id'}); - $self->{'value'} = $value; - $self->{'is_default'} = 0; + $self->{'value'} = $value; + $self->{'is_default'} = 0; } - 1; __END__ diff --git a/Bugzilla/User/Setting/Lang.pm b/Bugzilla/User/Setting/Lang.pm index d980b7a92..d1aeb3421 100644 --- a/Bugzilla/User/Setting/Lang.pm +++ b/Bugzilla/User/Setting/Lang.pm @@ -16,11 +16,11 @@ use parent qw(Bugzilla::User::Setting); use Bugzilla::Constants; sub legal_values { - my ($self) = @_; + my ($self) = @_; - return $self->{'legal_values'} if defined $self->{'legal_values'}; + return $self->{'legal_values'} if defined $self->{'legal_values'}; - return $self->{'legal_values'} = Bugzilla->languages; + return $self->{'legal_values'} = Bugzilla->languages; } 1; diff --git a/Bugzilla/User/Setting/Skin.pm b/Bugzilla/User/Setting/Skin.pm index 7b0688c0c..0447b02ab 100644 --- a/Bugzilla/User/Setting/Skin.pm +++ b/Bugzilla/User/Setting/Skin.pm @@ -21,24 +21,26 @@ use File::Basename; use constant BUILTIN_SKIN_NAMES => ['standard']; sub legal_values { - my ($self) = @_; + my ($self) = @_; - return $self->{'legal_values'} if defined $self->{'legal_values'}; + return $self->{'legal_values'} if defined $self->{'legal_values'}; - my $dirbase = bz_locations()->{'skinsdir'} . '/contrib'; - # Avoid modification of the list BUILTIN_SKIN_NAMES points to by copying the - # list over instead of simply writing $legal_values = BUILTIN_SKIN_NAMES. - my @legal_values = @{(BUILTIN_SKIN_NAMES)}; + my $dirbase = bz_locations()->{'skinsdir'} . '/contrib'; - foreach my $direntry (glob(catdir($dirbase, '*'))) { - if (-d $direntry) { - next if basename($direntry) =~ /^cvs$/i; - # Stylesheet set found - push(@legal_values, basename($direntry)); - } + # Avoid modification of the list BUILTIN_SKIN_NAMES points to by copying the + # list over instead of simply writing $legal_values = BUILTIN_SKIN_NAMES. + my @legal_values = @{(BUILTIN_SKIN_NAMES)}; + + foreach my $direntry (glob(catdir($dirbase, '*'))) { + if (-d $direntry) { + next if basename($direntry) =~ /^cvs$/i; + + # Stylesheet set found + push(@legal_values, basename($direntry)); } + } - return $self->{'legal_values'} = \@legal_values; + return $self->{'legal_values'} = \@legal_values; } 1; diff --git a/Bugzilla/User/Setting/Timezone.pm b/Bugzilla/User/Setting/Timezone.pm index 8959d1dda..b6b2503b5 100644 --- a/Bugzilla/User/Setting/Timezone.pm +++ b/Bugzilla/User/Setting/Timezone.pm @@ -18,19 +18,21 @@ use parent qw(Bugzilla::User::Setting); use Bugzilla::Constants; sub legal_values { - my ($self) = @_; + my ($self) = @_; - return $self->{'legal_values'} if defined $self->{'legal_values'}; + return $self->{'legal_values'} if defined $self->{'legal_values'}; - my @timezones = DateTime::TimeZone->all_names; - # Remove old formats, such as CST6CDT, EST, EST5EDT. - @timezones = grep { $_ =~ m#.+/.+#} @timezones; - # Append 'local' to the list, which will use the timezone - # given by the server. - push(@timezones, 'local'); - push(@timezones, 'UTC'); + my @timezones = DateTime::TimeZone->all_names; - return $self->{'legal_values'} = \@timezones; + # Remove old formats, such as CST6CDT, EST, EST5EDT. + @timezones = grep { $_ =~ m#.+/.+# } @timezones; + + # Append 'local' to the list, which will use the timezone + # given by the server. + push(@timezones, 'local'); + push(@timezones, 'UTC'); + + return $self->{'legal_values'} = \@timezones; } 1; |