User Management: Change password initial support for user admin
[osm/UI.git] / skyquake / plugins / user-management / src / dashboard / userMgmtSource.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 Users = mockUsers();
17
18
19 module.exports = function(Alt) {
20 return {
21 getUsers: {
22 remote: function() {
23 return new Promise(function(resolve, reject) {
24 // setTimeout(function() {
25 // resolve(Users);
26 // }, 1000)
27 $.ajax({
28 url: `/user?api_server=${API_SERVER}`,
29 type: 'GET',
30 beforeSend: Utils.addAuthorizationStub,
31 success: function(data, textStatus, jqXHR) {
32 resolve(data.users);
33 }
34 }).fail(function(xhr){
35 //Authentication and the handling of fail states should be wrapped up into a connection class.
36 Utils.checkAuthentication(xhr.status);
37 });
38 });
39 },
40 interceptResponse: interceptResponse({
41 'error': 'There was an error retrieving the resource orchestrator information.'
42 }),
43 success: Alt.actions.global.getUsersSuccess,
44 loading: Alt.actions.global.showScreenLoader,
45 error: Alt.actions.global.showNotification
46 },
47 updateUser: {
48 remote: function(state, user) {
49 return new Promise(function(resolve, reject) {
50 $.ajax({
51 url: `/user?api_server=${API_SERVER}`,
52 type: 'PUT',
53 data: user,
54 beforeSend: Utils.addAuthorizationStub,
55 success: function(data, textStatus, jqXHR) {
56 resolve(data);
57 }
58 }).fail(function(xhr){
59 //Authentication and the handling of fail states should be wrapped up into a connection class.
60 Utils.checkAuthentication(xhr.status);
61 });
62 });
63 },
64 interceptResponse: interceptResponse({
65 'error': 'There was an error updating the user.'
66 }),
67 success: Alt.actions.global.updateUserSuccess,
68 loading: Alt.actions.global.showScreenLoader,
69 error: Alt.actions.global.showNotification
70 },
71 deleteUser: {
72 remote: function(state, user) {
73 return new Promise(function(resolve, reject) {
74 // setTimeout(function() {
75 // resolve(true);
76 // }, 1000)
77 $.ajax({
78 url: `/user/${user['user-name']}/${user['user-domain']}?api_server=${API_SERVER}`,
79 type: 'DELETE',
80 data: user,
81 beforeSend: Utils.addAuthorizationStub,
82 success: function(data, textStatus, jqXHR) {
83 resolve(data);
84 }
85 }).fail(function(xhr){
86 //Authentication and the handling of fail states should be wrapped up into a connection class.
87 Utils.checkAuthentication(xhr.status);
88 });
89 });
90 },
91 interceptResponse: interceptResponse({
92 'error': 'There was an error deleting the user.'
93 }),
94 success: Alt.actions.global.deleteUserSuccess,
95 loading: Alt.actions.global.showScreenLoader,
96 error: Alt.actions.global.showNotification
97 },
98 createUser: {
99 remote: function(state, user) {
100
101 return new Promise(function(resolve, reject) {
102 // setTimeout(function() {
103 // resolve(true);
104 // }, 1000)
105 $.ajax({
106 url: `/user?api_server=${API_SERVER}`,
107 type: 'POST',
108 data: user,
109 beforeSend: Utils.addAuthorizationStub,
110 success: function(data, textStatus, jqXHR) {
111 resolve(data);
112 }
113 }).fail(function(xhr){
114 //Authentication and the handling of fail states should be wrapped up into a connection class.
115 Utils.checkAuthentication(xhr.status);
116 });
117 });
118 },
119 interceptResponse: interceptResponse({
120 'error': 'There was an error updating the account.'
121 }),
122 success: Alt.actions.global.createUserSuccess,
123 loading: Alt.actions.global.showScreenLoader,
124 error: Alt.actions.global.showNotification
125 }
126 }
127 }
128
129 function interceptResponse (responses) {
130 return function(data, action, args) {
131 if(responses.hasOwnProperty(data)) {
132 return {
133 type: data,
134 msg: responses[data]
135 }
136 } else {
137 return data;
138 }
139 }
140 }
141
142 function mockUsers() {
143 let data = [];
144 let count = 10;
145 for(let i = 0; i < 10; i++) {
146 data.push({
147 username: `Tester ${i}`,
148 domain: 'Some Domain',
149 platformRoles: {
150 super_admin: true,
151 platform_admin: false,
152 platform_oper: false
153 },
154 disabled: false,
155 projectRoles: [
156 'Project:Role'
157 ]
158 })
159 }
160 return data;
161 }