Browse Source

add group

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
7b5b44aaa4

+ 7
- 3
src/Auth/Business/LuticateBusiness.php View File

85
     {
85
     {
86
         $prefix = "/luticate";
86
         $prefix = "/luticate";
87
         $ns = 'Luticate\Auth\Business\\';
87
         $ns = 'Luticate\Auth\Business\\';
88
-        $route->post("$prefix/login", "${ns}LuticateUsersBusiness", "login");
89
-        $route->put("$prefix/logout", "${ns}LuticateUsersBusiness", "logout");
90
-        $route->post("$prefix/add", "${ns}LuticateUsersBusiness", "add", LuticatePermissions::USER_ADD);
88
+
89
+        $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
90
+        $route->put("$prefix/users/logout", "${ns}LuticateUsersBusiness", "logout");
91
+        $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add", LuticatePermissions::USER_ADD);
92
+
93
+
94
+        $route->post("$prefix/groups/add", "${ns}LuticateGroupsBusiness", "add", LuticatePermissions::GROUP_ADD);
91
     }
95
     }
92
 }
96
 }

+ 16
- 0
src/Auth/Business/LuticateGroupsBusiness.php View File

12
         return new LuticateGroupsDataAccess();
12
         return new LuticateGroupsDataAccess();
13
     }
13
     }
14
 
14
 
15
+    public static function getByName($group_name)
16
+    {
17
+        return LuticateGroupsDataAccess::getByName($group_name);
18
+    }
19
+
15
     public static function addUserToGroup($user_id, $group_id)
20
     public static function addUserToGroup($user_id, $group_id)
16
     {
21
     {
17
         return LuticateGroupsDataAccess::addUserToGroup($user_id, $group_id);
22
         return LuticateGroupsDataAccess::addUserToGroup($user_id, $group_id);
18
     }
23
     }
24
+
25
+    public static function add($group_name)
26
+    {
27
+        $group = self::getByName($group_name);
28
+        if (is_null($group)) {
29
+            $group = new LuticateGroupsDbo();
30
+            $group->setName($group_name);
31
+            return LuticateGroupsDataAccess::addId($group);
32
+        }
33
+        return $group->getId();
34
+    }
19
 }
35
 }

+ 15
- 1
src/Auth/Business/LuticatePermissionsBusiness.php View File

14
 
14
 
15
     public static function getUserPermission($user_id, $permission_name)
15
     public static function getUserPermission($user_id, $permission_name)
16
     {
16
     {
17
-        return LuticatePermissionsDataAccess::getUserPermission($user_id, $permission_name);
17
+        $val = LuticatePermissionsDataAccess::getUserPermission($user_id, $permission_name);
18
+        if (is_null($val)) {
19
+            return false;
20
+        }
21
+        return $val;
22
+    }
23
+
24
+    public static function getUserDynamicPermission($user_id, $permission_name, $action, $resource_id)
25
+    {
26
+        $dynamic_permission_name = "DYN_" . $permission_name . "_" . $action . "_" . $resource_id;
27
+        $val = LuticatePermissionsDataAccess::getUserPermission($user_id, $dynamic_permission_name);
28
+        if (is_null($val)) {
29
+            return self::getUserPermission($user_id, $permission_name);
30
+        }
31
+        return $val;
18
     }
32
     }
19
 }
33
 }

+ 6
- 0
src/Auth/DBO/LuticatePermissions.php View File

12
 {
12
 {
13
     const USER_LOGIN = "LU_USER_LOGIN";
13
     const USER_LOGIN = "LU_USER_LOGIN";
14
     const USER_ADD = "LU_USER_ADD";
14
     const USER_ADD = "LU_USER_ADD";
15
+    const USER_EDIT = "LU_USER_EDIT";
16
+    const USER_DEL = "LU_USER_DEL";
17
+
18
+    const GROUP_ADD = "LU_GROUP_ADD";
19
+    const GROUP_EDIT = "LU_GROUP_EDIT";
20
+    const GROUP_DEL = "LU_GROUP_DEL";
15
 }
21
 }

+ 12
- 0
src/Auth/DataAccess/LuticateGroupsDataAccess.php View File

12
         return new LuticateGroups();
12
         return new LuticateGroups();
13
     }
13
     }
14
 
14
 
15
+    /**
16
+     * @param $group_name
17
+     * @return LuticateGroupsDbo|null
18
+     */
19
+    public static function getByName($group_name)
20
+    {
21
+        $group = LuticateGroups::where("name", "=", $group_name)->first();
22
+        if (is_null($group))
23
+            return null;
24
+        return $group->toDbo();
25
+    }
26
+
15
     public static function addUserToGroup($user_id, $group_id)
27
     public static function addUserToGroup($user_id, $group_id)
16
     {
28
     {
17
         LuticateGroups::find($group_id)->users()->attach($user_id);
29
         LuticateGroups::find($group_id)->users()->attach($user_id);

Loading…
Cancel
Save