Przeglądaj źródła

get effective permissions; get permissions at login

tags/0.1.0
Robin Thoni 9 lat temu
rodzic
commit
2eca71abee
3 zmienionych plików z 102 dodań i 5 usunięć
  1. 16
    0
      src/cache.js
  2. 61
    0
      src/permissions.js
  3. 25
    5
      src/users.js

+ 16
- 0
src/cache.js Wyświetl plik

@@ -32,6 +32,22 @@
32 32
             luticateAuthCache.removeUser = function()
33 33
             {
34 34
                 localStorageService.remove('lu_user');
35
+                luticateAuthCache.removeEffectivePermissions();
36
+            };
37
+
38
+            luticateAuthCache.setEffectivePermissions = function(permissions)
39
+            {
40
+                localStorageService.set('lu_effective_permissions', permissions);
41
+            };
42
+
43
+            luticateAuthCache.getEffectivePermissions = function()
44
+            {
45
+                return localStorageService.get('lu_effective_permissions');
46
+            };
47
+
48
+            luticateAuthCache.removeEffectivePermissions = function()
49
+            {
50
+                localStorageService.remove('lu_effective_permissions');
35 51
             };
36 52
 
37 53
             return luticateAuthCache;

+ 61
- 0
src/permissions.js Wyświetl plik

@@ -0,0 +1,61 @@
1
+/**
2
+ * Created by robin on 11/1/15.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticateAuth')
8
+        .factory('luticateAuthPermissions', ['luticateRequest',
9
+            function(luticateRequest) {
10
+
11
+                var luticateAuthPermissions = {};
12
+
13
+                luticateAuthPermissions.getAll = function(data, promise)
14
+                {
15
+                    return luticateRequest.get("/api/luticate/permissions", data, promise);
16
+                };
17
+
18
+                luticateAuthPermissions.edit = function(data, promise)
19
+                {
20
+                    return luticateRequest.post("/api/luticate/permissions/" + data.permission_name + "/edit/"
21
+                        + data.permission_value, null, null, promise);
22
+                };
23
+
24
+                luticateAuthPermissions.add = function(data, promise)
25
+                {
26
+                    return luticateRequest.post("/api/luticate/permissions/add/" + data.permission_name + "/"
27
+                        + data.permission_value, null, null, promise);
28
+                };
29
+
30
+                luticateAuthPermissions.del = function(data, promise)
31
+                {
32
+                    return luticateRequest.post("/api/luticate/permissions/" + data.permission_name + "/del",
33
+                        null, null, promise);
34
+                };
35
+
36
+                luticateAuthPermissions.getEffectiveUser = function(data, promise)
37
+                {
38
+                    return luticateRequest.get("/api/luticate/permissions/effective/" + data.user_id
39
+                        + "/" + data.permission_name, null, promise);
40
+                };
41
+
42
+                luticateAuthPermissions.getAllEffectiveUser = function(data, promise)
43
+                {
44
+                    return luticateRequest.get("/api/luticate/permissions/effective/" + data.user_id, null, promise);
45
+                };
46
+
47
+                luticateAuthPermissions.getEffectiveMe = function(data, promise)
48
+                {
49
+                    return luticateRequest.get("/api/luticate/permissions/effective/me/"
50
+                        + data.permission_name, null, promise);
51
+                };
52
+
53
+                luticateAuthPermissions.getAllEffectiveMe = function(promise)
54
+                {
55
+                    return luticateRequest.get("/api/luticate/permissions/effective/me", null, promise);
56
+                };
57
+
58
+
59
+                return luticateAuthPermissions;
60
+        }]);
61
+})();

+ 25
- 5
src/users.js Wyświetl plik

@@ -5,8 +5,8 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticateAuth')
8
-        .factory('luticateAuthUsers', ['luticateRequest', '$q', 'luticateAuthCache',
9
-            function(luticateRequest, $q, luticateAuthCache) {
8
+        .factory('luticateAuthUsers', ['luticateRequest', '$q', 'luticateAuthCache', 'luticateAuthPermissions',
9
+            function(luticateRequest, $q, luticateAuthCache, luticateAuthPermissions) {
10 10
 
11 11
                 var luticateAuthUsers = {};
12 12
 
@@ -14,10 +14,18 @@
14 14
                 {
15 15
                     var defer = $q.defer();
16 16
                     luticateRequest.post("/api/luticate/users/login", data, null, promise)
17
-                        .then(function(data)
17
+                        .then(function(user)
18 18
                         {
19
-                            luticateAuthCache.setUser(data);
20
-                            defer.resolve(data);
19
+                            luticateAuthUsers.loadPermissions(user, promise)
20
+                                .then(function(permissions)
21
+                                {
22
+                                    luticateAuthCache.setUser(user);
23
+                                    defer.resolve(user);
24
+                                }, function(error)
25
+                                {
26
+                                    luticateAuthCache.removeUser();
27
+                                    defer.reject(error);
28
+                                });
21 29
                         }, function(error)
22 30
                         {
23 31
                             luticateAuthCache.removeUser();
@@ -26,6 +34,18 @@
26 34
                     return defer.promise;
27 35
                 };
28 36
 
37
+                luticateAuthUsers.loadPermissions = function(promise)
38
+                {
39
+                    var defer = $q.defer();
40
+                    luticateAuthPermissions.getAllEffectiveMe(promise)
41
+                        .then(function(permissions)
42
+                        {
43
+                            luticateAuthCache.setEffectivePermissions(permissions);
44
+                            defer.resolve(permissions);
45
+                        }, defer.reject);
46
+                    return defer.promise;
47
+                };
48
+
29 49
                 luticateAuthUsers.logout = function(promise)
30 50
                 {
31 51
                     var defer = $q.defer();

Ładowanie…
Anuluj
Zapisz