You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/06/20 15:21:09 UTC

[airavata-django-portal] 05/06: AIRAVATA-3440 Allow admins to delete unverified users

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit 414cacad2d133d6420650378f76681d82ce9c8bc
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Jun 19 08:57:02 2019 -0400

    AIRAVATA-3440 Allow admins to delete unverified users
---
 .../src/components/users/DeleteUserPanel.vue       | 33 ++++++++++++++++++++++
 .../IdentityServiceUserManagementContainer.vue     |  6 ++++
 .../UnverifiedEmailUserManagementContainer.vue     | 17 +++++++++--
 .../src/components/users/UserDetailsContainer.vue  |  9 +++++-
 .../api/static/django_airavata_api/js/index.js     |  2 --
 django_airavata/apps/api/views.py                  |  7 +++--
 django_airavata/apps/auth/iam_admin_client.py      |  5 ++++
 7 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/DeleteUserPanel.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/DeleteUserPanel.vue
new file mode 100644
index 0000000..30fc748
--- /dev/null
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/DeleteUserPanel.vue
@@ -0,0 +1,33 @@
+<template>
+  <b-card header="Delete User">
+    <p class="card-text">
+      This will remove {{ username }} from the identity service.
+    </p>
+    <delete-button @delete="deleteUser">
+      Are you sure you want to delete {{ username }}?
+    </delete-button>
+  </b-card>
+</template>
+
+<script>
+import { components } from "django-airavata-common-ui";
+
+export default {
+  name: "delete-user-panel",
+  props: {
+    username: {
+      type: String,
+      required: true
+    }
+  },
+  components: {
+    "delete-button": components.DeleteButton
+  },
+  methods: {
+    deleteUser() {
+      this.$emit("delete-user", this.username);
+    }
+  }
+};
+</script>
+
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/IdentityServiceUserManagementContainer.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/IdentityServiceUserManagementContainer.vue
index 1a40b3f..3f33a95 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/IdentityServiceUserManagementContainer.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/IdentityServiceUserManagementContainer.vue
@@ -54,6 +54,7 @@
                   :editable-groups="editableGroups"
                   @groups-updated="groupsUpdated"
                   @enable-user="enableUser"
+                  @delete-user="deleteUser"
                 />
               </template>
             </b-table>
@@ -199,6 +200,11 @@ export default {
       services.IAMUserProfileService.enable({ lookup: username }).finally(() =>
         this.reloadUserProfiles()
       );
+    },
+    deleteUser(username) {
+      services.IAMUserProfileService.delete({ lookup: username }).finally(() =>
+        this.reloadUserProfiles()
+      );
     }
   }
 };
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UnverifiedEmailUserManagementContainer.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UnverifiedEmailUserManagementContainer.vue
index 8c71046..8b066ff 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UnverifiedEmailUserManagementContainer.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UnverifiedEmailUserManagementContainer.vue
@@ -33,6 +33,11 @@
                   :email="data.item.email"
                   @enable-user="enableUser"
                 />
+                <delete-user-panel
+                  v-if="!data.item.enabled && !data.item.emailVerified"
+                  :username="data.item.userId"
+                  @delete-user="deleteUser"
+                />
               </template>
             </b-table>
             <pager
@@ -118,6 +123,11 @@ export default {
         this.loadUnverifiedEmailUsers()
       );
     },
+    deleteUser(username) {
+      services.IAMUserProfileService.delete({ lookup: username }).finally(() =>
+        this.loadUnverifiedEmailUsers()
+      );
+    },
     loadUnverifiedEmailUsers() {
       return services.UnverifiedEmailUserProfileService.list({
         limit: 10
@@ -125,9 +135,10 @@ export default {
     },
     toggleDetails(row) {
       row.toggleDetails();
-      this.showingDetails[row.item.userId] = !this
-        .showingDetails[row.item.userId];
-    },
+      this.showingDetails[row.item.userId] = !this.showingDetails[
+        row.item.userId
+      ];
+    }
   }
 };
 </script>
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue
index 8bd6bd8..6f6e5a8 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/UserDetailsContainer.vue
@@ -13,12 +13,18 @@
       :email="iamUserProfile.email"
       @enable-user="$emit('enable-user', $event)"
     />
+    <delete-user-panel
+      v-if="!iamUserProfile.enabled && !iamUserProfile.emailVerified"
+      :username="iamUserProfile.userId"
+      @delete-user="$emit('delete-user', $event)"
+    />
   </div>
 </template>
 <script>
 import { models } from "django-airavata-api";
 import UserGroupMembershipEditor from "./UserGroupMembershipEditor";
 import EnableUserPanel from "./EnableUserPanel";
+import DeleteUserPanel from "./DeleteUserPanel";
 
 export default {
   name: "user-details-container",
@@ -34,7 +40,8 @@ export default {
   },
   components: {
     UserGroupMembershipEditor,
-    EnableUserPanel
+    EnableUserPanel,
+    DeleteUserPanel
   },
   data() {
     return {
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/index.js b/django_airavata/apps/api/static/django_airavata_api/js/index.js
index 9edc7d9..c704fb4 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/index.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/index.js
@@ -24,7 +24,6 @@ import GroupResourceProfile from "./models/GroupResourceProfile";
 import IAMUserProfile from "./models/IAMUserProfile";
 import InputDataObjectType from "./models/InputDataObjectType";
 import JobState from "./models/JobState";
-import ManagedUserProfile from "./models/ManagedUserProfile";
 import OutputDataObjectType from "./models/OutputDataObjectType";
 import ParallelismType from "./models/ParallelismType";
 import Project from "./models/Project";
@@ -81,7 +80,6 @@ const models = {
   IAMUserProfile,
   InputDataObjectType,
   JobState,
-  ManagedUserProfile,
   OutputDataObjectType,
   ParallelismType,
   Project,
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index d3a1db3..c6f3ece 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -1386,10 +1386,10 @@ class WorkspacePreferencesView(APIView):
         return Response(serializer.data)
 
 
-class IAMUserViewSet(mixins.CreateModelMixin,
-                     mixins.RetrieveModelMixin,
+class IAMUserViewSet(mixins.RetrieveModelMixin,
                      mixins.UpdateModelMixin,
                      mixins.ListModelMixin,
+                     mixins.DestroyModelMixin,
                      GenericAPIBackedViewSet):
     serializer_class = serializers.IAMUserProfile
     pagination_class = APIResultPagination
@@ -1422,6 +1422,9 @@ class IAMUserViewSet(mixins.CreateModelMixin,
             group_manager_client.removeUsersFromGroup(
                 self.authz_token, [user_id], group_id)
 
+    def perform_destroy(self, instance):
+        iam_admin_client.delete_user(instance['userId'])
+
     @detail_route(methods=['post'])
     def enable(self, request, user_id=None):
         iam_admin_client.enable_user(user_id)
diff --git a/django_airavata/apps/auth/iam_admin_client.py b/django_airavata/apps/auth/iam_admin_client.py
index 05e3b2b..113d2a8 100644
--- a/django_airavata/apps/auth/iam_admin_client.py
+++ b/django_airavata/apps/auth/iam_admin_client.py
@@ -37,6 +37,11 @@ def enable_user(username):
     return iamadmin_client_pool.enableUser(authz_token, username)
 
 
+def delete_user(username):
+    authz_token = utils.get_service_account_authz_token()
+    return iamadmin_client_pool.deleteUser(authz_token, username)
+
+
 def is_user_exist(username):
     authz_token = utils.get_service_account_authz_token()
     return iamadmin_client_pool.isUserExist(authz_token, username)