Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/apps/api/views/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,25 @@ def validate_invite(self, request):

mem_ser = MembershipSerializer(membership)
return Response(mem_ser.data, status=status.HTTP_200_OK)

@action(detail=True, methods=['delete'])
def delete_organization(self, request, pk=None):
try:
org = Organization.objects.get(id=pk)
member = org.membership_set.get(user=request.user)
if member.group == Membership.OWNER:
org.delete()
return Response({
"success": True,
"message": "Organization deleted!"
})
else:
return Response({
"success": False,
"message": "You do not have delete rights!"
})
except Exception as e:
return Response({
"success": False,
"message": f"{e}"
})
3 changes: 3 additions & 0 deletions src/static/js/ours/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ CODALAB.api = {
delete_organization_member: (id, data) => {
return CODALAB.api.request('DELETE', `${URLS.API}organizations/${id}/delete_member/`, data)
},
delete_organization: (id) => {
return CODALAB.api.request('DELETE', `${URLS.API}organizations/${id}/delete_organization/`)
},
/*---------------------------------------------------------------------
Participants
---------------------------------------------------------------------*/
Expand Down
36 changes: 35 additions & 1 deletion src/templates/profiles/organization_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
{% if is_editor %}
<div class="ui container" style="margin-bottom: 1em">
<a href="{{ organization.url }}edit/"><button type="button" class="ui left floated button">Edit Organization</button></a>

{% if organization.users|length > 1 %}
<button class="ui red right floated button disabled">
Delete Organization
</button>
{% else %}
<button class="ui red right floated button" onclick="{self.delete_organization({{ organization.id }})}" >
Delete Organization
</button>
{% endif %}


</div>
{% endif %}
<div class="ui container">
Expand All @@ -29,7 +41,7 @@ <h1 class="header">{{ organization.name }}</h1>
<p>{{ organization.description | linebreaks }}</p>
</div>
<div class="extra">
Participating in Codalab since {{ organization.date_created }}
Participating in Codabench since {{ organization.date_created }}
</div>
</div>
</div>
Expand Down Expand Up @@ -77,3 +89,25 @@ <h1 class="ui dividing header">Users</h1>
</div>
</div>
{% endblock %}

{% block extra_js %}
<script>

self.delete_organization = (organization_id) => {
if (confirm(`Are you sure you want to permanently delete this organization?`)) {
CODALAB.api.delete_organization(organization_id)
.done((resp) => {
if(resp.success){
toastr.success(resp.message)
setTimeout(function (){window.location.href = '/';}, 1000)
}else{
toastr.error(resp.message)
}
})
.fail((errors) => {
toastr.error('An Error has occurred')
})
}
}
</script>
{% endblock %}