Project management bug fixes. Platform Role assignment init
[osm/UI.git] / skyquake / plugins / user_management / src / platformRoleManagement / platformRoleManagementSource.js
1 /*
2 * STANDARD_RIFT_IO_COPYRIGHT
3 */
4 import $ from 'jquery';
5 var Utils = require('utils/utils.js');
6 let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
7 let HOST = API_SERVER;
8 let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
9 let DEV_MODE = require('utils/rw.js').getSearchParams(window.location).dev_mode || false;
10
11 if (DEV_MODE) {
12 HOST = window.location.protocol + '//' + window.location.hostname;
13 }
14
15
16 let Projects = mockProjects();
17 let Users = mockUsers();
18
19
20 module.exports = function(Alt) {
21 return {
22
23 getUsers: {
24 remote: function() {
25 return new Promise(function(resolve, reject) {
26 // setTimeout(function() {
27 // resolve(Users);
28 // }, 1000);
29 $.ajax({
30 url: `/user?api_server=${API_SERVER}`,
31 type: 'GET',
32 beforeSend: Utils.addAuthorizationStub,
33 success: function(data, textStatus, jqXHR) {
34 resolve(data.users);
35 }
36 }).fail(function(xhr){
37 //Authentication and the handling of fail states should be wrapped up into a connection class.
38 Utils.checkAuthentication(xhr.status);
39 });
40 });
41 },
42 interceptResponse: interceptResponse({
43 'error': 'There was an error retrieving the resource orchestrator information.'
44 }),
45 success: Alt.actions.global.getUsersSuccess,
46 loading: Alt.actions.global.showScreenLoader,
47 error: Alt.actions.global.showNotification
48 },
49 getProjects: {
50 remote: function() {
51 return new Promise(function(resolve, reject) {
52 // setTimeout(function() {
53 // resolve(Projects);
54 // }, 1000)
55 $.ajax({
56 url: `/project?api_server=${API_SERVER}`,
57 type: 'GET',
58 beforeSend: Utils.addAuthorizationStub,
59 success: function(data, textStatus, jqXHR) {
60 resolve(data.project);
61 }
62 }).fail(function(xhr){
63 //Authentication and the handling of fail states should be wrapped up into a connection class.
64 Utils.checkAuthentication(xhr.status);
65 });
66 });
67 },
68 interceptResponse: interceptResponse({
69 'error': 'There was an error retrieving the resource orchestrator information.'
70 }),
71 success: Alt.actions.global.getProjectsSuccess,
72 loading: Alt.actions.global.showScreenLoader,
73 error: Alt.actions.global.showNotification
74 },
75 updateProject: {
76 remote: function(state, project) {
77 return new Promise(function(resolve, reject) {
78 $.ajax({
79 url: `/project?api_server=${API_SERVER}`,
80 type: 'PUT',
81 data: project,
82 beforeSend: Utils.addAuthorizationStub,
83 success: function(data, textStatus, jqXHR) {
84 resolve(data);
85 }
86 }).fail(function(xhr){
87 //Authentication and the handling of fail states should be wrapped up into a connection class.
88 Utils.checkAuthentication(xhr.status);
89 });
90 });
91 },
92 interceptResponse: interceptResponse({
93 'error': 'There was an error updating the project.'
94 }),
95 success: Alt.actions.global.updateProjectSuccess,
96 loading: Alt.actions.global.showScreenLoader,
97 error: Alt.actions.global.showNotification
98 },
99 deleteProject: {
100 remote: function(state, project) {
101 return new Promise(function(resolve, reject) {
102 // setTimeout(function() {
103 // resolve(true);
104 // }, 1000)
105 $.ajax({
106 url: `/project/${project['name']}?api_server=${API_SERVER}`,
107 type: 'DELETE',
108 beforeSend: Utils.addAuthorizationStub,
109 success: function(data, textStatus, jqXHR) {
110 resolve(data);
111 }
112 }).fail(function(xhr){
113 //Authentication and the handling of fail states should be wrapped up into a connection class.
114 Utils.checkAuthentication(xhr.status);
115 });
116 });
117 },
118 interceptResponse: interceptResponse({
119 'error': 'There was an error deleting the user.'
120 }),
121 success: Alt.actions.global.deleteProjectSuccess,
122 loading: Alt.actions.global.showScreenLoader,
123 error: Alt.actions.global.showNotification
124 },
125 createProject: {
126 remote: function(state, project) {
127
128 return new Promise(function(resolve, reject) {
129 // setTimeout(function() {
130 // resolve(true);
131 // }, 1000)
132 $.ajax({
133 url: `/project?api_server=${API_SERVER}`,
134 type: 'POST',
135 data: project,
136 beforeSend: Utils.addAuthorizationStub,
137 success: function(data, textStatus, jqXHR) {
138 resolve(data);
139 }
140 }).fail(function(xhr){
141 //Authentication and the handling of fail states should be wrapped up into a connection class.
142 Utils.checkAuthentication(xhr.status);
143 });
144 });
145 },
146 interceptResponse: interceptResponse({
147 'error': 'There was an error updating the account.'
148 }),
149 success: Alt.actions.global.createProjectSuccess,
150 loading: Alt.actions.global.showScreenLoader,
151 error: Alt.actions.global.showNotification
152 }
153 }
154 }
155
156 function interceptResponse (responses) {
157 return function(data, action, args) {
158 if(responses.hasOwnProperty(data)) {
159 return {
160 type: data,
161 msg: responses[data]
162 }
163 } else {
164 return data;
165 }
166 }
167 }
168
169 function mockProjects() {
170 let data = [];
171 let count = 10;
172 for(let i = 0; i < 3; i++) {
173 data.push({
174 name: `Test Project ${i}`,
175 description: 'Some description',
176 roles: ['Some-Role', 'Some-Other-Role'],
177 users: [
178 {
179 'user-name': 'Some-User',
180 'user-domain': 'system',
181 role: [
182 {
183 'role': 'Some-Role',
184 'key-set' : 'some key'
185 },
186 {
187 'role': 'Some-Other-Role',
188 'key-set' : 'some key'
189 }
190 ]
191 },
192 {
193 'user-name': 'Some-User',
194 'user-domain': 'system',
195 role: [
196 {
197 'role': 'Some-Role',
198 'key-set' : 'some key'
199 }
200 ]
201 }
202 ]
203 })
204 }
205 return data;
206 }
207 function mockUsers() {
208 let data = [];
209 let count = 10;
210 for(let i = 0; i < 10; i++) {
211 data.push({
212 'user-name': `Tester ${i}`,
213 'user-domain': 'Some Domain',
214 platformRoles: {
215 super_admin: true,
216 platform_admin: false,
217 platform_oper: false
218 },
219 disabled: false,
220 projectRoles: [
221 'Project:Role'
222 ]
223 })
224 }
225 return data;
226 }