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/05/09 16:20:00 UTC

[airavata-django-portal] 05/06: AIRAVATA-3030 simplified code for displaying inherited sharings

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 e6a91075065138edd6e3a7b847b193c79e477fda
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu May 9 12:15:16 2019 -0400

    AIRAVATA-3030 simplified code for displaying inherited sharings
---
 .../static/common/js/components/ShareButton.vue    | 38 +++---------
 .../common/js/components/SharedEntityEditor.vue    | 68 +++++++++-------------
 2 files changed, 36 insertions(+), 70 deletions(-)

diff --git a/django_airavata/static/common/js/components/ShareButton.vue b/django_airavata/static/common/js/components/ShareButton.vue
index 6380955..3f9fe42 100644
--- a/django_airavata/static/common/js/components/ShareButton.vue
+++ b/django_airavata/static/common/js/components/ShareButton.vue
@@ -26,26 +26,22 @@
         v-model="localSharedEntity"
         :users="users"
         :groups="groups"
-        :parent-entity-owner="parentEntityOwner"
-        :parent-entity-label="parentEntityLabel"
         :disallow-editing-admin-groups="disallowEditingAdminGroups"
       />
       <!-- Only show parent entity permissions for new entities -->
-      <template v-if="!entityId && hasParentSharedEntityPermissions">
+      <template v-if="hasParentSharedEntityPermissions">
         <shared-entity-editor
           v-if="parentSharedEntity && users && groups"
           v-model="parentSharedEntity"
           :users="users"
           :groups="groups"
           :readonly="true"
-          class="mt-5"
+          class="mt-4"
         >
-          <span slot="permissions-header">Inherited {{ parentEntityLabel }} Permissions</span>
+          <span slot="permissions-header">Inherited {{ parentEntityLabel }} Permissions
+            <!-- <small class="text-muted" v-if="parentEntityOwner">Owned by {{parentEntityOwner.firstName}} {{parentEntityOwner.lastName}} ({{parentEntityOwner.email}})</small> -->
+          </span>
         </shared-entity-editor>
-        <small class="text-muted">These permissions are inherited when your <span class="text-lowercase">{{ entityLabel
-            }}</span> is initially
-          created but can be updated
-          afterwards.</small>
       </template>
     </b-modal>
   </div>
@@ -64,10 +60,6 @@ export default {
       type: String,
       default: "Parent"
     },
-    entityLabel: {
-      type: String,
-      default: "Entity"
-    },
     sharedEntity: models.SharedEntity,
     autoAddDefaultGatewayUsersGroup: {
       type: Boolean,
@@ -117,18 +109,10 @@ export default {
           ...this.localSharedEntity.userPermissions.map(up => up.user)
         );
       }
