diff options
Diffstat (limited to 'userprefs.cgi')
-rwxr-xr-x | userprefs.cgi | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/userprefs.cgi b/userprefs.cgi index f0d5a8e53..d33de74ad 100755 --- a/userprefs.cgi +++ b/userprefs.cgi @@ -33,6 +33,7 @@ use Bugzilla::Search; use Bugzilla::Util; use Bugzilla::Error; use Bugzilla::User; +use Bugzilla::User::Setting qw(clear_settings_cache); use Bugzilla::Token; my $template = Bugzilla->template; @@ -79,6 +80,9 @@ sub DoAccount { sub SaveAccount { my $cgi = Bugzilla->cgi; my $dbh = Bugzilla->dbh; + + $dbh->bz_start_transaction; + my $user = Bugzilla->user; my $oldpassword = $cgi->param('old_password'); @@ -101,12 +105,7 @@ sub SaveAccount { validate_password($pwd1, $pwd2); if ($oldpassword ne $pwd1) { - my $cryptedpassword = bz_crypt($pwd1); - $dbh->do(q{UPDATE profiles - SET cryptpassword = ? - WHERE userid = ?}, - undef, ($cryptedpassword, $user->id)); - + $user->set_password($pwd1); # Invalidate all logins except for the current one Bugzilla->logout(LOGOUT_KEEP_CURRENT); } @@ -137,10 +136,9 @@ sub SaveAccount { } } - my $realname = trim($cgi->param('realname')); - trick_taint($realname); # Only used in a placeholder - $dbh->do("UPDATE profiles SET realname = ? WHERE userid = ?", - undef, ($realname, $user->id)); + $user->set_name($cgi->param('realname')); + $user->update({ keep_session => 1, keep_tokens => 1 }); + $dbh->bz_commit_transaction; } @@ -150,7 +148,7 @@ sub DoSettings { my $settings = $user->settings; $vars->{'settings'} = $settings; - my @setting_list = keys %$settings; + my @setting_list = sort keys %$settings; $vars->{'setting_names'} = \@setting_list; $vars->{'has_settings_enabled'} = 0; @@ -188,6 +186,7 @@ sub SaveSettings { } } $vars->{'settings'} = $user->settings(1); + clear_settings_cache($user->id); } sub DoEmail { @@ -338,6 +337,47 @@ sub SaveEmail { $dbh->bz_commit_transaction(); } + + ########################################################################### + # Ignore Bugs + ########################################################################### + my %ignored_bugs = map { $_->{'id'} => 1 } @{$user->bugs_ignored}; + + # Validate the new bugs to ignore by checking that they exist and also + # if the user gave an alias + my @add_ignored = split(/[\s,]+/, $cgi->param('add_ignored_bugs')); + @add_ignored = map { Bugzilla::Bug->check($_)->id } @add_ignored; + map { $ignored_bugs{$_} = 1 } @add_ignored; + + # Remove any bug ids the user no longer wants to ignore + foreach my $key (grep(/^remove_ignored_bug_/, $cgi->param)) { + my ($bug_id) = $key =~ /(\d+)$/; + delete $ignored_bugs{$bug_id}; + } + + # Update the database with any changes made + my ($removed, $added) = diff_arrays([ map { $_->{'id'} } @{$user->bugs_ignored} ], + [ keys %ignored_bugs ]); + + if (scalar @$removed || scalar @$added) { + $dbh->bz_start_transaction(); + + if (scalar @$removed) { + $dbh->do('DELETE FROM email_bug_ignore WHERE user_id = ? AND ' . + $dbh->sql_in('bug_id', $removed), + undef, $user->id); + } + if (scalar @$added) { + my $sth = $dbh->prepare('INSERT INTO email_bug_ignore + (user_id, bug_id) VALUES (?, ?)'); + $sth->execute($user->id, $_) foreach @$added; + } + + # Reset the cache of ignored bugs if the list changed. + delete $user->{bugs_ignored}; + + $dbh->bz_commit_transaction(); + } } @@ -345,9 +385,9 @@ sub DoPermissions { my $dbh = Bugzilla->dbh; my $user = Bugzilla->user; my (@has_bits, @set_bits); - + my $groups = $dbh->selectall_arrayref( - "SELECT DISTINCT name, description FROM groups WHERE id IN (" . + "SELECT DISTINCT name, description FROM groups WHERE id IN (" . $user->groups_as_string . ") ORDER BY name"); foreach my $group (@$groups) { my ($nam, $desc) = @$group; @@ -470,12 +510,13 @@ sub SaveSavedSearches { } $user->flush_queries_cache; - + # Update profiles.mybugslink. my $showmybugslink = defined($cgi->param("showmybugslink")) ? 1 : 0; $dbh->do("UPDATE profiles SET mybugslink = ? WHERE userid = ?", - undef, ($showmybugslink, $user->id)); + undef, ($showmybugslink, $user->id)); $user->{'showmybugslink'} = $showmybugslink; + Bugzilla->memcached->clear({ table => 'profiles', id => $user->id }); } |