Add ability for users to set their alias in TPAC
authorJeff Godin <jgodin@tadl.org>
Wed, 25 Jul 2012 23:34:36 +0000 (19:34 -0400)
committerJeff Godin <jgodin@tadl.org>
Wed, 25 Jul 2012 23:37:17 +0000 (19:37 -0400)
New option under Personal Information to display and allow editing
of a user's holdshelf alias.

Proof of concept, much potential for further enhancement.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/myopac/prefs.tt2
Open-ILS/src/templates/opac/myopac/update_alias.tt2 [new file with mode: 0644]

index 4ba9ad5..c2a0bc5 100644 (file)
@@ -1357,6 +1357,20 @@ __PACKAGE__->register_method(
 
 __PACKAGE__->register_method(
     method    => "update_passwd",
+    api_name  => "open-ils.actor.user.alias.update",
+    signature => {
+        desc   => "Update the operator's alias",
+        params => [
+            { desc => 'Authentication token', type => 'string' },
+            { desc => 'New alias',            type => 'string' },
+            { desc => 'Current password',     type => 'string' }
+        ],
+        return => {desc => '1 on success, Event on error or incorrect current password'}
+    }
+);
+
+__PACKAGE__->register_method(
+    method    => "update_passwd",
     api_name  => "open-ils.actor.user.email.update",
     signature => {
         desc   => "Update the operator's email address", 
@@ -1404,6 +1418,15 @@ sub update_passwd {
             }
             $db_user->usrname($new_val);
 
+        } elsif( $api =~ /alias/o ) {
+
+            my $exist = $e->search_actor_user({alias=>$new_val},{idlist=>1});
+            if (@$exist) {
+                $e->rollback;
+                return new OpenILS::Event('USERNAME_EXISTS');
+            }
+            $db_user->alias($new_val);
+
         } elsif( $api =~ /email/o ) {
             $db_user->email($new_val);
         }
index 7f8a9a8..4c4cd6c 100644 (file)
@@ -176,6 +176,7 @@ sub load {
     return $self->load_myopac_main if $path =~ m|opac/myopac/main|;
     return $self->load_myopac_receipt_email if $path =~ m|opac/myopac/receipt_email|;
     return $self->load_myopac_receipt_print if $path =~ m|opac/myopac/receipt_print|;
+    return $self->load_myopac_update_alias if $path =~ m|opac/myopac/update_alias|;
     return $self->load_myopac_update_email if $path =~ m|opac/myopac/update_email|;
     return $self->load_myopac_update_password if $path =~ m|opac/myopac/update_password|;
     return $self->load_myopac_update_username if $path =~ m|opac/myopac/update_username|;
index 285c5f6..3a3ddc1 100644 (file)
@@ -1552,6 +1552,47 @@ sub load_myopac_update_username {
     return $self->generic_redirect($url);
 }
 
+sub load_myopac_update_alias {
+    my $self = shift;
+    my $e = $self->editor;
+    my $ctx = $self->ctx;
+    my $alias = $self->cgi->param('alias') || '';
+    my $current_pw = $self->cgi->param('current_pw') || '';
+
+    $self->prepare_extended_user_info;
+
+    return Apache2::Const::OK
+        unless $self->cgi->request_method eq 'POST';
+
+    unless($alias) {
+        $ctx->{invalid_alias} = $alias;
+        return Apache2::Const::OK;
+    }
+
+    if($alias ne $e->requestor->alias) {
+
+        my $evt = $U->simplereq(
+            'open-ils.actor',
+            'open-ils.actor.user.alias.update',
+            $e->authtoken, $alias, $current_pw);
+
+        if($U->event_equals($evt, 'INCORRECT_PASSWORD')) {
+            $ctx->{password_incorrect} = 1;
+            return Apache2::Const::OK;
+        }
+
+        if($U->event_equals($evt, 'USERNAME_EXISTS')) {
+            $ctx->{alias_exists} = $alias;
+            return Apache2::Const::OK;
+        }
+    }
+
+    my $url = $self->apache->unparsed_uri;
+    $url =~ s/update_alias/prefs/;
+
+    return $self->generic_redirect($url);
+}
+
 sub load_myopac_update_password {
     my $self = shift;
     my $e = $self->editor;
index 418c7ac..6b14608 100644 (file)
                 <td class='light_border'>[% ctx.user.email | html %]</td>
                 <td class='light_border'><a href='update_email'>[% l('Change') %]</a></td>
             </tr>
+            <tr>
+                <td class='color_4 light_border'>[% l("Holdshelf Alias") %]</td>
+                <td class='light_border'>[% ctx.user.alias | html %]</td>
+                <td class='light_border'><a href='update_alias'>[% l('Change') %]</a></td>
+            </tr>
 
             [% IF ctx.user.ident_value %]<tr class="hide_me">
                 <td class='color_4 light_border'>
diff --git a/Open-ILS/src/templates/opac/myopac/update_alias.tt2 b/Open-ILS/src/templates/opac/myopac/update_alias.tt2
new file mode 100644 (file)
index 0000000..120e872
--- /dev/null
@@ -0,0 +1,31 @@
+[%  PROCESS "opac/parts/header.tt2";
+    PROCESS "opac/parts/misc_util.tt2";
+    WRAPPER "opac/parts/myopac/base.tt2";
+    myopac_page = "prefs"  %]
+<div id='myopac_summary_div' style="padding:0px;">
+
+[% IF ctx.alias_exists %]
+    <div id='account-update-alias-error'>
+        [% bad_alias = ctx.alias_exists | html %]
+        [% | l(bad_alias) %]
+        The alias "<b>[_1]</b>" is taken.  Please try a different alias.
+        [% END %]
+    </div>
+
+[% ELSIF ctx.password_incorrect %]
+    <div id='account-update-alias-error'>
+        [% |l %] Your current password was not correct. [% END %]
+    </div>
+
+[% END %]
+
+<form method='POST' id='account-update-alias'> 
+    <table> 
+        <tr><td>[% l('Current Alias') %]</td><td>[% ctx.user.alias | html %]</td></tr>
+        <tr><td>[% l('Current Password') %]</td><td><input type='password' name='current_pw'/></td></tr>
+        <tr><td>[% l('New Alias') %]</td><td><input type='text' name='alias' value='[% ctx.invalid_alias | html %]'/></td></tr>
+        <tr><td colspan='2' align='center'><input value="[% l('Submit') %]" type='submit'/></td></tr>
+    </table>
+</form>
+
+[% END %]