[otrs-cvs] FAQ/Kernel/System/LinkObject FAQ.pm,1.16,1.16.2.1

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

Modified Files:
      Tag: rel-2_0
	FAQ.pm 
Log Message:
Improved permission checks in LinkObject.

Author: ub

Index: FAQ.pm
===================================================================
RCS file: /home/cvs/FAQ/Kernel/System/LinkObject/FAQ.pm,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -2 -u -d -r1.16 -r1.16.2.1
--- FAQ.pm	22 Dec 2010 05:18:24 -0000	1.16
+++ FAQ.pm	25 Mar 2013 18:25:09 -0000	1.16.2.1
@@ -1,5 +1,5 @@
 # --
 # Kernel/System/LinkObject/FAQ.pm - to link faq objects
-# Copyright (C) 2001-2010 OTRS AG, http://otrs.org/
+# Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
 # --
 # $Id$
@@ -7,5 +7,5 @@
 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
 # the enclosed file COPYING for license information (AGPL). If you
-# did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
+# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
 # --
 
@@ -15,4 +15,5 @@
 use warnings;
 
+use Kernel::System::Group;
 use Kernel::System::FAQ;
 
@@ -33,5 +34,6 @@
 
     # create additional objects
-    $Self->{FAQObject} = Kernel::System::FAQ->new( %{$Self} );
+    $Self->{GroupObject} = Kernel::System::Group->new( %{$Self} );
+    $Self->{FAQObject}   = Kernel::System::FAQ->new( %{$Self} );
 
     return $Self;
@@ -72,10 +74,10 @@
     }
 
-    for my $LinkType ( keys %{ $Param{LinkList} } ) {
+    for my $LinkType ( sort keys %{ $Param{LinkList} } ) {
 
-        for my $Direction ( keys %{ $Param{LinkList}->{$LinkType} } ) {
+        for my $Direction ( sort keys %{ $Param{LinkList}->{$LinkType} } ) {
 
             FAQID:
-            for my $FAQID ( keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
+            for my $FAQID ( sort keys %{ $Param{LinkList}->{$LinkType}->{$Direction} } ) {
 
                 # get faq data
@@ -100,4 +102,75 @@
 }
 
+=item ObjectPermission()
+
+checks read permission for a given object and UserID.
+
+    $Permission = $LinkObject->ObjectPermission(
+        Object  => 'FAQ',
+        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 AgentFAQZoom
+    my $ModuleReg = $Self->{ConfigObject}->Get('Frontend::Module')->{AgentFAQZoom};
+
+    # 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