From 7fc1591e08ae8e2af29a3f9e9806de0158a76f01 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Sun, 18 Jun 2023 01:33:10 +0500 Subject: [PATCH 1/3] Organization delete functionality added --- src/apps/api/views/profiles.py | 15 ++++++++ src/static/js/ours/client.js | 3 ++ .../profiles/organization_detail.html | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/src/apps/api/views/profiles.py b/src/apps/api/views/profiles.py index c34fb9482..c841df941 100644 --- a/src/apps/api/views/profiles.py +++ b/src/apps/api/views/profiles.py @@ -229,3 +229,18 @@ 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) + org.delete() + return Response({ + "success": True, + "message": "Organization deleted!" + }) + except Exception as e: + return Response({ + "success": False, + "message": f"{e}" + }) diff --git a/src/static/js/ours/client.js b/src/static/js/ours/client.js index 3c4a6ae05..f3e1a21dc 100644 --- a/src/static/js/ours/client.js +++ b/src/static/js/ours/client.js @@ -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 ---------------------------------------------------------------------*/ diff --git a/src/templates/profiles/organization_detail.html b/src/templates/profiles/organization_detail.html index 8b99319a1..0ca39a93b 100644 --- a/src/templates/profiles/organization_detail.html +++ b/src/templates/profiles/organization_detail.html @@ -6,6 +6,18 @@ {% if is_editor %}
+ + {% if organization.users|length > 1 %} + + {% else %} + + {% endif %} + +
{% endif %}
@@ -77,3 +89,25 @@

Users

{% endblock %} + +{% block extra_js %} + +{% endblock %} From a009dc361c991e936090bc0de893b600cb9310c5 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Sun, 18 Jun 2023 01:35:22 +0500 Subject: [PATCH 2/3] Codalab->Codabench --- src/templates/profiles/organization_detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/profiles/organization_detail.html b/src/templates/profiles/organization_detail.html index 0ca39a93b..386403a22 100644 --- a/src/templates/profiles/organization_detail.html +++ b/src/templates/profiles/organization_detail.html @@ -41,7 +41,7 @@

{{ organization.name }}

{{ organization.description | linebreaks }}

- Participating in Codalab since {{ organization.date_created }} + Participating in Codabench since {{ organization.date_created }}
From 089441d7ce57328cf945af39f63c1f21e971785e Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Sun, 18 Jun 2023 20:09:01 +0500 Subject: [PATCH 3/3] delte restricted to owner only --- src/apps/api/views/profiles.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/apps/api/views/profiles.py b/src/apps/api/views/profiles.py index c841df941..6492a5efb 100644 --- a/src/apps/api/views/profiles.py +++ b/src/apps/api/views/profiles.py @@ -234,11 +234,18 @@ def validate_invite(self, request): def delete_organization(self, request, pk=None): try: org = Organization.objects.get(id=pk) - org.delete() - return Response({ - "success": True, - "message": "Organization deleted!" - }) + 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,