added method to return list of accessible objects based on object-specific perms
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 18 Feb 2008 23:17:32 +0000 (23:17 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 18 Feb 2008 23:17:32 +0000 (23:17 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8770 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm

index 6f7480f..419b235 100644 (file)
@@ -416,7 +416,9 @@ sub allowed {
            $self->log(I, "checking perms user=$uid, org=$org, perm=$perm");
     
         if($object) {
-            $OBJECT_PERM_QUERY->{select}->{au}->[0]->{params} = [$perm, $object->json_hint, $object->id, $org];
+            my $params = [$perm, $object->json_hint, $object->id];
+            push(@$params, $org) if $org;
+            $OBJECT_PERM_QUERY->{select}->{au}->[0]->{params} = $params;
             $OBJECT_PERM_QUERY->{where}->{id} = $uid;
             return 1 if $U->is_true($self->json_query($OBJECT_PERM_QUERY)->[0]->{has_perm});
 
@@ -435,6 +437,33 @@ sub allowed {
 
 
 # -----------------------------------------------------------------------------
+# Returns the list of object IDs this user has object-specific permissions for
+# -----------------------------------------------------------------------------
+sub objects_allowed {
+    my($self, $perm, $obj_type) = @_;
+
+    my $query = {
+        select => {puopm => ['object_id']},
+        from => {
+            puopm => {
+                ppl => {field => 'id',fkey => 'perm'}
+            }
+        },
+        where => {
+            '+puopm' => {usr => $self->requestor->id, object_type => $obj_type},
+            '+ppl' => {code => $perm}
+        }
+    };
+
+   my $list = $self->json_query($query);
+   my @ids;
+   push(@ids, 0+$_->{object_id}) for @$list;
+
+   return \@ids;
+}
+
+
+# -----------------------------------------------------------------------------
 # checks the appropriate perm for the operation
 # -----------------------------------------------------------------------------
 sub _checkperm {