##// END OF EJS Templates
state: move user object into state holder
ergo -
Show More
@@ -2772,7 +2772,9 b' function kickstartAE(initialUserData) {'
2772
2772
2773 app.run(['$rootScope', '$timeout', 'stateHolder', '$state', '$location', '$transitions', '$window', 'AeConfig',
2773 app.run(['$rootScope', '$timeout', 'stateHolder', '$state', '$location', '$transitions', '$window', 'AeConfig',
2774 function ($rootScope, $timeout, stateHolder, $state, $location, $transitions, $window, AeConfig) {
2774 function ($rootScope, $timeout, stateHolder, $state, $location, $transitions, $window, AeConfig) {
2775 stateHolder.AeUser = buildUser(initialUserData || {"user_name": null, "id": null});
2775 if (initialUserData){
2776 stateHolder.AeUser.update(initialUserData);
2777 }
2776 $rootScope.$state = $state;
2778 $rootScope.$state = $state;
2777 $rootScope.stateHolder = stateHolder;
2779 $rootScope.stateHolder = stateHolder;
2778 $rootScope.flash = stateHolder.flashMessages.list;
2780 $rootScope.flash = stateHolder.flashMessages.list;
@@ -12705,6 +12707,73 b" angular.module('appenlight.services.resources').factory('resourcesPropertyResour"
12705 // # https://rhodecode.com/licenses/
12707 // # https://rhodecode.com/licenses/
12706
12708
12707 angular.module('appenlight.services.stateHolder', []).factory('stateHolder', ['$timeout', 'AeConfig', function ($timeout, AeConfig) {
12709 angular.module('appenlight.services.stateHolder', []).factory('stateHolder', ['$timeout', 'AeConfig', function ($timeout, AeConfig) {
12710
12711 var AeUser = {"user_name": null, "id": null};
12712 AeUser.update = function (jsonData) {
12713 jsonData = jsonData || {};
12714 this.applications_map = {};
12715 this.dashboards_map = {};
12716 this.user_name = jsonData.user_name || null;
12717 this.id = jsonData.id;
12718 this.assigned_reports = jsonData.assigned_reports || null;
12719 this.latest_events = jsonData.latest_events || null;
12720 this.permissions = jsonData.permissions || null;
12721 this.groups = jsonData.groups || null;
12722 this.applications = [];
12723 this.dashboards = [];
12724 _.each(jsonData.applications, function (item) {
12725 this.addApplication(item);
12726 }.bind(this));
12727 _.each(jsonData.dashboards, function (item) {
12728 this.addDashboard(item);
12729 }.bind(this));
12730 };
12731 AeUser.addApplication = function (item) {
12732 this.applications.push(item);
12733 this.applications_map[item.resource_id] = item;
12734 };
12735 AeUser.addDashboard = function (item) {
12736 this.dashboards.push(item);
12737 this.dashboards_map[item.resource_id] = item;
12738 };
12739
12740 AeUser.removeApplicationById = function (applicationId) {
12741 this.applications = _.filter(this.applications, function (item) {
12742 return item.resource_id != applicationId;
12743 });
12744 delete this.applications_map[applicationId];
12745 };
12746 AeUser.removeDashboardById = function (dashboardId) {
12747 this.dashboards = _.filter(this.dashboards, function (item) {
12748 return item.resource_id != dashboardId;
12749 });
12750 delete this.dashboards_map[dashboardId];
12751 };
12752
12753 AeUser.hasAppPermission = function (perm_name) {
12754 if (this.permissions.indexOf('root_administration') !== -1) {
12755 return true
12756 }
12757 return this.permissions.indexOf(perm_name) !== -1;
12758 };
12759
12760 AeUser.hasContextPermission = function (permName, ACLList) {
12761 var hasPerm = false;
12762 _.each(ACLList, function (ACL) {
12763 // is this the right perm?
12764 if (ACL.perm_name == permName ||
12765 ACL.perm_name == '__all_permissions__') {
12766 // perm for this user or a group user belongs to
12767 if (ACL.user_name === this.user_name ||
12768 this.groups.indexOf(ACL.group_name) !== -1) {
12769 hasPerm = true
12770 }
12771 }
12772 }.bind(this));
12773
12774 return hasPerm;
12775 };
12776
12708 /**
12777 /**
12709 * Holds some common stuff like flash messages, but important part is
12778 * Holds some common stuff like flash messages, but important part is
12710 * plugins property that is a registry that holds all information about
12779 * plugins property that is a registry that holds all information about
@@ -12766,14 +12835,14 b" angular.module('appenlight.services.stateHolder', []).factory('stateHolder', ['$"
12766 }
12835 }
12767 self.inclusions[name].push(inclusion);
12836 self.inclusions[name].push(inclusion);
12768 }
12837 }
12769 }
12838 };
12770
12839
12771 var stateHolder = {
12840 var stateHolder = {
12772 section: 'settings',
12841 section: 'settings',
12773 resource: null,
12842 resource: null,
12774 plugins: Plugins,
12843 plugins: Plugins,
12775 flashMessages: flashMessages,
12844 flashMessages: flashMessages,
12776 AeUser: {"user_name": null, "id": null}
12845 AeUser: AeUser
12777 };
12846 };
12778 return stateHolder;
12847 return stateHolder;
12779 }]);
12848 }]);
@@ -12892,90 +12961,3 b" var underscore = angular.module('underscore', []);"
12892 underscore.factory('_', function () {
12961 underscore.factory('_', function () {
12893 return window._; // assumes underscore has already been loaded on the page
12962 return window._; // assumes underscore has already been loaded on the page
12894 });
12963 });
12895
12896 ;// # Copyright (C) 2010-2016 RhodeCode GmbH
12897 // #
12898 // # This program is free software: you can redistribute it and/or modify
12899 // # it under the terms of the GNU Affero General Public License, version 3
12900 // # (only), as published by the Free Software Foundation.
12901 // #
12902 // # This program is distributed in the hope that it will be useful,
12903 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
12904 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12905 // # GNU General Public License for more details.
12906 // #
12907 // # You should have received a copy of the GNU Affero General Public License
12908 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
12909 // #
12910 // # This program is dual-licensed. If you wish to learn more about the
12911 // # AppEnlight Enterprise Edition, including its added features, Support
12912 // # services, and proprietary license terms, please see
12913 // # https://rhodecode.com/licenses/
12914
12915 function buildUser(jsonData){
12916 var AeUser = {
12917 user_name: jsonData.user_name || null,
12918 id: jsonData.id,
12919 assigned_reports: jsonData.assigned_reports || null,
12920 latest_events: jsonData.latest_events || null,
12921 permissions: jsonData.permissions || null,
12922 groups: jsonData.groups || null,
12923 applications: [],
12924 dashboards: []
12925 };
12926 AeUser.applications_map = {};
12927 AeUser.dashboards_map = {};
12928 AeUser.addApplication = function (item) {
12929 AeUser.applications.push(item);
12930 AeUser.applications_map[item.resource_id] = item;
12931 };
12932 AeUser.addDashboard = function (item) {
12933 AeUser.dashboards.push(item);
12934 AeUser.dashboards_map[item.resource_id] = item;
12935 };
12936
12937 AeUser.removeApplicationById = function (applicationId) {
12938 AeUser.applications = _.filter(AeUser.applications, function (item) {
12939 return item.resource_id != applicationId;
12940 });
12941 delete AeUser.applications_map[applicationId];
12942 };
12943 AeUser.removeDashboardById = function (dashboardId) {
12944 AeUser.dashboards = _.filter(AeUser.dashboards, function (item) {
12945 return item.resource_id != dashboardId;
12946 });
12947 delete AeUser.dashboards_map[dashboardId];
12948 };
12949
12950 AeUser.hasAppPermission = function (perm_name) {
12951 if (AeUser.permissions.indexOf('root_administration') !== -1) {
12952 return true
12953 }
12954 return AeUser.permissions.indexOf(perm_name) !== -1;
12955 };
12956
12957 AeUser.hasContextPermission = function (permName, ACLList) {
12958 var hasPerm = false;
12959 _.each(ACLList, function (ACL) {
12960 // is this the right perm?
12961 if (ACL.perm_name == permName ||
12962 ACL.perm_name == '__all_permissions__') {
12963 // perm for this user or a group user belongs to
12964 if (ACL.user_name === AeUser.user_name ||
12965 AeUser.groups.indexOf(ACL.group_name) !== -1) {
12966 hasPerm = true
12967 }
12968 }
12969 });
12970
12971 return hasPerm;
12972 };
12973
12974 _.each(jsonData.applications, function (item) {
12975 AeUser.addApplication(item);
12976 });
12977 _.each(jsonData.dashboards, function (item) {
12978 AeUser.addDashboard(item);
12979 });
12980 return AeUser;
12981 }
@@ -137,7 +137,9 b' function kickstartAE(initialUserData) {'
137
137
138 app.run(['$rootScope', '$timeout', 'stateHolder', '$state', '$location', '$transitions', '$window', 'AeConfig',
138 app.run(['$rootScope', '$timeout', 'stateHolder', '$state', '$location', '$transitions', '$window', 'AeConfig',
139 function ($rootScope, $timeout, stateHolder, $state, $location, $transitions, $window, AeConfig) {
139 function ($rootScope, $timeout, stateHolder, $state, $location, $transitions, $window, AeConfig) {
140 stateHolder.AeUser = buildUser(initialUserData || {"user_name": null, "id": null});
140 if (initialUserData){
141 stateHolder.AeUser.update(initialUserData);
142 }
141 $rootScope.$state = $state;
143 $rootScope.$state = $state;
142 $rootScope.stateHolder = stateHolder;
144 $rootScope.stateHolder = stateHolder;
143 $rootScope.flash = stateHolder.flashMessages.list;
145 $rootScope.flash = stateHolder.flashMessages.list;
@@ -18,6 +18,73 b''
18 // # https://rhodecode.com/licenses/
18 // # https://rhodecode.com/licenses/
19
19
20 angular.module('appenlight.services.stateHolder', []).factory('stateHolder', ['$timeout', 'AeConfig', function ($timeout, AeConfig) {
20 angular.module('appenlight.services.stateHolder', []).factory('stateHolder', ['$timeout', 'AeConfig', function ($timeout, AeConfig) {
21
22 var AeUser = {"user_name": null, "id": null};
23 AeUser.update = function (jsonData) {
24 jsonData = jsonData || {};
25 this.applications_map = {};
26 this.dashboards_map = {};
27 this.user_name = jsonData.user_name || null;
28 this.id = jsonData.id;
29 this.assigned_reports = jsonData.assigned_reports || null;
30 this.latest_events = jsonData.latest_events || null;
31 this.permissions = jsonData.permissions || null;
32 this.groups = jsonData.groups || null;
33 this.applications = [];
34 this.dashboards = [];
35 _.each(jsonData.applications, function (item) {
36 this.addApplication(item);
37 }.bind(this));
38 _.each(jsonData.dashboards, function (item) {
39 this.addDashboard(item);
40 }.bind(this));
41 };
42 AeUser.addApplication = function (item) {
43 this.applications.push(item);
44 this.applications_map[item.resource_id] = item;
45 };
46 AeUser.addDashboard = function (item) {
47 this.dashboards.push(item);
48 this.dashboards_map[item.resource_id] = item;
49 };
50
51 AeUser.removeApplicationById = function (applicationId) {
52 this.applications = _.filter(this.applications, function (item) {
53 return item.resource_id != applicationId;
54 });
55 delete this.applications_map[applicationId];
56 };
57 AeUser.removeDashboardById = function (dashboardId) {
58 this.dashboards = _.filter(this.dashboards, function (item) {
59 return item.resource_id != dashboardId;
60 });
61 delete this.dashboards_map[dashboardId];
62 };
63
64 AeUser.hasAppPermission = function (perm_name) {
65 if (this.permissions.indexOf('root_administration') !== -1) {
66 return true
67 }
68 return this.permissions.indexOf(perm_name) !== -1;
69 };
70
71 AeUser.hasContextPermission = function (permName, ACLList) {
72 var hasPerm = false;
73 _.each(ACLList, function (ACL) {
74 // is this the right perm?
75 if (ACL.perm_name == permName ||
76 ACL.perm_name == '__all_permissions__') {
77 // perm for this user or a group user belongs to
78 if (ACL.user_name === this.user_name ||
79 this.groups.indexOf(ACL.group_name) !== -1) {
80 hasPerm = true
81 }
82 }
83 }.bind(this));
84 console.log('AeUser.hasContextPermission', permName, hasPerm);
85 return hasPerm;
86 };
87
21 /**
88 /**
22 * Holds some common stuff like flash messages, but important part is
89 * Holds some common stuff like flash messages, but important part is
23 * plugins property that is a registry that holds all information about
90 * plugins property that is a registry that holds all information about
@@ -79,14 +146,14 b" angular.module('appenlight.services.stateHolder', []).factory('stateHolder', ['$"
79 }
146 }
80 self.inclusions[name].push(inclusion);
147 self.inclusions[name].push(inclusion);
81 }
148 }
82 }
149 };
83
150
84 var stateHolder = {
151 var stateHolder = {
85 section: 'settings',
152 section: 'settings',
86 resource: null,
153 resource: null,
87 plugins: Plugins,
154 plugins: Plugins,
88 flashMessages: flashMessages,
155 flashMessages: flashMessages,
89 AeUser: {"user_name": null, "id": null}
156 AeUser: AeUser
90 };
157 };
91 return stateHolder;
158 return stateHolder;
92 }]);
159 }]);
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now