airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] branch master updated: AIRAVATA-2835 ShareButton with display of number of shared users/groups
Date Mon, 09 Jul 2018 21:01:36 GMT
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


The following commit(s) were added to refs/heads/master by this push:
     new bee6eb7  AIRAVATA-2835 ShareButton with display of number of shared users/groups
bee6eb7 is described below

commit bee6eb71f0a31bdfe72269aa6f8fa6bb30fc042d
Author: Marcus Christie <machrist@iu.edu>
AuthorDate: Mon Jul 9 16:50:28 2018 -0400

    AIRAVATA-2835 ShareButton with display of number of shared users/groups
---
 .../GroupComputeResourcePreference.vue             | 10 +++-
 django_airavata/apps/api/serializers.py            | 12 ++---
 .../api/static/django_airavata_api/js/index.js     |  2 +
 .../js/models/ResourcePermissionType.js            |  9 ++++
 .../django_airavata_api/js/models/SharedEntity.js  | 59 ++++++++++++++++++++++
 .../django_airavata_api/js/service_config.js       |  6 ++-
 django_airavata/apps/api/views.py                  |  4 +-
 .../static/common/js/components/ShareButton.vue    | 51 +++++++++++++++++++
 django_airavata/static/common/js/index.js          |  4 +-
 9 files changed, 145 insertions(+), 12 deletions(-)

diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
index 40d2378..337ebdf 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
@@ -12,6 +12,7 @@
           <auto-complete v-model="selectedGroups"
                          v-bind:suggestions="groups"></auto-complete>
         </div>
+        <share-button v-if="sharedEntity" v-model="sharedEntity"/>
       </div>
       <div class="new-application-tab-main">
         <h4>Compute Preferences</h4>
@@ -76,6 +77,10 @@
         this.groups = value.results;
       }));
       this.fetchGroup(this.value.groupResourceProfileId);
+      if (this.value.groupResourceProfileId) {
+        DjangoAiravataAPI.services.ServiceFactory.service("SharedEntities").retrieve({lookup:
this.value.groupResourceProfileId})
+          .then(sharedEntity => this.sharedEntity = sharedEntity);
+      }
     },
     data: function () {
       let data = Object.assign({},this.value);
@@ -87,6 +92,7 @@
         data: data,
         service: DjangoAiravataAPI.services.ServiceFactory.service("GroupResourcePreference"),
         groups: [],
+        sharedEntity: null,
 
       }
     },
@@ -94,8 +100,8 @@
     components: {
       ComputePreference,
       "auto-complete": comps.Autocomplete,
-      TabActionConsole
-
+      TabActionConsole,
+      "share-button": comps.ShareButton,
     },
     methods: {
       transformData: function (groupResourceProfile) {
diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py
index 1aeba7a..af48f68 100644
--- a/django_airavata/apps/api/serializers.py
+++ b/django_airavata/apps/api/serializers.py
@@ -472,8 +472,8 @@ class GroupPermissionSerializer(serializers.Serializer):
 class SharedEntitySerializer(serializers.Serializer):
 
     entityId = serializers.CharField(read_only=True)
-    users = UserPermissionSerializer(many=True)
-    groups = GroupPermissionSerializer(many=True)
+    userPermissions = UserPermissionSerializer(many=True)
+    groupPermissions = GroupPermissionSerializer(many=True)
     owner = UserProfileSerializer(read_only=True)
     isOwner = serializers.SerializerMethodField()
 
@@ -483,9 +483,9 @@ class SharedEntitySerializer(serializers.Serializer):
     def update(self, instance, validated_data):
         # Compute lists of ids to grant/revoke READ/WRITE
         existing_user_permissions = {user.user.userId: user.permissionType
-                                     for user in instance.users}
+                                     for user in instance.userPermissions}
         new_user_permissions = {user.user.userId: user.permissionType
-                                for user in validated_data.users}
+                                for user in validated_data.userPermissions}
 
         (user_grant_read_permission, user_grant_write_permission,
          user_revoke_read_permission, user_revoke_write_permission) = \
@@ -493,9 +493,9 @@ class SharedEntitySerializer(serializers.Serializer):
                                                  new_user_permissions)
 
         existing_group_permissions = {group.group.groupId: group.permissionType
-                                      for group in instance.groups}
+                                      for group in instance.groupPermissions}
         new_group_permissions = {group.group.groupId: group.permissionType
-                                 for group in validated_data.groups}
+                                 for group in validated_data.groupPermissions}
 
         (group_grant_read_permission, group_grant_write_permission,
          group_revoke_read_permission, group_revoke_write_permission) = \
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 f943eb4..cf101d4 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
@@ -9,6 +9,7 @@ import Project from './models/Project'
 import FullExperiment from './models/FullExperiment'
 import Group from './models/Group'
 import GroupResourceProfile from './models/GroupResourceProfile'
+import SharedEntity from './models/SharedEntity'
 
 import ApplicationDeploymentService from './services/ApplicationDeploymentService'
 import ApplicationInterfaceService from './services/ApplicationInterfaceService'
