-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'TreyWW:main' into fix/email-as-auth-bug
- Loading branch information
Showing
9 changed files
with
131 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.contrib import messages | ||
from django.shortcuts import render | ||
from django.contrib.auth.decorators import login_required | ||
from django.views.decorators.http import require_http_methods | ||
|
||
from backend.models import Client | ||
from backend.types.htmx import HtmxHttpRequest | ||
|
||
|
||
@require_http_methods(["DELETE"]) | ||
@login_required | ||
def client_delete(request: HtmxHttpRequest, id: int): | ||
try: | ||
client = Client.objects.get(id=id) | ||
except Client.DoesNotExist: | ||
messages.error(request, "Client not found") | ||
return render(request, "pages/clients/dashboard/_table.html", {"delete": True}) | ||
|
||
if not client: | ||
messages.error(request, "Client not found") | ||
return render(request, "pages/clients/dashboard/_table.html", {"delete": True}) | ||
|
||
if ( | ||
not request.user.is_authenticated | ||
or request.user != client.user | ||
or request.user.logged_in_as_team | ||
and request.user.logged_in_as_team != client.organization | ||
): | ||
messages.error(request, "You do not have permission to delete this client") | ||
return render(request, "pages/clients/dashboard/_table.html", {"delete": True}) | ||
|
||
client.delete() | ||
messages.success(request, f'Client "{client.name}" deleted successfully') | ||
|
||
if request.user.logged_in_as_team: | ||
return render( | ||
request, | ||
"pages/clients/dashboard/_table.html", | ||
{"clients": Client.objects.filter(organization=request.user.logged_in_as_team).order_by("-name"), "delete": True}, | ||
) | ||
else: | ||
return render( | ||
request, | ||
"pages/clients/dashboard/_table.html", | ||
{"clients": Client.objects.filter(user=request.user).order_by("-name"), "delete": True}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters