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 3ea3901d9e2858506d2b8a911c03b3ebde18ee49
Author: Marcus Christie <machr...@iu.edu>
AuthorDate: Fri Feb 23 01:26:31 2018 -0500

    AIRAVATA-2688 Adding/removing users in group edit
---
 django_airavata/apps/api/serializers.py            |  8 +++++
 django_airavata/apps/api/views.py                  |  9 +++++-
 .../js/groups_components/GroupCreateContainer.vue  |  3 ++
 .../js/groups_components/GroupEditContainer.vue    |  5 +++-
 .../js/groups_components/GroupEditor.vue           | 34 +++++++++-------------
 5 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/django_airavata/apps/api/serializers.py 
b/django_airavata/apps/api/serializers.py
index da2a10b..cf1e4a5 100644
--- a/django_airavata/apps/api/serializers.py
+++ b/django_airavata/apps/api/serializers.py
@@ -129,6 +129,14 @@ class GroupSerializer(serializers.Serializer):
     def update(self, instance, validated_data):
         instance.name = validated_data.get('name', instance.name)
         instance.description = validated_data.get('description', 
instance.description)
+        # Calculate added and removed members
+        old_members = set(instance.members)
+        new_members = set(validated_data.get('members', instance.members))
+        removed_members = old_members - new_members
+        added_members = new_members - old_members
+        instance._removed_members = list(removed_members)
+        instance._added_members = list(added_members)
+        instance.members = validated_data.get('members', instance.members)
         return instance
 
     def get_isAdmin(self, group):
diff --git a/django_airavata/apps/api/views.py 
b/django_airavata/apps/api/views.py
index d0ce7ef..ffe207f 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -218,7 +218,14 @@ class GroupViewSet(APIBackedViewSet):
 
     def perform_update(self, serializer):
         group = serializer.save()
-        
self.request.profile_service['group_manager'].updateGroup(self.authz_token, 
group)
+        group_manager_client = self.request.profile_service['group_manager']
+        if len(group._added_members) > 0:
+            group_manager_client.addUsersToGroup(
+                self.authz_token, group._added_members, group.id)
+        if len(group._removed_members) > 0:
+            group_manager_client.removeUsersFromGroup(
+                self.authz_token, group._removed_members, group.id)
+        group_manager_client.updateGroup(self.authz_token, group)
 
 
 class ProjectViewSet(APIBackedViewSet):
diff --git 
a/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupCreateContainer.vue
 
b/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupCreateContainer.vue
index 81b1dd9..7900407 100644
--- 
a/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupCreateContainer.vue
+++ 
b/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupCreateContainer.vue
@@ -22,6 +22,9 @@ export default {
         GroupEditor,
     },
     methods: {
+        handleSaved: function(group) {
+            window.location.assign("/groups/");
+        }
     },
     computed: {
     },
diff --git 
a/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditContainer.vue
 
b/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditContainer.vue
index 19907d9..66fc885 100644
--- 
a/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditContainer.vue
+++ 
b/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditContainer.vue
@@ -1,5 +1,5 @@
 <template>
-    <group-editor v-if="group" :group="group"></group-editor>
+    <group-editor v-if="group" :group="group" 
@saved="handleSaved"></group-editor>
 </template>
 
 <script>
@@ -26,6 +26,9 @@ export default {
         GroupEditor,
     },
     methods: {
+        handleSaved: function(group) {
+            window.location.assign("/groups/");
+        }
     },
     computed: {
     },
diff --git 
a/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditor.vue
 
b/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditor.vue
index ddba0dc..2749ed4 100644
--- 
a/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditor.vue
+++ 
b/django_airavata/apps/groups/static/django_airavata_groups/js/groups_components/GroupEditor.vue
@@ -4,7 +4,7 @@
       {{ showDismissibleAlert.message }}
     </b-alert>
 
-    <b-form v-if="show">
+    <b-form>
 
       <b-form-group id="group1" label="Group Name:" label-for="group_name" 
description="Name should only contain Alpha Characters">
         <b-form-input id="group_name" type="text" v-model="localGroup.name" 
required placeholder="Enter group name">
@@ -40,10 +40,7 @@ export default {
     },
     data () {
         return {
-            selection: '',
             localGroup: this.group.clone(),
-            show: true,
-            selected: [],
             showDismissibleAlert: {'variant':'success', 'message':'no data', 
'dismissable':false},
             userProfiles: [],
         }
@@ -53,23 +50,18 @@ export default {
     },
     methods: {
         submitForm () {
-            var temp = [];
-            for(var i=0;i<this.selected.length;i++) {
-                temp.push(this.selected[i].id);
-            }
-            this.localGroup.members = temp;
-            services.GroupService.create(this.localGroup)
-            .then(group => {
-                this.$emit('saved', result);
-            })
-            .catch(error => {
-                this.showDismissibleAlert.dismissable = true;
-                this.showDismissibleAlert.message = "Error: "+error.data;
-                this.showDismissibleAlert.variant = "danger";
-            });
-        },
-        updateSelectedValue(data) {
-            this.selected = data;
+            let saveOperation = (this.localGroup.id)
+                ? services.GroupService.update(this.localGroup)
+                : services.GroupService.create(this.localGroup);
+            saveOperation
+                .then(group => {
+                    this.$emit('saved', group);
+                })
+                .catch(error => {
+                    this.showDismissibleAlert.dismissable = true;
+                    this.showDismissibleAlert.message = "Error: "+error.data;
+                    this.showDismissibleAlert.variant = "danger";
+                });
         },
     },
     computed: {

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

Reply via email to