Commit 14f15a70 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added modal and completed API for members/permissions removal

parent 616329f4
......@@ -58,11 +58,11 @@ public class CLI implements CommandLineRunner {
switch (args[0]) {
case "create-group":
client.createGroup(getNames(args, 1));
client.addGroup(getNames(args, 1));
System.out.println("Group created");
break;
case "delete-group":
client.deleteGroup(getNames(args, 1));
client.removeGroup(getNames(args, 1));
System.out.println("Group deleted");
break;
case "add-member":
......@@ -90,8 +90,8 @@ public class CLI implements CommandLineRunner {
if (args.length < 4) {
displayUsage();
}
client.deletePermission(getNames(args, args.length - 3), args[args.length - 2], args[args.length - 1]);
System.out.println("Permission added");
client.removePermission(getNames(args, args.length - 2), args[args.length - 1]);
System.out.println("Permission removed");
break;
case "prepare-join":
if (args.length != 3) {
......@@ -108,12 +108,12 @@ public class CLI implements CommandLineRunner {
private void displayUsage() {
System.out.println("java -jar gms-client.jar\n"
+ " create-group <name1 name2 name3>\n"
+ " delete-group <name1 name2 name3>\n"
+ " add-group <name1 name2 name3>\n"
+ " remove-group <name1 name2 name3>\n"
+ " add-member <name1 name2 name3> <user_id>\n"
+ " remove-member <name1 name2 name3> <user_id>\n"
+ " add-permission <name1 name2 name3> <user_id> <permission>\n"
+ " delete-permission <name1 name2 name3> <user_id> <permission>\n"
+ " remove-permission <name1 name2 name3> <user_id>\n"
+ " prepare-join <from_user_id> <to_user_id>");
System.exit(0);
}
......
......@@ -40,7 +40,7 @@ public class GmsClient {
this.restTemplate = restTemplate;
}
public Group createGroup(List<String> names) {
public Group addGroup(List<String> names) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "group")
......@@ -51,7 +51,7 @@ public class GmsClient {
return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Group.class).getBody();
}
public void deleteGroup(List<String> names) {
public void removeGroup(List<String> names) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "group")
......@@ -101,13 +101,12 @@ public class GmsClient {
return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Permission.class).getBody();
}
public void deletePermission(List<String> names, String userId, String permission) {
public void removePermission(List<String> names, String userId) {
String url = UriComponentsBuilder.fromHttpUrl(baseUrl)
.pathSegment(WS, "permission")
.queryParam("names", names.toArray())
.queryParam("userId", userId)
.queryParam("permission", permission)
.toUriString();
restTemplate.exchange(url, HttpMethod.DELETE, getEntity(), Void.class);
......
......@@ -51,7 +51,7 @@ public class GmsClientTest {
List<String> names = Arrays.asList("LBT", "INAF");
client.createGroup(names);
client.addGroup(names);
ArgumentCaptor<HttpEntity> entityCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1)).exchange(eq(BASE_URL + "/ws/group"),
......@@ -67,7 +67,7 @@ public class GmsClientTest {
List<String> names = Arrays.asList("LBT", "INAF");
client.deleteGroup(names);
client.removeGroup(names);
ArgumentCaptor<HttpEntity> entityCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1)).exchange(eq(BASE_URL + "/ws/group?names=LBT&names=INAF"),
......@@ -140,10 +140,10 @@ public class GmsClientTest {
List<String> names = Arrays.asList("LBT", "INAF");
client.deletePermission(names, "user_id", "ADMIN");
client.removePermission(names, "user_id");
ArgumentCaptor<HttpEntity> entityCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1)).exchange(eq(BASE_URL + "/ws/permission?names=LBT&names=INAF&userId=user_id&permission=ADMIN"),
verify(restTemplate, times(1)).exchange(eq(BASE_URL + "/ws/permission?names=LBT&names=INAF&userId=user_id"),
eq(HttpMethod.DELETE), entityCaptor.capture(), eq(Void.class));
HttpEntity<?> entity = entityCaptor.getValue();
......
......@@ -82,7 +82,7 @@ export default {
})
});
},
deleteGroup (groupId, input) {
removeGroup (groupId, input) {
let url = BASE_API_URL + 'group/' + groupId
+ '?paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
......@@ -128,5 +128,71 @@ export default {
paginatorPage: input.paginatorPage
})
});
},
getPermission (groupId, userId) {
let url = BASE_API_URL + 'permission?groupId=' + groupId + '&userId=' + userId;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
addMember (userId, permission, input) {
let url = BASE_API_URL + 'member';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
},
removeMember (userId, removeAlsoPermission, input) {
let url = BASE_API_URL + 'member'
+ '?groupId=' + input.selectedGroupId
+ '&userId=' + userId
+ '&removeAlsoPermission=' + removeAlsoPermission
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
removePermission (userId, input) {
let url = BASE_API_URL + 'permission'
+ '?groupId=' + input.selectedGroupId
+ '&userId=' + userId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
}
};
......@@ -14,7 +14,7 @@
<font-awesome-icon icon="edit"></font-awesome-icon>
</a>
&nbsp;
<a href="#" v-on:click.stop="openDeleteGroupModal(group)" class="text-danger" title="Delete">
<a href="#" v-on:click.stop="openRemoveGroupModal(group)" class="text-danger" title="Delete">
<font-awesome-icon icon="trash"></font-awesome-icon>
</a>
</span>
......@@ -48,20 +48,20 @@
<div class="text-center">
</div>
<RenameGroupModal ref="renameGroupModal" />
<ConfirmDeleteGroupModal ref="confirmDeleteGroupModal" />
<ConfirmRemoveGroupModal ref="confirmRemoveGroupModal" />
</b-tab>
</template>
<script>
import RenameGroupModal from './modals/RenameGroupModal.vue'
import ConfirmDeleteGroupModal from './modals/ConfirmDeleteGroupModal.vue'
import { mapState, mapActions } from 'vuex'
import RenameGroupModal from './modals/RenameGroupModal.vue';
import ConfirmRemoveGroupModal from './modals/ConfirmRemoveGroupModal.vue';
import { mapState, mapActions } from 'vuex';
export default {
name: 'GroupsPanel',
components: {
RenameGroupModal,
ConfirmDeleteGroupModal
ConfirmRemoveGroupModal
},
computed: mapState({
model: state => state.model,
......@@ -85,8 +85,8 @@ export default {
openRenameGroupModal: function(group) {
this.$refs.renameGroupModal.openRenameGroupModal(group);
},
openDeleteGroupModal: function(group) {
this.$refs.confirmDeleteGroupModal.openDeleteGroupModal(group);
openRemoveGroupModal: function(group) {
this.$refs.confirmRemoveGroupModal.openRemoveGroupModal(group);
},
setPage: function(page) {
console.log('setPage ', page);
......
......@@ -8,13 +8,14 @@
<PermissionsPanel />
<template slot="tabs-end">
<b-button variant="primary" class="in-tabs-header-btn" v-if="showAddGroupBtn" v-on:click="openAddGroupModal">Add group</b-button>
<b-button variant="primary" class="in-tabs-header-btn" v-if="showAddMemberBtn">Add member</b-button>
<b-button variant="primary" class="in-tabs-header-btn" v-if="showAddCollaboratorBtn">Add collaborator</b-button>
<b-button variant="primary" class="in-tabs-header-btn" v-if="showAddMemberBtn" v-on:click="openAddMemberModal">Add member</b-button>
<b-button variant="primary" class="in-tabs-header-btn" v-if="showAddCollaboratorBtn" v-on:click="openAddMemberModal">Add collaborator</b-button>
<b-button variant="primary" class="in-tabs-header-btn" v-if="showAddPermissionBtn" v-on:click="openAddPermissionModal">Add permission</b-button>
</template>
</b-tabs>
</b-card>
<NewGroupModal />
<AddGroupModal />
<AddMemberModal />
<AddPermissionModal />
</div>
</template>
......@@ -24,7 +25,7 @@ import GroupsBreadcrumb from './GroupsBreadcrumb.vue'
import GroupsPanel from './GroupsPanel.vue'
import MembersPanel from './MembersPanel.vue'
import PermissionsPanel from './PermissionsPanel.vue'
import NewGroupModal from './modals/NewGroupModal.vue'
import AddGroupModal from './modals/AddGroupModal.vue'
import AddMemberModal from './modals/AddMemberModal.vue'
import AddPermissionModal from './modals/AddPermissionModal.vue'
import { mapState } from 'vuex';
......@@ -36,7 +37,7 @@ export default {
GroupsPanel,
MembersPanel,
PermissionsPanel,
NewGroupModal,
AddGroupModal,
AddMemberModal,
AddPermissionModal
},
......@@ -67,10 +68,10 @@ export default {
}
},
openAddGroupModal: function() {
this.$bvModal.show('new-group-modal');
this.$bvModal.show('add-group-modal');
},
openAddMemberModal: function() {
this.$bvModal.show('add-member-modal');
},
openAddPermissionModal: function() {
this.$bvModal.show('add-permission-modal');
......
......@@ -3,12 +3,11 @@
<div v-if="model.membersPanel !== null">
<b-list-group v-for="member in model.membersPanel.items" id="members-list">
<b-list-group-item href="#">
{{member.label}}
<span v-if="model.permission === 'ADMIN'">
<a href="#" v-on:click="changeMemberPermission(member)">
<font-awesome-icon icon="edit"></font-awesome-icon>
</a>
<a href="#" v-on:click="deleteMember(member)">
<div class="float-left">
<User v-bind:user="member" />
</div>
<span v-if="model.permission === 'ADMIN' || model.permission === 'MANAGE_MEMBERS'" class="float-right">
<a href="#" v-on:click.stop="openRemoveMemberModal(member)" class="text-danger" title="Remove member">
<font-awesome-icon icon="trash"></font-awesome-icon>
</a>
</span>
......@@ -25,27 +24,49 @@
v-on:change="setPage"
></b-pagination>
</div>
<ConfirmRemoveMemberModal ref="confirmRemoveMemberModal" />
</b-tab>
</template>
<script>
import client from 'api-client';
import User from './User.vue';
import ConfirmRemoveMemberModal from './modals/ConfirmRemoveMemberModal.vue'
import { mapState } from 'vuex';
export default {
name: 'MembersPanel',
components: {
User,
ConfirmRemoveMemberModal
},
computed: mapState({
model: state => state.model,
model: state => state.model
}),
methods: {
deleteMember: function(member) {
console.log('deleteMember ' + member.id);
},
changeMemberPermission: function(member) {
console.log('changeMemberPermission ' + member.id);
openRemoveMemberModal: function(member) {
getMemberPermission(this, member)
.then(memberPermission => {
this.$refs.confirmRemoveMemberModal.openRemoveMemberModal(member, memberPermission);
});
},
setPage: function(page) {
console.log('setPage ', page);
}
}
}
function getMemberPermission(self, member) {
return new Promise((resolve, reject) => {
if(self.model.permission === 'ADMIN') {
let groupId = self.$store.state.input.selectedGroupId;
client.getPermission(groupId, member.id)
.then(res => {
resolve(res.permission);
});
} else {
resolve(null);
}
});
}
</script>
......@@ -15,7 +15,11 @@
<User v-bind:user="up.user" />
</td>
<td>{{up.permission}}</td>
<td></td>
<td>
<a href="#" v-on:click.stop="openRemovePermissionModal(up.user)" class="text-danger" title="Remove permission">
<font-awesome-icon icon="trash"></font-awesome-icon>
</a>
</td>
</tr>
</tbody>
</table>
......@@ -30,24 +34,27 @@
v-on:change="setPage"
></b-pagination>
</div>
<ConfirmRemovePermissionModal ref="confirmRemovePermissionModal" />
</b-tab>
</template>
<script>
import User from './User.vue'
import User from './User.vue';
import ConfirmRemovePermissionModal from './modals/ConfirmRemovePermissionModal.vue'
import { mapState } from 'vuex';
export default {
name: 'PermissionsPanel',
components: {
User
User,
ConfirmRemovePermissionModal
},
computed: mapState({
model: state => state.model,
}),
methods: {
deletePermission: function(userPermission) {
openRemovePermissionModal: function(user) {
this.$refs.confirmRemovePermissionModal.openRemovePermissionModal(user);
},
setPage: function(page) {
console.log('setPage ', page);
......
<template>
<b-modal id="new-group-modal" title="Add group" @show="resetModal" ok-title="Add" @ok="addGroup">
<b-modal id="add-group-modal" title="Add group" @show="resetModal" ok-title="Add" @ok="addGroup">
<b-form inline>
<label class="w-25" for="new-group-name-input">Group name:</label>
<b-form-input v-model="newGroupName"
......@@ -18,7 +18,7 @@
import client from 'api-client';
export default {
name: 'NewGroupModal',
name: 'AddGroupModal',
computed: {
newGroupNameState() {
if(this.newGroupNameError) {
......@@ -56,7 +56,7 @@ export default {
this.newGroupNameError = res.message;
} else {
this.$store.commit('updateGroupsPanel', res);
this.$bvModal.hide('new-group-modal');
this.$bvModal.hide('add-group-modal');
}
});
}
......
<template>
<b-modal id="add-member-modal" title="Add member" ok-title="Add" @ok="addMember">
<SearchUser />
<SearchUser ref="searchUser" />
</b-modal>
</template>
<script>
import client from 'api-client';
import SearchUser from './SearchUser.vue'
import { mapState } from 'vuex';
export default {
name: 'AddMemberModal',
components: {
SearchUser
},
data: function() {
return {
permission: 'VIEW_MEMBERS'
}
},
methods: {
addMember: function() {
addMember: function(event) {
// Prevent modal from closing
event.preventDefault();
let userId = this.$refs.searchUser.selectedUser;
let permission = this.$refs.searchUser.permission;
client.addMember(userId, permission, this.$store.state.input)
.then(res => {
this.$store.commit('updateMembersPanel', res);
this.$bvModal.hide('add-member-modal');
});
}
}
};
......
......@@ -13,10 +13,6 @@ export default {
components: {
SearchUser
},
data: function() {
return {
}
},
methods: {
addPermission: function(event) {
// Prevent modal from closing
......
<template>
<b-modal id="confirm-delete-group-modal" title="Confirm action" ok-title="Delete" @ok="deleteGroup" ok-variant="danger">
<p v-if="groupToDelete">Are you sure that you want to delete the group <strong>{{groupToDelete.groupName}}</strong>?</p>
<b-modal id="confirm-remove-group-modal" title="Confirm action" ok-title="Delete" @ok="removeGroup" ok-variant="danger">
<p v-if="groupToRemove">Are you sure that you want to delete the group <strong>{{groupToRemove.groupName}}</strong>?</p>
</b-modal>
</template>
......@@ -8,22 +8,25 @@
import client from 'api-client';
export default {
name: 'ConfirmDeleteGroupModal',
name: 'ConfirmRemoveGroupModal',
data: function() {
return {
groupToDelete: null
groupToRemove: null
}
},
methods: {
openDeleteGroupModal: function(group) {
this.groupToDelete = group;
this.$bvModal.show('confirm-delete-group-modal');
openRemoveGroupModal: function(group) {
this.groupToRemove = group;
this.$bvModal.show('confirm-remove-group-modal');
},
deleteGroup: function() {
client.deleteGroup(this.groupToDelete.groupId, this.$store.state.input)
removeGroup: function(event) {
// Prevent modal from closing
event.preventDefault();
client.removeGroup(this.groupToRemove.groupId, this.$store.state.input)
.then(res => {
this.$store.commit('updateGroupsPanel', res);
this.$bvModal.hide('confirm-delete-group-modal');
this.$bvModal.hide('confirm-remove-group-modal');
})
}
}
......
<template>
<b-modal id="confirm-remove-member-modal" title="Confirm action" ok-title="Remove" @ok="removeMember" ok-variant="danger">
<p v-if="memberToRemove">Are you sure that you want to remove the user {{memberToRemove.displayName}} from this group?</p>
<b-form inline v-if="model.permission === 'ADMIN' && memberPermission">
<b-form-checkbox v-model="removeAlsoPermission">Remove also permission ({{memberPermission}})</b-form-checkbox>
</b-form>
</b-modal>
</template>
<script>
import client from 'api-client';
import { mapState, mapActions } from 'vuex';
export default {
name: 'ConfirmRemoveGroupModal',
data: function() {
return {
memberToRemove: null,
memberPermission: null,
removeAlsoPermission: true
}
},
computed: mapState({
model: state => state.model
}),
methods: {
openRemoveMemberModal: function(member, memberPermission) {
this.memberToRemove = member;
this.memberPermission = memberPermission;
this.$bvModal.show('confirm-remove-member-modal');
},
removeMember: function(event) {
// Prevent modal from closing
event.preventDefault();
client.removeMember(this.memberToRemove.id, this.removeAlsoPermission, this.$store.state.input)
.then(res => {
this.$store.commit('updateMembersPanel', res);
this.$bvModal.hide('confirm-remove-member-modal');
});
}
}
}
</script>
<template>
<b-modal id="confirm-remove-permission-modal" title="Confirm action" ok-title="Remove" @ok="removePermission" ok-variant="danger">
<p v-if="user">Are you sure that you want to remove the permission for the user {{user.displayName}}?</p>
</b-modal>
</template>
<script>
import client from 'api-client';
import { mapState, mapActions } from 'vuex';
export default {
name: 'ConfirmRemovePermissionModal',
data: function() {
return {
user: null
}
},