Browse Source

user edition; group edition

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
cb8d3df4c4

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

98
         $user_id = "{user_id:$int}";
98
         $user_id = "{user_id:$int}";
99
 
99
 
100
         $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
100
         $route->post("$prefix/users/login", "${ns}LuticateUsersBusiness", "login");
101
-        $route->put("$prefix/users/logout", "${ns}LuticateUsersBusiness", "logout");
101
+        $route->post("$prefix/users/logout", "${ns}LuticateUsersBusiness", "logout");
102
         $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add", LuticatePermissions::USER_ADD);
102
         $route->post("$prefix/users/add", "${ns}LuticateUsersBusiness", "add", LuticatePermissions::USER_ADD);
103
+        $route->post("$prefix/users/$user_id/del", "${ns}LuticateUsersBusiness", "del", LuticatePermissions::USER_DEL);
103
         $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersBusiness", "edit", LuticatePermissions::USER_EDIT);
104
         $route->post("$prefix/users/$user_id/edit", "${ns}LuticateUsersBusiness", "edit", LuticatePermissions::USER_EDIT);
104
-        $route->post("$prefix/users/me/edit", "${ns}LuticateUsersBusiness", "editMe", LuticatePermissions::USER_EDIT_MYSELF);
105
+        $route->post("$prefix/users/me/edit", "${ns}LuticateUsersBusiness", "editMe", LuticatePermissions::USER_EDIT_ME);
105
         $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersBusiness", "setPassword", LuticatePermissions::USER_SET_PASSWORD);
106
         $route->post("$prefix/users/$user_id/setPassword", "${ns}LuticateUsersBusiness", "setPassword", LuticatePermissions::USER_SET_PASSWORD);
106
-        $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersBusiness", "setPasswordMe", LuticatePermissions::USER_SET_PASSWORD_MYSELF);
107
+        $route->post("$prefix/users/me/setPassword", "${ns}LuticateUsersBusiness", "setPasswordMe", LuticatePermissions::USER_SET_PASSWORD_ME);
107
 
108
 
108
 
109
 
109
         $route->post("$prefix/groups/add", "${ns}LuticateGroupsBusiness", "add", LuticatePermissions::GROUP_ADD);
110
         $route->post("$prefix/groups/add", "${ns}LuticateGroupsBusiness", "add", LuticatePermissions::GROUP_ADD);
110
-        $route->post("$prefix/groups/del/$group_id", "${ns}LuticateGroupsBusiness", "del", LuticatePermissions::GROUP_DEL);
111
+        $route->post("$prefix/groups/$group_id/del", "${ns}LuticateGroupsBusiness", "del", LuticatePermissions::GROUP_DEL);
112
+        $route->post("$prefix/groups/$group_id/edit", "${ns}LuticateGroupsBusiness", "edit", LuticatePermissions::GROUP_EDIT);
111
         $route->post("$prefix/groups/$group_id/addUser/$user_id", "${ns}LuticateGroupsBusiness", "addUser", LuticatePermissions::GROUP_ADD_USER);
113
         $route->post("$prefix/groups/$group_id/addUser/$user_id", "${ns}LuticateGroupsBusiness", "addUser", LuticatePermissions::GROUP_ADD_USER);
112
         $route->post("$prefix/groups/$group_id/delUser/$user_id", "${ns}LuticateGroupsBusiness", "delUser", LuticatePermissions::GROUP_DEL_USER);
114
         $route->post("$prefix/groups/$group_id/delUser/$user_id", "${ns}LuticateGroupsBusiness", "delUser", LuticatePermissions::GROUP_DEL_USER);
113
     }
115
     }

+ 24
- 4
src/Auth/Business/LuticateGroupsBusiness.php View File

12
         return new LuticateGroupsDataAccess();
12
         return new LuticateGroupsDataAccess();
13
     }
13
     }
14
 
14
 
15
+    /**
16
+     * @param $group_id
17
+     * @return LuticateGroupsDbo|null
18
+     */
15
     public static function checkGroupId($group_id)
19
     public static function checkGroupId($group_id)
16
     {
20
     {
17
-        if (is_null(self::getById($group_id))) {
21
+        $group = self::getById($group_id);
22
+        if (is_null($group)) {
18
             self::notFound("Group not found");
23
             self::notFound("Group not found");
19
         }
24
         }
25
+        return $group;
20
     }
26
     }
21
 
27
 
22
     public static function getByName($group_name)
28
     public static function getByName($group_name)
54
             $group->setName($group_name);
60
             $group->setName($group_name);
55
             return LuticateGroupsDataAccess::addId($group);
61
             return LuticateGroupsDataAccess::addId($group);
56
         }
62
         }
57
-        return $group->getId();
63
+        self::badInput("Group name already exists");
64
+        return false;
58
     }
65
     }
59
 
66
 
60
-    public static function del($group_id)
67
+    public static function edit($group_id, $group_name)
61
     {
68
     {
62
-        self::checkGroupId($group_id);
69
+        $group = self::getByName($group_name);
70
+        if (!is_null($group) && $group->getId() != $group_id) {
71
+            self::badInput("Group name already exists");
72
+        }
73
+        $group = self::checkGroupId($group_id);
74
+        $group->setName($group_name);
63
 
75
 
76
+        LuticateGroupsDataAccess::editById($group_id, $group);
77
+        return true;
78
+    }
79
+
80
+    public static function del($group_id)
81
+    {
82
+        LuticateGroupsDataAccess::deleteById($group_id);
83
+        return true;
64
     }
84
     }
65
 }
85
 }

+ 5
- 5
src/Auth/Business/LuticatePermissionsBusiness.php View File

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

+ 2
- 2
src/Auth/DBO/LuticatePermissions.php View File

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";
15
     const USER_EDIT = "LU_USER_EDIT";
16
-    const USER_EDIT_MYSELF = "LU_USER_EDIT_MYSELF";
16
+    const USER_EDIT_ME = "LU_USER_EDIT_ME";
17
     const USER_DEL = "LU_USER_DEL";
17
     const USER_DEL = "LU_USER_DEL";
18
     const USER_SET_PASSWORD = "LU_USER_SET_PASSWORD";
18
     const USER_SET_PASSWORD = "LU_USER_SET_PASSWORD";
19
-    const USER_SET_PASSWORD_MYSELF = "LU_USER_SET_PASSWORD_MYSELF";
19
+    const USER_SET_PASSWORD_ME = "LU_USER_SET_PASSWORD_ME";
20
 
20
 
21
     const GROUP_ADD = "LU_GROUP_ADD";
21
     const GROUP_ADD = "LU_GROUP_ADD";
22
     const GROUP_EDIT = "LU_GROUP_EDIT";
22
     const GROUP_EDIT = "LU_GROUP_EDIT";

Loading…
Cancel
Save