[otrs-cvs] ITSMCore/Kernel/System/LinkObject Service.pm,1.11,1.12

"CVS commits notifications of OTRS.org" <[email protected]> Mon, 25 Mar 2013 19:08:05 +0000
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/ITSMCore/Kernel/System/LinkObject
In directory lancelot:/tmp/cvs-serv16252/Kernel/System/LinkObject

Modified Files:
	Service.pm 
Log Message:
Improved permission checks in LinkObject.

Author: ub

Index: Service.pm
===================================================================
RCS file: /home/cvs/ITSMCore/Kernel/System/LinkObject/Service.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -2 -u -d -r1.11 -r1.12
--- Service.pm	23 Mar 2013 14:18:16 -0000	1.11
+++ Service.pm	25 Mar 2013 19:08:00 -0000	1.12
@@ -15,4 +15,5 @@
 use warnings;
 
+use Kernel::System::Group;
 use Kernel::System::Service;
 
@@ -33,4 +34,5 @@
 
     # create additional objects
+    $Self->{GroupObject}   = Kernel::System::Group->new( %{$Self} );
     $Self->{ServiceObject} = Kernel::System::Service->new( %{$Self} );
 
@@ -101,4 +103,75 @@
 }
 
+=item ObjectPermission()
+
+checks read permission for a given object and UserID.
+
+    $Permission = $LinkObject->ObjectPermission(
+        Object  => 'Service',
+        Key     => 123,
+        UserID  => 1,
+    );
+
+=cut
+
+sub ObjectPermission {
+    my ( $Self, %Param ) = @_;
+
+    # check needed stuff
+    for my $Argument (qw(Object Key UserID)) {
+        if ( !$Param{$Argument} ) {
+            $Self->{LogObject}->Log(
+                Priority => 'error',
+                Message  => "Need $Argument!",
+            );
+            return;
+        }
+    }
+
+    # check module registry of AgentITSMServiceZoom
+    my $ModuleReg = $Self->{ConfigObject}->Get('Frontend::Module')->{AgentITSMServiceZoom};
+
+    # do not grant access if frontend module is not registered
+    return if !$ModuleReg;
+
+    # grant access if module permisson has no Group or GroupRo defined
+    if ( !$ModuleReg->{GroupRo} && !$ModuleReg->{Group} ) {
+        return 1;
+    }
+
+    PERMISSION:
+    for my $Permission (qw(GroupRo Group)) {
+
+        next PERMISSION if !$ModuleReg->{$Permission};
+        next PERMISSION if ref $ModuleReg->{$Permission} ne 'ARRAY';
+
+        for my $Group ( @{ $ModuleReg->{$Permission} } ) {
+
+            # get the group id
+            my $GroupID = $Self->{GroupObject}->GroupLookup( Group => $Group );
+
+            my $Type;
+            if ( $Permission eq 'GroupRo' ) {
+                $Type = 'ro';
+            }
+            elsif ( $Permission eq 'Group' ) {
+                $Type = 'rw';
+            }
+
+            # get user groups, where the user has the appropriate privilege
+            my %Groups = $Self->{GroupObject}->GroupMemberList(
+                UserID => $Param{UserID},
+                Type   => $Type,
+                Result => 'HASH',
+            );
+
+            # grant access if agent is a member in the group
+            return 1 if $Groups{$GroupID};
+        }
+    }
+
+    return;
+}
+
 =item ObjectDescriptionGet()
 
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log