[Rt-commit] r8964 - in rt/branches/3.7-EXPERIMENTAL: . html/User
t/web
sartak at bestpractical.com
sartak at bestpractical.com
Fri Sep 7 14:37:51 EDT 2007
Author: sartak
Date: Fri Sep 7 14:37:50 2007
New Revision: 8964
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/html/User/Prefs.html
rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm
rt/branches/3.7-EXPERIMENTAL/t/web/crypt-gnupg.t
Log:
r42429 at onn: sartak | 2007-09-07 14:37:38 -0400
Add a PreferredKey method to User_Overlay which handles the business of querying GPG and so.
Makes all t/web/crypt-gnupg.t tests pass :)
Modified: rt/branches/3.7-EXPERIMENTAL/html/User/Prefs.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/User/Prefs.html (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/User/Prefs.html Fri Sep 7 14:37:50 2007
@@ -169,9 +169,7 @@
<table cellspacing="0" cellpadding="0">
<tr>
<td class="label"><&|/l&>Preferred Key</&>:</td>
-% my $prefkey = $UserObj->FirstAttribute('PreferredKey');
-% $prefkey = $prefkey ? $prefkey->Content : '';
- <td class="value"><& /Elements/SelectKey, EmailAddress => $UserObj->EmailAddress, Default => $prefkey &></td>
+ <td class="value"><& /Elements/SelectKey, EmailAddress => $UserObj->EmailAddress, Default => $UserObj->PreferredKey &></td>
</tr>
</table>
</&>
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm Fri Sep 7 14:37:50 2007
@@ -1288,6 +1288,8 @@
return ( $self->CurrentUser->HasRight(Right => $right, Object => $RT::System) );
}
+# }}}
+
sub _PrefName {
my $name = shift;
if (ref $name) {
@@ -1611,6 +1613,40 @@
# }}}
+=head2 PreferredKey
+
+Returns the preferred key of the user. If none is set, then this will query
+GPG and set the preferred key to the maximally trusted key found (and then
+return it). Returns C<undef> if no preferred key can be found.
+
+=cut
+
+sub PreferredKey
+{
+ my $self = shift;
+ return undef unless RT->Config->Get('GnuPG')->{'Enable'};
+ my $prefkey = $self->FirstAttribute('PreferredKey');
+ return $prefkey->Content if $prefkey;
+
+ # we don't have a preferred key for this user, so now we must query GPG
+ my %res = RT::Crypt::GnuPG::GetKeysInfo($self->EmailAddress);
+ return undef unless defined $res{'info'};
+ my @keys = @{ $res{'info'} };
+ return undef if @keys == 0;
+
+ if (@keys == 1) {
+ $prefkey = $keys[0]->{'Key'};
+ }
+ else {
+ # prefer the maximally trusted key
+ @keys = sort { $b->{'TrustLevel'} <=> $a->{'TrustLevel'} } @keys;
+ $prefkey = $keys[0]->{'Key'};
+ }
+
+ $self->SetAttribute(Name => 'PreferredKey', Content => $prefkey);
+ return $prefkey;
+}
+
sub BasicColumns {
(
[ Name => 'User Id' ],
Modified: rt/branches/3.7-EXPERIMENTAL/t/web/crypt-gnupg.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/t/web/crypt-gnupg.t (original)
+++ rt/branches/3.7-EXPERIMENTAL/t/web/crypt-gnupg.t Fri Sep 7 14:37:50 2007
@@ -390,9 +390,7 @@
# test key selection
ok($user = RT::User->new($RT::SystemUser));
ok($user->Load('root'), "Loaded user 'root'");
-my $prefkey = $user->FirstAttribute('PreferredKey');
-$prefkey = $prefkey ? $prefkey->Content : '';
-is($prefkey, "9FA662C06DE22FC2", "preferred key is set correctly");
+is($user->PreferredKey, "9FA662C06DE22FC2", "preferred key is set correctly");
$m->get("$baseurl/User/Prefs.html");
like($m->content, qr/Preferred Key/, "preferred key option shows up in preference");
@@ -407,9 +405,7 @@
ok($user = RT::User->new($RT::SystemUser));
ok($user->Load('root'), "Loaded user 'root'");
-$prefkey = $user->FirstAttribute('PreferredKey');
-$prefkey = $prefkey ? $prefkey->Content : '';
-is($prefkey, "DF651FA0632C4F50", "preferred key is set correctly to the new value");
+is($user->PreferredKey, "DF651FA0632C4F50", "preferred key is set correctly to the new value");
$m->get("$baseurl/User/Prefs.html");
like($m->content, qr/Preferred Key/, "preferred key option shows up in preference");
More information about the Rt-commit
mailing list