added batch version of perm.highest_org and now make use of that method in
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 24 Jan 2006 23:27:03 +0000 (23:27 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 24 Jan 2006 23:27:03 +0000 (23:27 +0000)
the stat_cat_editor

git-svn-id: svn://svn.open-ils.org/ILS/trunk@2818 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/xul/staff_client/server/admin/stat_cat_editor.js

index eb4c01f..e15197f 100644 (file)
@@ -1116,7 +1116,7 @@ __PACKAGE__->register_method(
        method => 'check_user_perms3',
        api_name        => 'open-ils.actor.user.perm.highest_org',
        notes           => q/
-               Returns the highest org unit object at which a user has a given permission
+               Returns the highest org unit id at which a user has a given permission
                If the requestor does not match the target user, the requestor must have
                'VIEW_PERMISSION' rights at the home org unit of the target user
                @param authtoken The login session key
@@ -1136,18 +1136,58 @@ sub check_user_perms3 {
        return $evt if $evt;
 
        my $tree = get_org_tree();
-       $org = $apputils->find_org($tree, $target->home_ou );
+       return _find_highest_perm_org( $perm, $userid, $target->home_ou, $tree );
+}
+
+
+sub _find_highest_perm_org {
+       my ( $perm, $userid, $start_org, $org_tree ) = @_;
+       my $org = $apputils->find_org($org_tree, $start_org );
 
        my $lastid = undef;
        while( $org ) {
                last if ($apputils->check_perms( $userid, $org->id, $perm )); # perm failed
                $lastid = $org->id;
-               $org = $apputils->find_org( $tree, $org->parent_ou() );
+               $org = $apputils->find_org( $org_tree, $org->parent_ou() );
        }
 
        return $lastid;
 }
 
+__PACKAGE__->register_method(
+       method => 'check_user_perms4',
+       api_name        => 'open-ils.actor.user.perm.highest_org.batch',
+       notes           => q/
+               Returns the highest org unit id at which a user has a given permission
+               If the requestor does not match the target user, the requestor must have
+               'VIEW_PERMISSION' rights at the home org unit of the target user
+               @param authtoken The login session key
+               @param userid The id of the user in question
+               @param perms An array of perm names to check 
+               @return An array of orgId's  representing the org unit 
+               highest in the org tree within which the user has the requested permission
+               The arrah of orgId's has matches the order of the perms array
+       /);
+
+sub check_user_perms4 {
+       my( $self, $client, $authtoken, $userid, $perms ) = @_;
+       
+       my( $staff, $target, $org, $evt );
+
+       ( $staff, $target, $evt ) = $apputils->checkses_requestor(
+               $authtoken, $userid, 'VIEW_PERMISSION' );
+       return $evt if $evt;
+
+       my @arr;
+       return [] unless ref($perms);
+       my $tree = get_org_tree();
+
+       for my $p (@$perms) {
+               push( @arr, _find_highest_perm_org( $p, $userid, $target->home_ou, $tree ) );
+       }
+       return \@arr;
+}
+
 
 
 
index 3c8c6ef..8ac94e8 100644 (file)
@@ -112,48 +112,36 @@ sub rollback_db_session {
        $session->kill_me();
 }
 
+
+# returns undef it the event is not an ILS event
+# returns the event code otherwise
+sub event_code {
+       my( $self, $evt ) = @_;
+       return $evt->{ilsevent} if( ref($evt) eq 'HASH' and defined($evt->{ilsevent})) ;
+       return undef;
+}
+
 # ---------------------------------------------------------------------------
 # Checks to see if a user is logged in.  Returns the user record on success,
 # throws an exception on error.
 # ---------------------------------------------------------------------------
-
-
 sub check_user_session {
 
        my( $self, $user_session ) = @_;
 
-       my $session = OpenSRF::AppSession->create( "open-ils.auth" );
-       my $request = $session->request("open-ils.auth.session.retrieve", $user_session );
-       my $response = $request->recv();
+       my $content = $self->simplereq( 
+               'open-ils.auth', 
+               'open-ils.auth.session.retrieve', $user_session );
 
-       if(!$response) {
-               throw OpenSRF::EX::User 
-                       ("Error communication with storage server");
-       }
 
-       if(ref($response) and $response->isa("OpenSRF::EX")) {
-               throw $response ($response->stringify);
-       }
-
-
-       my $content = $response->content;
-       if( ref($content) eq 'HASH' ) {
-               if(defined($content->{ilsevent}) and $content->{ilsevent} ne '0' ) {
-                       throw OpenSRF::EX::ERROR 
-                               ("Session [$user_session] cannot be authenticated" );
-               }
-       }
-
-       my $user = $content;
-       if(!$user) {
+       if(! $content or $self->event_code($content)) {
                throw OpenSRF::EX::ERROR 
                        ("Session [$user_session] cannot be authenticated" );
        }
 
-       $session->disconnect();
-       $session->kill_me();
+       $logger->debug("Fetch user session $user_session found user " . $content->id );
 
-       return $user;
+       return $content;
 }
 
 # generic simple request returning a scalar value
index 2e04895..467ad2e 100644 (file)
@@ -41,19 +41,39 @@ function scGo() {
 
 function scFetchPerms() {
 
-       PERMS[ACTOR].create_stat_cat = scFetchPerm('CREATE_PATRON_STAT_CAT');
-       PERMS[ACTOR].update_stat_cat = scFetchPerm('UPDATE_PATRON_STAT_CAT');
-       PERMS[ACTOR].delete_stat_cat = scFetchPerm('DELETE_PATRON_STAT_CAT');
-       PERMS[ACTOR].create_stat_cat_entry = scFetchPerm('CREATE_PATRON_STAT_CAT_ENTRY');
-       PERMS[ACTOR].update_stat_cat_entry = scFetchPerm('UPDATE_PATRON_STAT_CAT_ENTRY');
-       PERMS[ACTOR].delete_stat_cat_entry = scFetchPerm('DELETE_PATRON_STAT_CAT_ENTRY');
-
-       PERMS[ASSET].create_stat_cat = scFetchPerm('CREATE_COPY_STAT_CAT');
-       PERMS[ASSET].update_stat_cat = scFetchPerm('UPDATE_COPY_STAT_CAT');
-       PERMS[ASSET].delete_stat_cat = scFetchPerm('DELETE_COPY_STAT_CAT');
-       PERMS[ASSET].create_stat_cat_entry = scFetchPerm('CREATE_COPY_STAT_CAT_ENTRY');
-       PERMS[ASSET].update_stat_cat_entry = scFetchPerm('UPDATE_COPY_STAT_CAT_ENTRY');
-       PERMS[ASSET].delete_stat_cat_entry = scFetchPerm('DELETE_COPY_STAT_CAT_ENTRY');
+       var req = new RemoteRequest(
+               'open-ils.actor',
+               'open-ils.actor.user.perm.highest_org.batch', session, user.id(), 
+               [       'CREATE_PATRON_STAT_CAT',
+                       'UPDATE_PATRON_STAT_CAT',
+                       'DELETE_PATRON_STAT_CAT',
+                       'CREATE_PATRON_STAT_CAT_ENTRY',
+                       'UPDATE_PATRON_STAT_CAT_ENTRY',
+                       'DELETE_PATRON_STAT_CAT_ENTRY',
+       
+                       'CREATE_COPY_STAT_CAT',
+                       'UPDATE_COPY_STAT_CAT',
+                       'DELETE_COPY_STAT_CAT',
+                       'CREATE_COPY_STAT_CAT_ENTRY',
+                       'UPDATE_COPY_STAT_CAT_ENTRY',
+                       'DELETE_COPY_STAT_CAT_ENTRY' ] );
+
+       req.send(true);
+       var orgs = req.getResultObject();
+
+       PERMS[ACTOR].create_stat_cat = orgs[0];
+       PERMS[ACTOR].update_stat_cat = orgs[1];
+       PERMS[ACTOR].delete_stat_cat = orgs[2];
+       PERMS[ACTOR].create_stat_cat_entry = orgs[3];
+       PERMS[ACTOR].update_stat_cat_entry = orgs[4];
+       PERMS[ACTOR].delete_stat_cat_entry = orgs[5];
+
+       PERMS[ASSET].create_stat_cat = orgs[6];
+       PERMS[ASSET].update_stat_cat = orgs[7];
+       PERMS[ASSET].delete_stat_cat = orgs[8];
+       PERMS[ASSET].create_stat_cat_entry =  orgs[9];
+       PERMS[ASSET].update_stat_cat_entry =  orgs[10];
+       PERMS[ASSET].delete_stat_cat_entry =  orgs[11];
 }
 
 function scFetchPerm(perm) {