airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] 03/04: AIRAVATA-2794 Prevent deleting GatewayGroups groups
Date Mon, 04 Jun 2018 18:15:05 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

commit b82da7c30e02a546b6f0dae9e6ff02f848bbbde7
Author: Marcus Christie <machrist@iu.edu>
AuthorDate: Tue May 22 17:40:40 2018 -0400

    AIRAVATA-2794 Prevent deleting GatewayGroups groups
---
 django_airavata/apps/api/serializers.py            | 24 ++++++++++++++++++++++
 .../static/django_airavata_api/js/models/Group.js  |  3 +++
 .../js/group_components/GroupListItem.vue          | 18 ++++++++++++++--
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py
index fffdd5f..6b4398d 100644
--- a/django_airavata/apps/api/serializers.py
+++ b/django_airavata/apps/api/serializers.py
@@ -138,6 +138,9 @@ class GroupSerializer(serializers.Serializer):
     isAdmin = serializers.SerializerMethodField()
     isOwner = serializers.SerializerMethodField()
     isMember = serializers.SerializerMethodField()
+    isGatewayAdminsGroup = serializers.SerializerMethodField()
+    isReadOnlyGatewayAdminsGroup = serializers.SerializerMethodField()
+    isDefaultGatewayUsersGroup = serializers.SerializerMethodField()
 
     def create(self, validated_data):
         validated_data['ownerId'] = self.context['request'].user.username + "@" + settings.GATEWAY_ID
@@ -170,6 +173,27 @@ class GroupSerializer(serializers.Serializer):
         username = request.user.username + "@" + settings.GATEWAY_ID
         return group.members and username in group.members
 
+    def get_isGatewayAdminsGroup(self, group):
+        request = self.context['request']
+        return group.id == self._gateway_groups()['adminsGroupId']
+
+    def get_isReadOnlyGatewayAdminsGroup(self, group):
+        request = self.context['request']
+        return group.id == self._gateway_groups()['readOnlyAdminsGroupId']
+
+    def get_isDefaultGatewayUsersGroup(self, group):
+        return group.id == self._gateway_groups()['defaultGatewayUsersGroupId']
+
+    def _gateway_groups(self):
+        request = self.context['request']
+        # gateway_groups_middleware sets this session variable
+        if 'GATEWAY_GROUPS' in request.session:
+            return request.session['GATEWAY_GROUPS']
+        else:
+            gateway_groups = request.airavata_client.getGatewayGroups(
+                request.authz_token)
+            return copy.deepcopy(gateway_groups.__dict__)
+
 
 class ProjectSerializer(serializers.Serializer):
     url = FullyEncodedHyperlinkedIdentityField(view_name='django_airavata_api:project-detail',
lookup_field='projectID', lookup_url_kwarg='project_id')
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/Group.js b/django_airavata/apps/api/static/django_airavata_api/js/models/Group.js
index f570c2e..54afe01 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/models/Group.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/models/Group.js
@@ -9,6 +9,9 @@ const FIELDS = [
     'isOwner',
     'isAdmin',
     'isMember',
+    'isGatewayAdminsGroup',
+    'isReadOnlyGatewayAdminsGroup',
+    'isDefaultGatewayUsersGroup',
 ];
 
 export default class Group extends BaseModel {
diff --git a/django_airavata/apps/groups/static/django_airavata_groups/js/group_components/GroupListItem.vue
b/django_airavata/apps/groups/static/django_airavata_groups/js/group_components/GroupListItem.vue
index 04155f0..6357d9f 100644
--- a/django_airavata/apps/groups/static/django_airavata_groups/js/group_components/GroupListItem.vue
+++ b/django_airavata/apps/groups/static/django_airavata_groups/js/group_components/GroupListItem.vue
@@ -1,6 +1,10 @@
 <template>
     <tr>
-        <td>{{ group.name }}</td>
+        <td>{{ group.name }}
+            <b-badge v-if="group.isGatewayAdminsGroup">Admins</b-badge>
+            <b-badge v-if="group.isReadOnlyGatewayAdminsGroup">Read Only Admins</b-badge>
+            <b-badge v-if="group.isDefaultGatewayUsersGroup">Default</b-badge>
+        </td>
         <td>{{ group.ownerId }}</td>
         <td>{{ group.description }}</td>
         <td>
@@ -8,7 +12,7 @@
                 :href="'/groups/edit/' + encodeURIComponent(group.id) + '/'">
                 Edit <i class="fa fa-pencil"></i>
             </a>
-            <a href="#" v-if="group.isOwner" @click="show=true" :variant="deleteButtonVariant">
+            <a href="#" v-if="deleteable" @click="show=true" :variant="deleteButtonVariant">
                 Delete <i class="fa fa-trash"></i>
             </a>
             <b-modal :header-bg-variant="headerBgVariant" :header-text-variant="headerTextVariant"
:body-bg-variant="bodyBgVariant" v-model="show" :id="'modal'+group.id" title="Are you sure?">
@@ -41,6 +45,16 @@ export default {
       }
     },
     props: ['group'],
+    computed: {
+        deleteable: function() {
+            return this.group.isOwner
+                // Don't allow deleting "GatewayGroups" groups since they serve
+                // a special function in the gateway
+                && this.group.isGatewayAdminsGroup === false
+                && this.group.isReadOnlyGatewayAdminsGroup === false
+                && this.group.isDefaultGatewayUsersGroup === false;
+        }
+    },
     methods: {
       deleteGroup(id) {
           this.deleting = true;

-- 
To stop receiving notification emails like this one, please contact
machristie@apache.org.

Mime
View raw message