conjur-asset-ui 1.4.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -3
  3. data/CHANGELOG.md +10 -0
  4. data/Makefile +19 -0
  5. data/README.md +0 -3
  6. data/Rakefile +22 -17
  7. data/TODO.md +0 -23
  8. data/app/.csscomb.json +304 -0
  9. data/app/.eslintignore +3 -0
  10. data/app/.eslintrc +265 -0
  11. data/app/config/preprocessor.js +19 -0
  12. data/app/config/webpack.js +124 -0
  13. data/app/gulpfile.js +96 -0
  14. data/app/package.json +86 -0
  15. data/app/src/actions.js +550 -0
  16. data/app/src/app.js +83 -0
  17. data/app/src/clients/audit.js +34 -0
  18. data/app/src/clients/auth.js +24 -0
  19. data/app/src/clients/generic.js +52 -0
  20. data/app/src/clients/graph.js +7 -0
  21. data/app/src/clients/layer_members.js +18 -0
  22. data/app/src/clients/list.js +31 -0
  23. data/app/src/clients/members.js +20 -0
  24. data/app/src/clients/request.js +531 -0
  25. data/app/src/clients/search.js +5 -0
  26. data/app/src/components/app/__tests__/app-test.js +22 -0
  27. data/app/src/components/app/app.js +36 -0
  28. data/app/src/components/app/wrapper.js +17 -0
  29. data/app/src/components/audit/__tests__/table_header-test.js +22 -0
  30. data/app/src/components/audit/box.js +9 -0
  31. data/app/src/components/audit/constants.js +5 -0
  32. data/app/src/components/audit/entry.js +105 -0
  33. data/app/src/components/audit/fields_mixin.js +11 -0
  34. data/app/src/components/audit/humanize_event.js +213 -0
  35. data/app/src/components/audit/table.js +64 -0
  36. data/app/src/components/audit/table_header.js +37 -0
  37. data/app/src/components/audit/timestamp.js +28 -0
  38. data/app/src/components/auth/login.js +177 -0
  39. data/app/src/components/auth/login.less +71 -0
  40. data/app/src/components/auth/logout.js +42 -0
  41. data/app/src/components/auth/logout.less +21 -0
  42. data/app/src/components/chart/chart.js +540 -0
  43. data/app/src/components/chart/chart_helper_mixin.js +78 -0
  44. data/app/src/components/custom/list.js +3 -0
  45. data/app/src/components/custom/view.js +81 -0
  46. data/app/src/components/dashboard/activity.js +144 -0
  47. data/app/src/components/dashboard/dashboard.js +46 -0
  48. data/app/src/components/flash/flash.js +98 -0
  49. data/app/src/components/flash/flash.less +3 -0
  50. data/app/src/components/generic/__tests__/time-test.js +42 -0
  51. data/app/src/components/generic/annotations.js +39 -0
  52. data/app/src/components/generic/breadcrumbs.js +57 -0
  53. data/app/src/components/generic/foldable_audit_section.js +204 -0
  54. data/app/src/components/generic/list.js +141 -0
  55. data/app/src/components/generic/list_factory.js +41 -0
  56. data/app/src/components/generic/resource_link.js +64 -0
  57. data/app/src/components/generic/role_link.js +66 -0
  58. data/app/src/components/generic/tab_mixin.js +146 -0
  59. data/app/src/components/generic/time.js +32 -0
  60. data/app/src/components/graph/__tests__/collapse-test.js +133 -0
  61. data/app/src/components/graph/__tests__/edges-from-vertices-test.js +48 -0
  62. data/app/src/components/graph/__tests__/new-vertex-set-test.js +16 -0
  63. data/app/src/components/graph/__tests__/next-id-test.js +27 -0
  64. data/app/src/components/graph/__tests__/role-kind-from-id-test.js +24 -0
  65. data/app/src/components/graph/__tests__/vertices-from-edges-test.js +72 -0
  66. data/app/src/components/graph/graph.js +449 -0
  67. data/app/src/components/graph/graph.less +39 -0
  68. data/app/src/components/graph/helpers.js +368 -0
  69. data/app/src/components/group/list.js +3 -0
  70. data/app/src/components/group/view.js +153 -0
  71. data/app/src/components/host/activity.js +111 -0
  72. data/app/src/components/host/details.js +28 -0
  73. data/app/src/components/host/executors.js +77 -0
  74. data/app/src/components/host/host_link.js +18 -0
  75. data/app/src/components/host/list.js +3 -0
  76. data/app/src/components/host/updaters.js +77 -0
  77. data/app/src/components/host/view.js +145 -0
  78. data/app/src/components/layer/list.js +3 -0
  79. data/app/src/components/layer/view.js +197 -0
  80. data/app/src/components/navbar/__tests__/navbar-test.js +21 -0
  81. data/app/src/components/navbar/nav_search_form.js +40 -0
  82. data/app/src/components/navbar/navbar.js +96 -0
  83. data/app/src/components/notfound/notfound.js +35 -0
  84. data/app/src/components/notfound/notfound.less +21 -0
  85. data/app/src/components/owned_resources/owned_resources.js +84 -0
  86. data/app/src/components/owned_resources/owned_resources_box.js +101 -0
  87. data/app/src/components/permissions/permissions.js +138 -0
  88. data/app/src/components/permissions/permissions_table.js +101 -0
  89. data/app/src/components/policy/list.js +3 -0
  90. data/app/src/components/policy/view.js +107 -0
  91. data/app/src/components/refresh/refresh.js +29 -0
  92. data/app/src/components/refresh/refresh.less +15 -0
  93. data/app/src/components/search/group.js +43 -0
  94. data/app/src/components/search/group_heading.js +50 -0
  95. data/app/src/components/search/group_title.js +37 -0
  96. data/app/src/components/search/result_item.js +55 -0
  97. data/app/src/components/search/search.js +118 -0
  98. data/app/src/components/user/activity.js +112 -0
  99. data/app/src/components/user/details.js +30 -0
  100. data/app/src/components/user/list.js +3 -0
  101. data/app/src/components/user/pubkeys.js +118 -0
  102. data/app/src/components/user/pubkeys.less +56 -0
  103. data/app/src/components/user/view.js +143 -0
  104. data/app/src/components/variable/activity.js +101 -0
  105. data/app/src/components/variable/details.js +46 -0
  106. data/app/src/components/variable/fetchers.js +77 -0
  107. data/app/src/components/variable/list.js +3 -0
  108. data/app/src/components/variable/updaters.js +77 -0
  109. data/app/src/components/variable/view.js +115 -0
  110. data/app/src/constants.js +36 -0
  111. data/{public → app/src}/images/conjur-logo.svg +0 -0
  112. data/{public → app/src}/images/icon-client-pc.svg +0 -0
  113. data/{public → app/src}/images/icon-environment.png +0 -0
  114. data/{public → app/src}/images/icon-person.svg +0 -0
  115. data/{public → app/src}/images/icon-policy.png +0 -0
  116. data/{public → app/src}/images/icon-resource.png +0 -0
  117. data/{public → app/src}/images/icon-service-dots.svg +0 -0
  118. data/{public → app/src}/images/icon-variable.png +0 -0
  119. data/app/src/pages/index.html +27 -0
  120. data/app/src/routes.js +64 -0
  121. data/app/src/stores/app_store.js +35 -0
  122. data/app/src/stores/audit_store.js +143 -0
  123. data/app/src/stores/graph_store.js +51 -0
  124. data/app/src/stores/group_store.js +104 -0
  125. data/app/src/stores/host_store.js +111 -0
  126. data/app/src/stores/layer_store.js +115 -0
  127. data/app/src/stores/policy_store.js +88 -0
  128. data/app/src/stores/resources_store.js +115 -0
  129. data/app/src/stores/route_store.js +21 -0
  130. data/app/src/stores/search_store.js +77 -0
  131. data/app/src/stores/user_store.js +109 -0
  132. data/app/src/stores/variable_store.js +93 -0
  133. data/app/src/styles/bootstrap.less +54 -0
  134. data/{public/css → app/src/styles}/styles.less +26 -82
  135. data/app/src/utils.js +38 -0
  136. data/app/src/vendor/pace.js +2 -0
  137. data/conjur-asset-ui.gemspec +3 -4
  138. data/docker/assets-build/Dockerfile +12 -0
  139. data/docker/conjur-ui/Dockerfile +33 -0
  140. data/docker/conjur-ui/README.md +38 -0
  141. data/docker/conjur-ui/mime.types +90 -0
  142. data/docker/conjur-ui/nginx.conf +110 -0
  143. data/docker/conjur-ui/start.py +72 -0
  144. data/docker/conjur-ui/start.sh +18 -0
  145. data/docker/conjur-ui/test.env +8 -0
  146. data/lib/conjur-asset-ui-version.rb +1 -1
  147. data/lib/conjur/command/ui.rb +10 -2
  148. data/lib/conjur/webserver/home.rb +3 -3
  149. data/lib/conjur/webserver/login.rb +1 -1
  150. data/lib/conjur/webserver/server.rb +16 -4
  151. data/public/js/views/roleGraph.js +91 -0
  152. metadata +167 -105
  153. data/.jshintrc +0 -41
  154. data/bower.json +0 -98
  155. data/gulpfile.js +0 -139
  156. data/package.json +0 -47
  157. data/preprocessor.js +0 -7
  158. data/public/_client_libs.html +0 -9
  159. data/public/index.html.erb +0 -63
  160. data/public/js/init.js +0 -196
  161. data/public/js/lib/pace.js +0 -2
  162. data/public/js/lib/sorted-set.no-require.js +0 -1145
  163. data/public/js/lib/sorted-set.no-require.js.txt +0 -6
  164. data/public/js/models/groupRecord.js +0 -72
  165. data/public/js/models/hostRecord.js +0 -60
  166. data/public/js/models/layerRecord.js +0 -79
  167. data/public/js/models/namespace.js +0 -12
  168. data/public/js/models/policyList.js +0 -16
  169. data/public/js/models/policyRecord.js +0 -54
  170. data/public/js/models/record.js +0 -117
  171. data/public/js/models/resourceList.js +0 -87
  172. data/public/js/models/userList.js +0 -25
  173. data/public/js/models/userRecord.js +0 -75
  174. data/public/js/models/variableList.js +0 -27
  175. data/public/js/models/variableRecord.js +0 -77
  176. data/public/js/routers.js +0 -242
  177. data/public/js/views/annotations.js +0 -47
  178. data/public/js/views/audit.js +0 -369
  179. data/public/js/views/breadcrumbs.js +0 -62
  180. data/public/js/views/chart.js +0 -617
  181. data/public/js/views/dashboard.js +0 -146
  182. data/public/js/views/generic.js +0 -122
  183. data/public/js/views/group.js +0 -109
  184. data/public/js/views/groups.js +0 -26
  185. data/public/js/views/host.js +0 -200
  186. data/public/js/views/hosts.js +0 -26
  187. data/public/js/views/layer.js +0 -146
  188. data/public/js/views/layers.js +0 -26
  189. data/public/js/views/mixins/search.js +0 -22
  190. data/public/js/views/mixins/tabs.js +0 -154
  191. data/public/js/views/namespaces.js +0 -40
  192. data/public/js/views/navSearch.js +0 -36
  193. data/public/js/views/owned.js +0 -184
  194. data/public/js/views/permissions.js +0 -254
  195. data/public/js/views/policies.js +0 -26
  196. data/public/js/views/policy.js +0 -70
  197. data/public/js/views/resource.js +0 -59
  198. data/public/js/views/role.js +0 -63
  199. data/public/js/views/searchResults.js +0 -212
  200. data/public/js/views/sections.js +0 -226
  201. data/public/js/views/time.js +0 -39
  202. data/public/js/views/user.js +0 -297
  203. data/public/js/views/users.js +0 -26
  204. data/public/js/views/variable.js +0 -310
  205. data/public/js/views/variables.js +0 -26
  206. data/spec/javascripts/helpers/.gitkeep +0 -0
  207. data/spec/javascripts/support/jasmine.yml +0 -112
  208. data/spec/javascripts/support/jasmine_helper.rb +0 -22
  209. data/spec/javascripts/support/run.html.erb +0 -23
  210. data/spec/javascripts/views/AuditSpec.js +0 -22
  211. data/spec/javascripts/views/AuditSpec.ls +0 -18
