Skip to content

Commit

Permalink
Fix removing users from workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 9, 2024
1 parent d20ef41 commit 0984c5f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
6 changes: 5 additions & 1 deletion temba/orgs/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ def derive_queryset(self, **kwargs):


class BaseDeleteModal(OrgObjPermsMixin, SmartDeleteView):
default_template = "smartmin/delete_confirm.html"
submit_button_name = _("Delete")
fields = ("id",)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["submit_button_name"] = self.submit_button_name
return context

def post(self, request, *args, **kwargs):
self.get_object().release(self.request.user)

Expand Down
12 changes: 9 additions & 3 deletions temba/orgs/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class UserCRUDL(SmartCRUDL):
actions = (
"list",
"update",
"remove",
"delete",
"edit",
"forget",
"recover",
Expand Down Expand Up @@ -390,7 +390,7 @@ class Form(forms.ModelForm):
role = forms.ChoiceField(
choices=[(r.code, r.display) for r in (OrgRole.ADMINISTRATOR, OrgRole.EDITOR, OrgRole.AGENT)],
required=True,
label=" ",
label=_("Role"),
widget=SelectWidget(),
)

Expand All @@ -413,15 +413,21 @@ def save(self, obj):
self.request.org.add_user(obj, role)
return obj

class Remove(OrgObjPermsMixin, SmartDeleteView):
class Delete(OrgObjPermsMixin, SmartDeleteView):
permission = "orgs.user_update"
fields = ("id",)
submit_button_name = _("Remove")
cancel_url = "@orgs.user_list"
redirect_url = "@orgs.user_list"

def get_object_org(self):
return self.request.org

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["submit_button_name"] = self.submit_button_name
return context

def post(self, request, *args, **kwargs):
self.request.org.remove_user(self.get_object())

Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions templates/orgs/user_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
{% endblocktrans %}
</temba-alert>
{% endif %}
<form method="get" action="{{ request.path }}" id="search-form">
<temba-textinput placeholder="{% trans "Search" %}" name="search" value="{{ search }}" class="w-full">
</temba-textinput>
<input type="submit" class="hide">
</form>
{% block pre-table %}
<temba-modax header="{{ _("Update User") |escapejs }}" -temba-redirected="refreshUsers" id="update-user">
</temba-modax>
<temba-modax header="{{ _("Remove User") |escapejs }}" -temba-redirected="refreshUsers" id="remove-user">
<temba-modax header="{{ _("Remove User") |escapejs }}" -temba-redirected="refreshUsers" id="delete-user">
</temba-modax>
{% endblock pre-table %}
<form method="get" action="{{ request.path }}" id="search-form">
<temba-textinput placeholder="{% trans "Search" %}" name="search" value="{{ search }}" class="w-full">
</temba-textinput>
<input type="submit" class="hide">
</form>
<div class="mt-4 shadow rounded-lg rounded-bl-none rounded-br-none bg-white">{% include "includes/short_pagination.html" %}</div>
<div class="flex-grow overflow-y-auto shadow">
<table class="list lined scrolled">
Expand All @@ -40,7 +40,7 @@
<td>{{ obj.role.display }}</td>
<td class="w-10">
<div style="visibility:hidden"
onclick="event.stopPropagation(); showRemoveUserModal({{ obj.id }});"
onclick="event.stopPropagation(); showDeleteUserModal({{ obj.id }});"
class="pl-2 pt-1 delete-link linked text-gray-400">
<temba-icon name="delete_small">
</temba-icon>
Expand All @@ -65,9 +65,9 @@
modax.open = true;
}

function showRemoveUserModal(id) {
var modax = document.querySelector('#remove-user');
modax.endpoint = `/user/remove/${id}/`;
function showDeleteUserModal(id) {
var modax = document.querySelector('#delete-user');
modax.endpoint = `/user/delete/${id}/`;
modax.open = true;
}
</script>
Expand Down

0 comments on commit 0984c5f

Please sign in to comment.