-      if (this.parentSharedEntity) {
-        // Only add in inherited permissions if we haven't saved yet because
-        // once saved the inherited permissions are already copied in
-        if (
-          this.localSharedEntity &&
-          !this.localSharedEntity.entityId &&
-          this.parentSharedEntity.userPermissions
-        ) {
-          users.push(
-            ...this.parentSharedEntity.userPermissions.map(up => up.user)
-          );
-        }
+      if (this.parentSharedEntity && this.parentSharedEntity.userPermissions) {
+        users.push(
+          ...this.parentSharedEntity.userPermissions.map(up => up.user)
+        );
         if (this.parentEntityOwner) {
           users.push(this.parentEntityOwner);
         }
@@ -147,11 +131,7 @@ export default {
     combinedGroups() {
       const groups = [];
       groups.push(...this.filteredGroupPermissions.map(gp => gp.group));
-      // Only add in inherited permissions if we haven't saved yet because
-      // once saved the inherited permissions are already copied in
       if (
-        this.localSharedEntity &&
-        !this.localSharedEntity.entityId &&
         this.parentSharedEntity &&
         this.parentSharedEntity.groupPermissions
       ) {
diff --git a/django_airavata/static/common/js/components/SharedEntityEditor.vue b/django_airavata/static/common/js/components/SharedEntityEditor.vue
index a03e5e2..609d01d 100644
--- a/django_airavata/static/common/js/components/SharedEntityEditor.vue
+++ b/django_airavata/static/common/js/components/SharedEntityEditor.vue
@@ -32,42 +32,41 @@
       v-if="usersCount > 0"
       id="modal-user-table"
       hover
-      :items="sortedUserPermissionsData"
+      :items="sortedUserPermissions"
       :fields="userFields"
     >
       <template
         slot="name"
         slot-scope="data"
       >
-        <span :title="data.item.user.userId" :class="data.item.classes">{{data.item.user.firstName}} {{data.item.user.lastName}}</span>
+        <span :title="data.item.user.userId" :class="userDataClasses">{{data.item.user.firstName}} {{data.item.user.lastName}}</span>
       </template>
       <template
         slot="email"
         slot-scope="data"
       >
-        <span :class="data.item.classes">{{data.item.user.email}}</span>
+        <span :class="userDataClasses">{{data.item.user.email}}</span>
       </template>
       <template
         slot="permission"
         slot-scope="data"
       >
         <b-form-select
-          v-if="!data.item.readonly"
-          :value="data.item.permissionType"
+          v-if="!readonly"
+          v-model="data.item.permissionType"
           :options="permissionOptions"
-          @input="changeUserPermission(data.item.user, $event)"
         />
         <span
           v-else
           class="text-uppercase"
-          :class="data.item.classes"
-        >{{ data.item.permissionTypeLabel }}</span>
+          :class="userDataClasses"
+        >{{ data.item.permissionType.name }}</span>
       </template>
       <template
         slot="remove"
         slot-scope="data"
       >
-        <b-link v-if="!data.item.readonly" @click="removeUser(data.item.user)">
+        <b-link v-if="!readonly" @click="removeUser(data.item.user)">
           <span class="fa fa-trash"></span>
         </b-link>
       </template>
@@ -145,13 +144,6 @@ export default {
     readonly: {
       type: Boolean,
       default: false
-    },
-    parentEntityOwner: {
-      type: models.UserProfile,
-    },
-    parentEntityLabel: {
-      type: String,
-      default: "Parent"
     }
   },
   components: {
@@ -174,35 +166,33 @@ export default {
       ];
     },
     usersCount: function() {
-      return this.sortedUserPermissionsData.length;
+      return this.data && this.data.userPermissions
+        ? this.data.userPermissions.length
+        : 0;
     },
-    sortedUserPermissionsData: function() {
+    sortedUserPermissions: function() {
       const userPermsCopy = this.data.userPermissions
         ? this.data.userPermissions.slice()
         : [];
-      const sorted = utils.StringUtils.sortIgnoreCase(
+      const sortedUserPerms = utils.StringUtils.sortIgnoreCase(
         userPermsCopy,
         userPerm => userPerm.user.lastName + ", " + userPerm.user.firstName
       );
-      const sortedData = sorted.map(up => {
-        return {
-          user: up.user,
-          permissionType: up.permissionType,
-          permissionTypeLabel: up.permissionType.name,
-          readonly: this.readonly,
-          classes: this.readonly ? ['text-muted', 'font-italic'] : null
-        }
-      });
-      if (this.parentEntityOwner) {
-        sortedData.push({
-          user: this.parentEntityOwner,
-          permissionType: models.ResourcePermissionType.OWNER,
-          permissionTypeLabel: this.parentEntityLabel + " OWNER",
-          readonly: true,
-          classes: ['text-muted', 'font-italic']
-        });
+      // When in readonly mode, if the current owner isn't the owner, display
+      // the user with the OWNER permission
+      if (this.readonly && !this.data.isOwner) {
+        sortedUserPerms.push(new models.UserPermission({
+          user: this.data.owner,
+          permissionType: models.ResourcePermissionType.OWNER
+        }));
+      }
+      return sortedUserPerms;
+    },
+    userDataClasses() {
+      return {
+        'text-muted': this.readonly,
+        'font-italic': this.readonly
       }
-      return sortedData;
     },
     filteredGroupPermissions: function() {
       return this.data && this.data.groupPermissions
@@ -295,10 +285,6 @@ export default {
     removeUser: function(user) {
       this.data.removeUser(user);
     },
-    changeUserPermission(user, permissionType) {
-      const up = this.data.userPermissions.find(up => up.user.airavataInternalUserId === user.airavataInternalUserId);
-      up.permissionType = permissionType;
-    },
     removeGroup: function(group) {
       this.data.removeGroup(group);
     },