Skip to content

Commit

Permalink
Jkmarx/public group bug fix (#1424)
Browse files Browse the repository at this point in the history
* Add conditional on backend to prevent user from leaving public.

* If public, controls will not show in ui.

* Add dismiss for group edits.

* Add close css.

* Disable button, not just visually.

* Managers can not leave a group.

* Managers can not leave group.

* Remove myfancycounter, not reference elsewhere.

* Add header back.
  • Loading branch information
jkmarx committed Sep 27, 2016
1 parent 474b44d commit 9493da3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
5 changes: 5 additions & 0 deletions refinery/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,11 @@ def ext_groups_members_detail(self, request, **kwargs):
elif request.method == 'DELETE':
# Removing yourself - must delete to leave if last member.
if user.id == int(kwargs['user_id']):

# Prevent users from leaving default public group
if ext_group.name == 'Public':
return HttpForbidden('Members may not leave Public group')

if ext_group.user_set.count() == 1:
return HttpForbidden('Last member - must delete group')

Expand Down
22 changes: 15 additions & 7 deletions refinery/ui/source/js/collaboration/controllers/group-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ function GroupEditorCtrl (
this.group = group;
this.authService = authService;
this.sessionService = sessionService;
this.errorFlag = false;

this.close = function () {
this.$uibModalInstance.dismiss();
};
}

GroupEditorCtrl.prototype.leaveGroup = function () {
var that = this;
that.errorFlag = false;

that.authService.isAuthenticated()
.then(function (isAuthenticated) {
Expand All @@ -34,12 +40,13 @@ GroupEditorCtrl.prototype.leaveGroup = function () {
.then(function () {
that.groupDataService.update();
that.$uibModalInstance.dismiss();
})
.catch(function () {
that.bootbox.alert('Are you the only member or manager left?');
}, function () {
that.errorFlag = true;
that.errorMessage = 'Error leaving group. If last member, delete' +
' group.';
});
} else {
that.bootbox.alert('Sorry, you\'re not authenticated.');
that.bootbox.alert('Error: You are not authenticated.');
}
})
.catch(function () {
Expand All @@ -49,6 +56,7 @@ GroupEditorCtrl.prototype.leaveGroup = function () {

GroupEditorCtrl.prototype.deleteGroup = function () {
var that = this;
that.errorFlag = false;

that.groupExtendedService.delete({
uuid: that.group.uuid
Expand All @@ -57,9 +65,9 @@ GroupEditorCtrl.prototype.deleteGroup = function () {
.then(function () {
that.groupDataService.update();
that.$uibModalInstance.dismiss();
})
.catch(function () {
that.bootbox.alert('Group could not be deleted');
}, function () {
that.errorFlag = true;
that.errorMessage = 'Group could not be deleted.';
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<div class="modal-header">
<h3>Group Editor</h3>
<p>To leave groups with only one member left, you must delete it.</p>
<div class="float-right">
<a ng-click="modal.close()">
<i class="fa fa-times close" aria-hidden="true"></i>
</a>
</div>
<h3 class="text-left">
Group Editor
</h3>
</div>
<div class="modal-body">
<table class="table table-hover" id="group-table">
<thead>
<tr>
<th>Group</th>
<th></th>
<th>{{ collaboration.myFancyCounter }}</th>
</tr>
</thead>
<tbody>
Expand All @@ -21,7 +25,8 @@ <h3>Group Editor</h3>
class="refinery-base btn btn-default"
style="float:right"
ng-click="modal.leaveGroup()"
ng-class="{ disabled: modal.group.member_list.length===1 }"}>
ng-class="{ disabled: modal.group.member_list.length===1 }"}
ng-disabled="modal.group.member_list.length===1 || modal.group.can_edit">
Leave
</button>
</td>
Expand All @@ -35,6 +40,12 @@ <h3>Group Editor</h3>
</button>
</td>
</tr>
<tr>
<div class="text-warning" ng-if="modal.errorFlag">
<i class="fa fa-warning" aria-hidden="true"></i>
{{ modal.errorMessage }}
</div>
</tr>
</tbody>
</table>
</div>
4 changes: 3 additions & 1 deletion refinery/ui/source/js/collaboration/view/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ <h3>
</p>
</td>
<td style="text-align:center">
<a ng-href="#/{{group.uuid}}/" ng-click="collab.openGroupEditor(group)">
<span ng-if="group.name !== 'Public'">
<a ng-href="#/{{group.uuid}}/" ng-click="collab.openGroupEditor(group)">
<i class="fa fa-cog"></i>
</a>
</span>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 9493da3

Please sign in to comment.