@@ -45,6 +46,7 @@ exports.models = {
     Project,
     Group,
     GroupResourceProfile,
+    SharedEntity,
 }
 
 exports.services = {
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/ResourcePermissionType.js
b/django_airavata/apps/api/static/django_airavata_api/js/models/ResourcePermissionType.js
new file mode 100644
index 0000000..b3143d8
--- /dev/null
+++ b/django_airavata/apps/api/static/django_airavata_api/js/models/ResourcePermissionType.js
@@ -0,0 +1,9 @@
+import BaseEnum from './BaseEnum'
+
+export default class ResourcePermissionType extends BaseEnum {
+}
+ResourcePermissionType.init([
+    'WRITE',
+    'READ',
+    'OWNER',
+]);
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/SharedEntity.js
b/django_airavata/apps/api/static/django_airavata_api/js/models/SharedEntity.js
new file mode 100644
index 0000000..fd7744e
--- /dev/null
+++ b/django_airavata/apps/api/static/django_airavata_api/js/models/SharedEntity.js
@@ -0,0 +1,59 @@
+import BaseModel from './BaseModel';
+import Group from './Group';
+import ResourcePermissionType from './ResourcePermissionType';
+import UserProfile from './UserProfile';
+
+class UserPermission extends BaseModel {
+    constructor(data = {}) {
+        super([
+            {
+                name: 'user',
+                type: UserProfile,
+            },
+            {
+                name: 'permissionType',
+                type: ResourcePermissionType,
+            }
+        ], data);
+    }
+}
+
+class GroupPermission extends BaseModel {
+    constructor(data = {}) {
+        super([
+            {
+                name: 'group',
+                type: Group,
+            },
+            {
+                name: 'permissionType',
+                type: ResourcePermissionType,
+            }
+        ], data);
+    }
+}
+
+const FIELDS = [
+    'entityId',
+    {
+        name: 'userPermissions',
+        type: UserPermission,
+        list: true
+    },
+    {
+        name: 'groupPermissions',
+        type: GroupPermission,
+        list: true
+    },
+    {
+        name: 'owner',
+        type: UserProfile,
+    },
+    'isOwner',
+];
+
+export default class SharedEntity extends BaseModel {
+    constructor(data = {}) {
+        super(FIELDS, data);
+    }
+}
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
index cd51d77..55dc68f 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
@@ -42,5 +42,9 @@ export default {
             name:"create",
             pagination:true
         }]
-    }
+    },
+    "SharedEntities": {
+        url: "/api/shared-entities",
+        viewSet: true
+    },
 }
\ No newline at end of file
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index 7df39bb..a792715 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -778,8 +778,8 @@ class SharedEntityViewSet(mixins.RetrieveModelMixin,
             group_list.append({'group': self._load_group(group_id),
                                'permissionType': groups[group_id]})
         return {'entityId': lookup_value,
-                'users': user_list,
-                'groups': group_list,
+                'userPermissions': user_list,
+                'groupPermissions': group_list,
                 'owner': self._load_user_profile(owner_id)}
 
     def _load_accessible_users(self, entity_id, permission_type):
diff --git a/django_airavata/static/common/js/components/ShareButton.vue b/django_airavata/static/common/js/components/ShareButton.vue
new file mode 100644
index 0000000..cc7b643
--- /dev/null
+++ b/django_airavata/static/common/js/components/ShareButton.vue
@@ -0,0 +1,51 @@
+<template>
+    <b-button :variant="'outline-primary'" :title="title">
+        Share
+        <b-badge>{{ totalCount }}</b-badge>
+    </b-button>
+</template>
+
+<script>
+import { models } from 'django-airavata-api';
+
+export default {
+    name: "share-button",
+    props: {
+        value: models.SharedEntity,
+        // TODO: add gatewayGroups
+    },
+    computed: {
+        title: function() {
+            return "Shared with " + this.groupsCount + " groups"
+                + (this.groupsCount > 0 ? " (" + this.groupNames.join(", ") + ")" : "")
+                + " and " + this.usersCount + " users"
+                + (this.usersCount > 0 ? " (" + this.userNames.join(", ") + ")" : "");
+        },
+        usersCount: function() {
+            return this.value ? this.value.userPermissions.length : 0;
+        },
+        userNames: function() {
+            return this.value
+                ? this.value.userPermissions.map(userPerm => userPerm.user.firstName +
" " + userPerm.user.lastName)
+                : null;
+        },
+        groupNames: function() {
+            return this.value
+                ? this.value.groupPermissions.map(groupPerm => groupPerm.group.name)
+                : null;
+        },
+        groupsCount: function() {
+            return this.value ? this.value.groupPermissions.length: 0;
+        },
+        totalCount: function() {
+            return this.usersCount + this.groupsCount;
+        },
+    }
+}
+</script>
+
+<style scoped>
+button {
+    background-color: white;
+}
+</style>
\ No newline at end of file
diff --git a/django_airavata/static/common/js/index.js b/django_airavata/static/common/js/index.js
index 8004556..b208677 100644
--- a/django_airavata/static/common/js/index.js
+++ b/django_airavata/static/common/js/index.js
@@ -1,12 +1,14 @@
 import ApplicationCard from './components/ApplicationCard.vue'
 import Autocomplete from './components/Autocomplete.vue'
 import Pager from './components/Pager.vue'
+import ShareButton from './components/ShareButton.vue'
 import * as utils from './utils'
 
 exports.components = {
     Pager,
     ApplicationCard,
-    Autocomplete
+    Autocomplete,
+    ShareButton,
 }
 
 exports.utils = utils;


Mime
View raw message