Browse Source

refractor

develop
Robin Thoni 8 years ago
parent
commit
ef73ada604

+ 18
- 0
src/Auth/DataAccess/LuPermissionsDataAccess.php View File

2
 
2
 
3
 namespace Luticate\Auth\DataAccess;
3
 namespace Luticate\Auth\DataAccess;
4
 
4
 
5
+use Luticate\Auth\DataAccess\Sp\SpLuGetUserEffectivePermissionById;
6
+use Luticate\Auth\DataAccess\Sp\SpLuGetUserEffectivePermissionByName;
7
+use Luticate\Auth\DataAccess\Sp\SpLuGetUserEffectivePermissions;
5
 use Luticate\Utils\DataAccess\LuDataAccess;
8
 use Luticate\Utils\DataAccess\LuDataAccess;
6
 
9
 
7
 class LuPermissionsDataAccess extends LuDataAccess {
10
 class LuPermissionsDataAccess extends LuDataAccess {
8
     protected static $_connection = "luticatedb";
11
     protected static $_connection = "luticatedb";
9
     protected static $_table = "lu_permissions";
12
     protected static $_table = "lu_permissions";
13
+
14
+    public static function getUserEffectivePermissionById(int $userId, int $permissionId)
15
+    {
16
+        return SpLuGetUserEffectivePermissionById::getUserEffectivePermission($userId, $permissionId);
17
+    }
18
+
19
+    public static function getUserEffectivePermissionByName(int $userId, string $permissionName)
20
+    {
21
+        return SpLuGetUserEffectivePermissionByName::getUserEffectivePermission($userId, $permissionName);
22
+    }
23
+
24
+    public static function getUserEffectivePermissions(int $userId)
25
+    {
26
+        return SpLuGetUserEffectivePermissions::getUserEffectivePermissions($userId);
27
+    }
10
 }
28
 }

+ 1
- 1
src/Auth/DataAccess/Sp/SpLuGetUserEffectivePermissionById.php View File

22
      * @param $permissionId int
22
      * @param $permissionId int
23
      * @return bool
23
      * @return bool
24
      */
24
      */
25
-    public static function getPermissionValue(int $userId, int $permissionId)
25
+    public static function getUserEffectivePermission(int $userId, int $permissionId)
26
     {
26
     {
27
         /**
27
         /**
28
          * @var $val LuBoolDbo
28
          * @var $val LuBoolDbo

+ 1
- 1
src/Auth/DataAccess/Sp/SpLuGetUserEffectivePermissionByName.php View File

22
      * @param $permissionName string
22
      * @param $permissionName string
23
      * @return bool
23
      * @return bool
24
      */
24
      */
25
-    public static function getPermissionValue(int $userId, string $permissionName)
25
+    public static function getUserEffectivePermission(int $userId, string $permissionName)
26
     {
26
     {
27
         /**
27
         /**
28
          * @var $val LuBoolDbo
28
          * @var $val LuBoolDbo

+ 32
- 0
src/Auth/DataAccess/Sp/SpLuGetUserEffectivePermissions.php View File

1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 7/2/16
6
+ * Time: 5:32 PM
7
+ */
8
+
9
+namespace Luticate\Auth\DataAccess\Sp;
10
+
11
+use Luticate\Auth\Dbo\LuPermissionLite;
12
+use Luticate\Utils\DataAccess\LuStoredProcedure;
13
+
14
+class SpLuGetUserEffectivePermissions extends LuStoredProcedure
15
+{
16
+    protected static $_connection = "luticatedb";
17
+    protected static $_storedProcedure = "sp_lu_get_user_effective_permissions";
18
+    protected static $_dboClass = LuPermissionLite::class;
19
+
20
+    /**
21
+     * @param $userId int
22
+     * @return LuPermissionLite[]
23
+     */
24
+    public static function getUserEffectivePermissions(int $userId)
25
+    {
26
+        /**
27
+         * @var $val LuPermissionLite[]
28
+         */
29
+        $val = static::getMultiple([$userId]);
30
+        return $val;
31
+    }
32
+}

+ 53
- 4
tests/LuPermissionTest.php View File

1
 <?php
1
 <?php
2
-use Luticate\Auth\DataAccess\Sp\SpLuGetUserEffectivePermissionById;
3
-use Luticate\Auth\DataAccess\Sp\SpLuGetUserEffectivePermissionByName;
2
+
3
+use Luticate\Auth\DataAccess\LuPermissionsDataAccess;
4
+use Luticate\Utils\Dbo\LuDbo;
4
 
5
 
5
 /**
6
 /**
6
  * Created by PhpStorm.
7
  * Created by PhpStorm.
12
 {
13
 {
13
     protected function permissionTest($expectedValue, string $permissionName, int $permissionId, int $userId)
14
     protected function permissionTest($expectedValue, string $permissionName, int $permissionId, int $userId)
14
     {
15
     {
15
-        $this->assertSame($expectedValue, SpLuGetUserEffectivePermissionByName::getPermissionValue($userId, $permissionName));
16
-        $this->assertSame($expectedValue, SpLuGetUserEffectivePermissionById::getPermissionValue($userId, $permissionId));
16
+        $this->assertSame($expectedValue, LuPermissionsDataAccess::getUserEffectivePermissionByName($userId, $permissionName));
17
+        $this->assertSame($expectedValue, LuPermissionsDataAccess::getUserEffectivePermissionById($userId, $permissionId));
17
     }
18
     }
18
 
19
 
19
     public function testPermission0True()
20
     public function testPermission0True()
65
     {
66
     {
66
         static::permissionTest(false, "LU_TEST_USER_6_FALSE", 11, 6);
67
         static::permissionTest(false, "LU_TEST_USER_6_FALSE", 11, 6);
67
     }
68
     }
69
+
70
+    public function testPermissionGetAll0()
71
+    {
72
+        $permissions = [
73
+            ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
74
+            ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
75
+            ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
76
+            ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
77
+            ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => true],
78
+            ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
79
+            ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
80
+            ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
81
+            ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => true]];
82
+
83
+        $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(0)));
84
+    }
85
+
86
+    public function testPermissionGetAll4()
87
+    {
88
+        $permissions = [
89
+            ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
90
+            ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
91
+            ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
92
+            ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
93
+            ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => false],
94
+            ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
95
+            ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
96
+            ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
97
+            ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => true]];
98
+
99
+        $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(4)));
100
+    }
101
+
102
+    public function testPermissionGetAll6()
103
+    {
104
+        $permissions = [
105
+            ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
106
+            ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
107
+            ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
108
+            ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
109
+            ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => true],
110
+            ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
111
+            ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
112
+            ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
113
+            ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => false]];
114
+
115
+        $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(6)));
116
+    }
68
 }
117
 }

Loading…
Cancel
Save