@@ -0,0 +1,35 @@
1
+ import {createStore} from 'fluxxor';
2
+ import _ from 'lodash';
3
+ import constants from '../constants';
4
+
5
+ export default createStore({
6
+ initialize() {
7
+ this.flashMsgs = [];
8
+
9
+ this.bindActions(
10
+ constants.FLASH_MESSAGE, this.onFlashMessage,
11
+ constants.FLASH_MESSAGE_CLEAR, this.onFlashMessageClear
12
+ );
13
+ },
14
+
15
+ onFlashMessage(payload) {
16
+ this.flashMsgs.push({
17
+ msg: payload.msg,
18
+ status: payload.status
19
+ });
20
+
21
+ this.emit('change');
22
+ },
23
+
24
+ onFlashMessageClear() {
25
+ this.flashMsgs = [];
26
+
27
+ this.emit('change');
28
+ },
29
+
30
+ getState() {
31
+ return {
32
+ flashMsgs: _.clone(this.flashMsgs, true)
33
+ };
34
+ }
35
+ });
@@ -0,0 +1,143 @@
1
+ import Fluxxor from 'fluxxor';
2
+ import SortedSet from 'collections/sorted-set';
3
+ import _ from 'lodash';
4
+
5
+ import constants from '../components/audit/constants';
6
+ import c from '../constants';
7
+
8
+ /**
9
+ * AuditStore stores audit events
10
+ *
11
+ * Use SortedSet as internal data structure.
12
+ */
13
+ module.exports = Fluxxor.createStore({
14
+ initialize() {
15
+ this.loading = 0;
16
+ this.events = new SortedSet([], function(a, b) {
17
+ return b.id === a.id;
18
+ }, function(a, b) {
19
+ if (a.id < b.id) {
20
+ return -1;
21
+ }
22
+
23
+ if (a.id > b.id) {
24
+ return 1;
25
+ }
26
+
27
+ return 0;
28
+ });
29
+
30
+ this.bindActions(
31
+ c.AUDIT.LOAD, this._onLoad,
32
+ c.AUDIT.LOAD_SUCCESS, this._onLoadSuccess,
33
+ c.AUDIT.LOAD_FAIL, this._onLoadFail
34
+ );
35
+ },
36
+
37
+ _incLoading() {
38
+ this.loading = this.loading + 1;
39
+ },
40
+
41
+ _decLoading() {
42
+ this.loading = this.loading - 1 < 0 ? 0 : this.loading - 1;
43
+ },
44
+
45
+ _isLoading() {
46
+ return Boolean(this.loading);
47
+ },
48
+
49
+ _filterEvent(e) {
50
+ // remove internal resources creation
51
+ if (_.isString(e.role) && (e.role.split(':')[1] === '@')) {
52
+ return false;
53
+ }
54
+
55
+ if (_.isString(e.resource) && (e.resource.split(':')[1] === '@')) {
56
+ return false;
57
+ }
58
+
59
+ if (_.isString(e.resource) && (e.resource.split(':')[1] === 'secret')) {
60
+ return false;
61
+ }
62
+
63
+ if (_.isString(e.grantee) && (e.grantee.split(':')[1] === '@')) {
64
+ return false;
65
+ }
66
+
67
+ // hide automated creation of roles corresponding to resources of known type
68
+ if ((e.kind === 'role') && (e.action === 'create')) {
69
+ var roleKind = e.role.split(':')[1];
70
+
71
+ if (_.includes(constants.knownRolsourceTypes, roleKind)) {
72
+ return false;
73
+ }
74
+ }
75
+
76
+ // hide new event `role:index` / `all_roles`, which is used by role graph only
77
+ if ((e.kind === 'role') && (e.action === 'index')) {
78
+ return false;
79
+ }
80
+
81
+ if ((e.kind === 'role') && (e.action === 'all_roles')) {
82
+ return false;
83
+ }
84
+
85
+ return true;
86
+ },
87
+
88
+ _onLoad() {
89
+ this._incLoading();
90
+ this.emit('change');
91
+ },
92
+
93
+ _onLoadSuccess(payload) {
94
+ if (_.isObject(payload.event)) {
95
+ this.events.addEach(_.filter([payload.event], this._filterEvent));
96
+ this.emit('change');
97
+ } else if (_.isArray(payload.res.body)) {
98
+ this._decLoading();
99
+ this.events.addEach(_.filter(payload.res.body, this._filterEvent));
100
+ this.emit('change');
101
+ }
102
+
103
+ if (payload.startFlow === true) {
104
+ this.flux.actions.audit.loadFlow(this.events.findGreatest().value.id);
105
+ }
106
+ },
107
+
108
+ _onLoadFail() {
109
+ this._decLoading();
110
+ this.emit('change');
111
+ },
112
+
113
+ /**
114
+ * Return all exist events in store
115
+ */
116
+ getAllEvents() {
117
+ return {
118
+ loading: Boolean(this.loading),
119
+ data: this.events.toArray()
120
+ };
121
+ },
122
+
123
+ getEventFor(kind, id) {
124
+ var fullId = window.decodeURIComponent(this.flux.actions.getFullId(kind, id));
125
+
126
+ return {
127
+ loading: this._isLoading(),
128
+ data: this.events.filter(function(event) {
129
+
130
+ var resourceId = event.resource;
131
+ if ((!event.resource) && (event.resources)) {
132
+ resourceId = event.resources[0];
133
+ }
134
+ var roleId = event.role;
135
+ if ((!event.role) && (event.roles)) {
136
+ roleId = event.roles[0];
137
+ }
138
+
139
+ return roleId === fullId || resourceId === fullId;
140
+ }).toArray()
141
+ };
142
+ }
143
+ });
@@ -0,0 +1,51 @@
1
+ import {createStore} from 'fluxxor';
2
+ import c from '../constants';
3
+
4
+ export default createStore({
5
+ initialize() {
6
+ this.error = false;
7
+ this.loading = false;
8
+ this.graphs = {};
9
+
10
+ this.bindActions(
11
+ c.GRAPH.LOAD, this.onLoad,
12
+ c.GRAPH.LOAD_SUCCESS, this.onLoadSuccess,
13
+ c.GRAPH.LOAD_FAIL, this.onLoadFail
14
+ );
15
+ },
16
+
17
+ onLoad() {
18
+ this.error = false;
19
+ this.loading = true;
20
+ this.emit('change');
21
+ },
22
+
23
+ onLoadSuccess(payload) {
24
+ this.error = false;
25
+ this.loading = false;
26
+
27
+ if (typeof this.graphs[payload.kind] !== 'object') {
28
+ this.graphs[payload.kind] = {};
29
+ }
30
+
31
+ if (typeof this.graphs[payload.kind][payload.id] !== 'object') {
32
+ this.graphs[payload.kind][payload.id] = payload.res.body.graph;
33
+ }
34
+
35
+ this.emit('change');
36
+ },
37
+
38
+ onLoadFail() {
39
+ this.error = true;
40
+ this.loading = false;
41
+ this.emit('change');
42
+ },
43
+
44
+ getGraph(kind, id) {
45
+ return {
46
+ loading: this.loading,
47
+ error: this.error,
48
+ data: (this.graphs[kind] || {})[id] || []
49
+ };
50
+ }
51
+ });
@@ -0,0 +1,104 @@
1
+ import {createStore} from 'fluxxor';
2
+ import {c as generic} from '../clients/generic';
3
+ import {GROUP as constants} from '../constants';
4
+
5
+ var fieldMapping = {
6
+ ATTRIBUTES: 'group',
7
+ OWNED_RESOURCES: 'owned',
8
+ ALL_ROLES: 'roles',
9
+ GROUP_ROLES: 'members',
10
+ RESOURCES: 'resources'
11
+ };
12
+
13
+ export default createStore({
14
+ initialize() {
15
+ this.data = this._fresh();
16
+
17
+ this.bindActions(
18
+ constants.LOAD, this.onLoad,
19
+ constants.LOAD_SUCCESS, this.onLoadSuccess,
20
+ constants.LOAD_FAIL, this.onLoadFail
21
+ );
22
+ },
23
+
24
+ _fresh() {
25
+ return {
26
+ group: {
27
+ id: ''
28
+ },
29
+ loading: {
30
+ group: true,
31
+ owned: true,
32
+ roles: true,
33
+ members: true,
34
+ resources: true
35
+ }
36
+ };
37
+ },
38
+
39
+ onLoad(payload) {
40
+ if (typeof payload.type === 'undefined') {
41
+ this.data = this._fresh();
42
+ this.data.identifier = payload.id;
43
+ this.emit('change');
44
+ } else if (payload.id === this.data.identifier) {
45
+ this.turn(payload.type, true);
46
+ this.emit('change');
47
+ }
48
+ },
49
+
50
+ onLoadSuccess(payload) {
51
+ if (payload.id === this.data.identifier) {
52
+ this.turn(payload.type, false);
53
+
54
+ this.setData(payload);
55
+ this.emit('change');
56
+ }
57
+ },
58
+
59
+ onLoadFail(payload) {
60
+ this.turn(payload.type, false);
61
+ },
62
+
63
+ turn(type, state) {
64
+ var fields = fieldMapping[type];
65
+
66
+ if (typeof fields === 'object') {
67
+ fields.forEach((field) => {
68
+ this.data.loading[field] = state;
69
+ });
70
+ } else {
71
+ this.data.loading[fields] = state;
72
+ }
73
+ },
74
+
75
+ setData(payload) {
76
+ switch (payload.type) {
77
+ case generic.ATTRIBUTES:
78
+ this.data.group = payload.res.body;
79
+ break;
80
+
81
+ case generic.OWNED_RESOURCES:
82
+ this.data.owned = payload.res.body;
83
+ break;
84
+
85
+ case generic.ALL_ROLES:
86
+ this.data.roles = payload.res.body;
87
+ break;
88
+
89
+ case 'GROUP_ROLES':
90
+ this.data.members = payload.res.body;
91
+ break;
92
+
93
+ case 'RESOURCES':
94
+ this.data.resources = payload.res.body;
95
+ break;
96
+
97
+ default:
98
+ }
99
+ },
100
+
101
+ getData() {
102
+ return this.data;
103
+ }
104
+ });
@@ -0,0 +1,111 @@
1
+ import {createStore} from 'fluxxor';
2
+ import {c as generic} from '../clients/generic';
3
+ import {c as members} from '../clients/members';
4
+ import {HOST as constants} from '../constants';
5
+
6
+ var fieldMapping = {
7
+ ATTRIBUTES: 'host',
8
+ OWNED_RESOURCES: 'owned',
9
+ ALL_ROLES: 'roles',
10
+ RESOURCES: 'resources',
11
+ MEMBERS_EXECUTE: 'executors',
12
+ MEMBERS_UPDATE: 'updaters'
13
+ };
14
+
15
+ export default createStore({
16
+ initialize() {
17
+ this.data = this._fresh();
18
+
19
+ this.bindActions(
20
+ constants.LOAD, this.onLoad,
21
+ constants.LOAD_SUCCESS, this.onLoadSuccess,
22
+ constants.LOAD_FAIL, this.onLoadFail
23
+ );
24
+ },
25
+
26
+ _fresh() {
27
+ return {
28
+ host: {},
29
+ loading: {
30
+ host: true,
31
+ owned: true,
32
+ roles: true,
33
+ resources: true
34
+ }
35
+ };
36
+ },
37
+
38
+ onLoad(payload) {
39
+ if (typeof payload.type === 'undefined') {
40
+ this.data = this._fresh();
41
+ this.data.identifier = payload.id;
42
+ this.emit('change');
43
+ } else if (payload.id === this.data.identifier) {
44
+ this.turn(payload.type, true);
45
+ this.emit('change');
46
+ }
47
+ },
48
+
49
+ onLoadSuccess(payload) {
50
+ if (payload.id === this.data.identifier) {
51
+ this.turn(payload.type, false);
52
+
53
+ this.setData(payload);
54
+ this.emit('change');
55
+ }
56
+ },
57
+
58
+ onLoadFail(payload) {
59
+ this.turn(payload.type, false);
60
+ },
61
+
62
+ turn(type, state) {
63
+ var fields = fieldMapping[type];
64
+
65
+ if (typeof fields === 'object') {
66
+ fields.forEach((field) => {
67
+ this.data.loading[field] = state;
68
+ });
69
+ } else {
70
+ this.data.loading[fields] = state;
71
+ }
72
+ },
73
+
74
+ notInternalRole(item) {
75
+ return item.split(':')[1] !== '@';
76
+ },
77
+
78
+ setData(payload) {
79
+ switch (payload.type) {
80
+ case generic.ATTRIBUTES:
81
+ this.data.host = payload.res.body;
82
+ break;
83
+
84
+ case generic.OWNED_RESOURCES:
85
+ this.data.owned = payload.res.body;
86
+ break;
87
+
88
+ case generic.ALL_ROLES:
89
+ this.data.roles = payload.res.body;
90
+ break;
91
+
92
+ case members.MEMBERS_EXECUTE:
93
+ this.data.executors = payload.res.body.filter(this.notInternalRole);
94
+ break;
95
+
96
+ case members.MEMBERS_UPDATE:
97
+ this.data.updaters = payload.res.body.filter(this.notInternalRole);
98
+ break;
99
+
100
+ case 'RESOURCES':
101
+ this.data.resources = payload.res.body;
102
+ break;
103
+
104
+ default:
105
+ }
106
+ },
107
+
108
+ getData() {
109
+ return this.data;
110
+ }
111
+ });
@@ -0,0 +1,115 @@
1
+ import {createStore} from 'fluxxor';
2
+ import {pluck} from 'lodash';
3
+
4
+ import {c as generic} from '../clients/generic';
5
+ import {c as layerMembers} from '../clients/layer_members';
6
+ import {LAYER as constants} from '../constants';
7
+
8
+ var fieldMapping = {
9
+ ATTRIBUTES: 'layer',
10
+ OWNED_RESOURCES: 'owned',
11
+ ALL_ROLES: 'roles',
12
+ LAYER_MEMBERS_USE: 'users',
13
+ LAYER_MEMBERS_ADMIN: 'admins',
14
+ RESOURCES: 'resources'
15
+ };
16
+
17
+ export default createStore({
18
+ initialize() {
19
+ this.data = this._fresh();
20
+
21
+ this.bindActions(
22
+ constants.LOAD, this.onLoad,
23
+ constants.LOAD_SUCCESS, this.onLoadSuccess,
24
+ constants.LOAD_FAIL, this.onLoadFail
25
+ );
26
+ },
27
+
28
+ _fresh() {
29
+ return {
30
+ layer: {
31
+ hosts: []
32
+ },
33
+ admins: [],
34
+ users: [],
35
+ loading: {
36
+ layer: true,
37
+ owned: true,
38
+ roles: true,
39
+ users: true,
40
+ admins: true,
41
+ resources: true
42
+ }
43
+ };
44
+ },
45
+
46
+ onLoad(payload) {
47
+ if (typeof payload.type === 'undefined') {
48
+ this.data = this._fresh();
49
+ this.data.identifier = payload.id;
50
+ this.emit('change');
51
+ } else if (payload.id === this.data.identifier) {
52
+ this.turn(payload.type, true);
53
+ this.emit('change');
54
+ }
55
+ },
56
+
57
+ onLoadSuccess(payload) {
58
+ if (payload.id === this.data.identifier) {
59
+ this.turn(payload.type, false);
60
+
61
+ this.setData(payload);
62
+ this.emit('change');
63
+ }
64
+ },
65
+
66
+ onLoadFail(payload) {
67
+ this.turn(payload.type, false);
68
+ },
69
+
70
+ turn(type, state) {
71
+ var fields = fieldMapping[type];
72
+
73
+ if (typeof fields === 'object') {
74
+ fields.forEach((field) => {
75
+ this.data.loading[field] = state;
76
+ });
77
+ } else {
78
+ this.data.loading[fields] = state;
79
+ }
80
+ },
81
+
82
+ setData(payload) {
83
+ switch (payload.type) {
84
+ case generic.ATTRIBUTES:
85
+ this.data.layer = payload.res.body;
86
+ break;
87
+
88
+ case generic.OWNED_RESOURCES:
89
+ this.data.owned = payload.res.body;
90
+ break;
91
+
92
+ case generic.ALL_ROLES:
93
+ this.data.roles = payload.res.body;
94
+ break;
95
+
96
+ case layerMembers.LAYER_MEMBERS_USE:
97
+ this.data.users = pluck(payload.res.body, 'member');
98
+ break;
99
+
100
+ case layerMembers.LAYER_MEMBERS_ADMIN:
101
+ this.data.admins = pluck(payload.res.body, 'member');
102
+ break;
103
+
104
+ case 'RESOURCES':
105
+ this.data.resources = payload.res.body;
106
+ break;
107
+
108
+ default:
109
+ }
110
+ },
111
+
112
+ getData() {
113
+ return this.data;
114
+ }
115
+ });