Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jkmarx/public group bug fix #1424

Merged
merged 9 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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