Browse Source

permissions get all effective

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
98f9e1a628

+ 4
- 0
src/Auth/Business/LuticateBusiness.php View File

@@ -87,8 +87,12 @@ class LuticateBusiness
87 87
 
88 88
         $route->get("$prefix/permissions/effective/$user_id/$permission_name", "${ns}LuticatePermissionsController",
89 89
             "getEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
90
+        $route->get("$prefix/permissions/effective/$user_id", "${ns}LuticatePermissionsController",
91
+            "getAllEffectivePermission", LuticatePermissions::PERM_EFFECTIVE_GET);
90 92
         $route->get("$prefix/permissions/effective/me/$permission_name", "${ns}LuticatePermissionsController",
91 93
             "getEffectivePermissionMe");
94
+        $route->get("$prefix/permissions/effective/me", "${ns}LuticatePermissionsController",
95
+            "getAllEffectivePermissionMe");
92 96
 
93 97
         $route->get("$prefix/permissions/$permission_name", "${ns}LuticatePermissionsController", "get",
94 98
             LuticatePermissions::PERM_GET);

+ 10
- 0
src/Auth/Business/LuticatePermissionsBusiness.php View File

@@ -31,11 +31,21 @@ class LuticatePermissionsBusiness extends LuBusiness {
31 31
         return $perm;
32 32
     }
33 33
 
34
+    public static function getAllEffectivePermission($user_id)
35
+    {
36
+        return LuticatePermissionsDataAccess::getAllEffectivePermission($user_id);
37
+    }
38
+
34 39
     public static function getEffectivePermissionMe($user, $permission_name)
35 40
     {
36 41
         return self::getEffectivePermission($user->getId(), $permission_name);
37 42
     }
38 43
 
44
+    public static function getAllEffectivePermissionMe($user)
45
+    {
46
+        return self::getAllEffectivePermission($user->getId());
47
+    }
48
+
39 49
     public static function getEffectiveDynamicPermission($user_id, $permission_name, $resource_id)
40 50
     {
41 51
         $dynamic_permission_name = "LU_DYN_" . $permission_name . "_" . $resource_id;

+ 20
- 0
src/Auth/Controller/LuticatePermissionsController.php View File

@@ -35,6 +35,26 @@ class LuticatePermissionsController extends LuController {
35 35
         return LuticatePermissionsBusiness::getEffectivePermissionMe($_user, $permission_name);
36 36
     }
37 37
 
38
+    /**
39
+     * Get all the effective permission for a user
40
+     * @param $user_id int The user id
41
+     * @return LuticatePermissionsDbo
42
+     */
43
+    public function getAllEffectivePermission($user_id)
44
+    {
45
+        return LuticatePermissionsBusiness::getAllEffectivePermission($user_id);
46
+    }
47
+
48
+    /**
49
+     * Get all the effective permission for the logged user
50
+     * @param $_user LuticateUsersDbo Logged user
51
+     * @return LuticatePermissionsDbo
52
+     */
53
+    public function getAllEffectivePermissionMe($_user)
54
+    {
55
+        return LuticatePermissionsBusiness::getAllEffectivePermissionMe($_user);
56
+    }
57
+
38 58
     /**
39 59
      * Get a permission
40 60
      * @param $permission_name string The permission name

+ 14
- 0
src/Auth/DataAccess/LuticatePermissionsDataAccess.php View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 namespace Luticate\Auth\DataAccess;
4 4
 
5
+use Luticate\Auth\DataAccess\SP\SpLuGetAllUserPermission;
5 6
 use Luticate\Auth\DataAccess\SP\SpLuGetUserPermission;
6 7
 use Luticate\Utils\LuDataAccess;
7 8
 use Luticate\Auth\DataAccess\Models\LuticatePermissions;
@@ -23,6 +24,19 @@ class LuticatePermissionsDataAccess extends LuDataAccess {
23 24
         return SpLuGetUserPermission::execute($user_id, $permission_name)->getVal();
24 25
     }
25 26
 
27
+    public static function getAllEffectivePermission($user_id)
28
+    {
29
+        $values = SpLuGetAllUserPermission::execute($user_id);
30
+        $dbos = [];
31
+        foreach ($values as $value) {
32
+            $dbo = new LuticatePermissionsDbo();
33
+            $dbo->setName($value->getPermissonName());
34
+            $dbo->setValue($value->getVal());
35
+            $dbos[] = $dbo;
36
+        }
37
+        return $dbos;
38
+    }
39
+
26 40
     public static function getModelByName($permission_name)
27 41
     {
28 42
         return LuticatePermissions::where("name", "=", $permission_name)->first();

+ 61
- 0
src/Auth/DataAccess/SP/SpLuGetAllUserPermission.php View File

@@ -0,0 +1,61 @@
1
+<?php
2
+
3
+/**
4
+ * AUTO GENERATED BY LUTICATE GENERATOR
5
+ * ANY CHANGES WILL BE OVERWRITTEN
6
+ */
7
+
8
+namespace Luticate\Auth\DataAccess\SP;
9
+
10
+use Luticate\Utils\LuSpModel;
11
+use Illuminate\Support\Facades\DB;
12
+
13
+class SpLuGetAllUserPermission extends LuSpModel {
14
+
15
+    protected static function damToDbo($dam)
16
+    {
17
+        if (is_null($dam))
18
+            return null;
19
+        $dbo = new SpLuGetAllUserPermission();
20
+
21
+        $dbo->setPermissonName($dam->_permisson_name);
22
+        $dbo->setVal($dam->val);
23
+
24
+        return $dbo;
25
+    }
26
+
27
+    public static function execute($_user_id)
28
+    {
29
+        $values = DB::select('SELECT * FROM sp_lu_get_all_user_permission(?)', array($_user_id));
30
+        $dboValues = array();
31
+        foreach ($values as $value)
32
+            $dboValues[] = self::damToDbo($value);
33
+        return $dboValues;
34
+    }
35
+
36
+    /**
37
+    * @var string
38
+    */
39
+    protected $_PermissonName;
40
+    public function getPermissonName()
41
+    {
42
+        return $this->_PermissonName;
43
+    }
44
+    public function setPermissonName($value)
45
+    {
46
+        $this->_PermissonName = $value;
47
+    }
48
+
49
+    /**
50
+    * @var boolean
51
+    */
52
+    protected $_val;
53
+    public function getVal()
54
+    {
55
+        return $this->_val;
56
+    }
57
+    public function setVal($value)
58
+    {
59
+        $this->_val = $value;
60
+    }
61
+}

Loading…
Cancel
Save