PlatformRoleManagement: removing current user from payload, as user can not edit...
[osm/UI.git] / skyquake / plugins / user_management / src / platformRoleManagement / platformRoleManagementSource.js
index 2024622..0a0d4c3 100644 (file)
@@ -13,9 +13,6 @@ if (DEV_MODE) {
 }
 
 
-let Projects = mockProjects();
-let Users = mockUsers();
-
 
 module.exports = function(Alt) {
     return {
@@ -23,19 +20,21 @@ module.exports = function(Alt) {
         getUsers: {
           remote: function() {
               return new Promise(function(resolve, reject) {
-                // setTimeout(function() {
-                //   resolve(Users);
-                // }, 1000);
                 $.ajax({
                   url: `/user?api_server=${API_SERVER}`,
                   type: 'GET',
                   beforeSend: Utils.addAuthorizationStub,
                   success: function(data, textStatus, jqXHR) {
-                    resolve(data.users);
+                    resolve(data.user);
                   }
                 }).fail(function(xhr){
                   //Authentication and the handling of fail states should be wrapped up into a connection class.
                   Utils.checkAuthentication(xhr.status);
+                  let msg = xhr.responseText;
+                  if(xhr.errorMessage) {
+                    msg = xhr.errorMessage
+                  }
+                  reject(msg);
                 });
               });
           },
@@ -49,9 +48,6 @@ module.exports = function(Alt) {
         getPlatform: {
           remote: function() {
               return new Promise(function(resolve, reject) {
-                // setTimeout(function() {
-                //   resolve(Projects);
-                // }, 1000)
                 $.ajax({
                   url: `/platform?api_server=${API_SERVER}`,
                   type: 'GET',
@@ -62,6 +58,11 @@ module.exports = function(Alt) {
                 }).fail(function(xhr){
                   //Authentication and the handling of fail states should be wrapped up into a connection class.
                   Utils.checkAuthentication(xhr.status);
+                  let msg = xhr.responseText;
+                  if(xhr.errorMessage) {
+                    msg = xhr.errorMessage
+                  }
+                  reject(msg);
                 });
               });
           },
@@ -79,6 +80,7 @@ module.exports = function(Alt) {
                   url: `/platform?api_server=${API_SERVER}`,
                   type: 'PUT',
                   data: project,
+                  dataType: 'json',
                   beforeSend: Utils.addAuthorizationStub,
                   success: function(data, textStatus, jqXHR) {
                     resolve(data);
@@ -86,69 +88,20 @@ module.exports = function(Alt) {
                 }).fail(function(xhr){
                   //Authentication and the handling of fail states should be wrapped up into a connection class.
                   Utils.checkAuthentication(xhr.status);
+                  let msg = xhr.responseText;
+                  if(xhr.errorMessage) {
+                    msg = xhr.errorMessage
+                  }
+                  reject(msg);
                 });
             });
           },
           interceptResponse: interceptResponse({
             'error': 'There was an error updating the project.'
           }),
-          success: Alt.actions.global.updateProjectSuccess,
-          loading: Alt.actions.global.showScreenLoader,
-          error: Alt.actions.global.showNotification
-        },
-        deleteProject: {
-          remote: function(state, project) {
-            return new Promise(function(resolve, reject) {
-              // setTimeout(function() {
-              //     resolve(true);
-              // }, 1000)
-              $.ajax({
-                url: `/project/${project['name']}?api_server=${API_SERVER}`,
-                type: 'DELETE',
-                beforeSend: Utils.addAuthorizationStub,
-                success: function(data, textStatus, jqXHR) {
-                  resolve(data);
-                }
-              }).fail(function(xhr){
-                //Authentication and the handling of fail states should be wrapped up into a connection class.
-                Utils.checkAuthentication(xhr.status);
-              });
-            });
-          },
-          interceptResponse: interceptResponse({
-            'error': 'There was an error deleting the user.'
-          }),
-          success: Alt.actions.global.deleteProjectSuccess,
+          success: Alt.actions.global.updatePlatformSuccess,
           loading: Alt.actions.global.showScreenLoader,
           error: Alt.actions.global.showNotification
-        },
-        createProject: {
-            remote: function(state, project) {
-
-              return new Promise(function(resolve, reject) {
-                // setTimeout(function() {
-                //     resolve(true);
-                // }, 1000)
-                $.ajax({
-                  url: `/project?api_server=${API_SERVER}`,
-                  type: 'POST',
-                  data: project,
-                  beforeSend: Utils.addAuthorizationStub,
-                  success: function(data, textStatus, jqXHR) {
-                    resolve(data);
-                  }
-                }).fail(function(xhr){
-                  //Authentication and the handling of fail states should be wrapped up into a connection class.
-                  Utils.checkAuthentication(xhr.status);
-                });
-              });
-            },
-            interceptResponse: interceptResponse({
-              'error': 'There was an error updating the account.'
-            }),
-            success: Alt.actions.global.createProjectSuccess,
-            loading: Alt.actions.global.showScreenLoader,
-            error: Alt.actions.global.showNotification
         }
       }
 }
@@ -166,61 +119,3 @@ function interceptResponse (responses) {
   }
 }
 
-function mockProjects() {
-  let data = [];
-  let count = 10;
-  for(let i = 0; i < 3; i++) {
-    data.push({
-      name: `Test Project ${i}`,
-      description: 'Some description',
-      roles: ['Some-Role', 'Some-Other-Role'],
-      users: [
-        {
-          'user-name': 'Some-User',
-          'user-domain': 'system',
-          role: [
-            {
-              'role': 'Some-Role',
-              'key-set' : 'some key'
-            },
-            {
-              'role': 'Some-Other-Role',
-              'key-set' : 'some key'
-            }
-          ]
-        },
-        {
-          'user-name': 'Some-User',
-          'user-domain': 'system',
-          role: [
-            {
-              'role': 'Some-Role',
-              'key-set' : 'some key'
-            }
-          ]
-        }
-      ]
-    })
-  }
-  return data;
-}
-function mockUsers() {
-  let data = [];
-  let count = 10;
-  for(let i = 0; i < 10; i++) {
-    data.push({
-      'user-name': `Tester ${i}`,
-      'user-domain': 'Some Domain',
-      platformRoles: {
-        super_admin: true,
-        platform_admin: false,
-        platform_oper: false
-      },
-      disabled: false,
-      projectRoles: [
-        'Project:Role'
-      ]
-    })
-  }
-  return data;
-}