Skip to content

Commit

Permalink
API for check NGO URL
Browse files Browse the repository at this point in the history
  • Loading branch information
danniel committed Jan 24, 2024
1 parent 8609ed9 commit 171564f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions backend/donations/views/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from django.core.exceptions import PermissionDenied, BadRequest
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator

from ..models import Ngo
from .base import BaseHandler, AccountHandler


class CheckNgoUrl(AccountHandler):
def get(self, request, *args, **kwargs):
raise NotImplementedError("CheckNgoUrl not implemented yet")
def get(self, request, ngo_url, *args, **kwargs):
# if we don't receive an ngo url or it's not a logged in user or not and admin
if not ngo_url or not request.user and not request.user.is_staff:
raise PermissionDenied()

if not Ngo.objects.filter(slug=ngo_url).count():
return HttpResponse()
else:
raise BadRequest()


class NgosApi(BaseHandler):
Expand Down
3 changes: 2 additions & 1 deletion backend/redirectioneaza/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@
path("contul-meu", MyAccountHandler.as_view(), name="contul-meu"),
path("asociatia", NgoDetailsHandler.as_view(), name="asociatia"),
path("date-cont", MyAccountDetailsHandler.as_view(), name="date-contul-meu"),
# APIs
path("api/ngo/check-url/<ngo_url>", CheckNgoUrl.as_view(), name="api-ngo-check-url"),
#
#
# TODO: all the URLs until END_OF_TODO need to be implemented
#
path("api/ngo/check-url/<ngo_url>", CheckNgoUrl.as_view(), name="api-ngo-check-url"),
path("api/ngo/upload-url", GetUploadUrl.as_view(), name="api-ngo-upload-url"),
path("api/ngo/form/<ngo_url>", GetNgoForm.as_view(), name="api-ngo-form-url"),
path("api/ngo/forms/download", GetNgoForms.as_view(), name="api-ngo-forms"),
Expand Down

0 comments on commit 171564f

Please sign in to comment.