Kaynağa Gözat

lu has permission mutliple

tags/0.1.0
Robin Thoni 9 yıl önce
ebeveyn
işleme
fa4f9e3bda
2 değiştirilmiş dosya ile 61 ekleme ve 56 silme
  1. 53
    52
      src/luhaspermission.js
  2. 8
    4
      src/lupermissionsedit.js

+ 53
- 52
src/luhaspermission.js Dosyayı Görüntüle

@@ -2,58 +2,59 @@
2 2
  * Created by robin on 11/5/15.
3 3
  */
4 4
 
5
-angular.module('luticateUtils')
6
-    .directive('luShowPermission', ['luticateAuthCache',
7
-        function(luticateAuthCache) {
8
-            return {
9
-                restrict: 'A',
10
-                link: function ($scope, element, attrs) {
5
+(function()
6
+{
7
+    function checkPermissions(permissions, luticateAuthCache)
8
+    {
9
+        var perms = permissions.split(',');
10
+        for (var i = 0; i < perms.length; ++i) {
11
+            if (!luticateAuthCache.hasEffectivePermission(perms[i])) {
12
+                return false;
13
+            }
14
+        }
15
+        return true;
16
+    }
11 17
 
12
-                    $scope.$watch(function()
13
-                    {
14
-                        var permissions = luticateAuthCache.getEffectivePermissions();
15
-                        if (permissions == null) {
16
-                            return null;
17
-                        }
18
-                        var permission_name = attrs.luShowPermission;
19
-                        if ($scope[permission_name] != null) {
20
-                            permission_name = $scope[permission_name];
21
-                        }
18
+    angular.module('luticateUtils')
19
+        .directive('luShowPermission', ['luticateAuthCache',
20
+            function(luticateAuthCache) {
21
+                return {
22
+                    restrict: 'A',
23
+                    link: function ($scope, element, attrs) {
22 24
 
23
-                        var value = permissions[permission_name];
24
-                        return value == null ? null : value;
25
-                    }, function(newValue, oldValue)
26
-                    {
27
-                        if (newValue == true) {
28
-                            element.show();
29
-                        }
30
-                        else {
31
-                            element.hide();
32
-                        }
33
-                    })
34
-                }
35
-            };
36
-        }])
37
-    .directive('luEnablePermission', ['luticateAuthCache',
38
-        function(luticateAuthCache) {
39
-            return {
40
-                restrict: 'A',
41
-                scope: {
42
-                    luEnablePermission: '@'
43
-                },
44
-                link: function ($scope, element, attrs) {
25
+                        $scope.$watch(function()
26
+                        {
27
+                            return checkPermissions(attrs.luShowPermission, luticateAuthCache);
28
+                        }, function(newValue)
29
+                        {
30
+                            if (newValue == true) {
31
+                                element.show();
32
+                            }
33
+                            else {
34
+                                element.hide();
35
+                            }
36
+                        })
37
+                    }
38
+                };
39
+            }])
40
+        .directive('luEnablePermission', ['luticateAuthCache',
41
+            function(luticateAuthCache) {
42
+                return {
43
+                    restrict: 'A',
44
+                    link: function ($scope, element, attrs) {
45 45
 
46
-                    $scope.$watch(function() {
47
-                        return luticateAuthCache.hasEffectivePermissions($scope.luEnablePermission);
48
-                    }, function(newValue)
49
-                    {
50
-                        if (newValue == true) {
51
-                            element.removeAttr("disabled");
52
-                        }
53
-                        else {
54
-                            element.attr("disabled", "disabled");
55
-                        }
56
-                    })
57
-                }
58
-            };
59
-        }]);
46
+                        $scope.$watch(function() {
47
+                            return checkPermissions(attrs.luEnablePermission, luticateAuthCache);
48
+                        }, function(newValue)
49
+                        {
50
+                            if (newValue == true) {
51
+                                element.removeAttr("disabled");
52
+                            }
53
+                            else {
54
+                                element.attr("disabled", "disabled");
55
+                            }
56
+                        })
57
+                    }
58
+                };
59
+            }]);
60
+})()

+ 8
- 4
src/lupermissionsedit.js Dosyayı Görüntüle

@@ -3,8 +3,8 @@
3 3
  */
4 4
 
5 5
 angular.module('luticateUtils')
6
-    .directive('luPermissionEdit', ['dialogs', 'luticateDialogErrorHelper', 'luticateAuthPermissions',
7
-        function(dialogs, luticateDialogErrorHelper, luticateAuthPermissions) {
6
+    .directive('luPermissionEdit', ['dialogs', 'luticateDialogErrorHelper', 'luticateAuthPermissions', 'luticateAuthCache',
7
+        function(dialogs, luticateDialogErrorHelper, luticateAuthPermissions, luticateAuthCache) {
8 8
             return {
9 9
                 restrict: 'E',
10 10
                 scope: {
@@ -21,7 +21,6 @@ angular.module('luticateUtils')
21 21
                         Value: true
22 22
                     };
23 23
                     $scope.luModelOptions = $scope.luModel();
24
-                    console.log();
25 24
 
26 25
                     $scope.editPermission = function(permission, value)
27 26
                     {
@@ -103,7 +102,12 @@ angular.module('luticateUtils')
103 102
                             }, luticateDialogErrorHelper.errorDialog);
104 103
                     };
105 104
 
106
-                    $scope.loadAllPermissions();
105
+                    if (luticateAuthCache.hasEffectivePermission('LU_PERM_GET')) {
106
+                        $scope.loadAllPermissions();
107
+                    }
108
+                    else {
109
+                        $scope.loadPermissions();
110
+                    }
107 111
                 }
108 112
             };
109 113
         }]);

Loading…
İptal
Kaydet