Skip to content

Commit

Permalink
Add a health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Oct 30, 2024
1 parent 749efd4 commit a1b7ba7
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 54 deletions.
2 changes: 2 additions & 0 deletions backend/hub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CommitteeCandidatesListView,
CommitteeOrganizationListView,
ElectorCandidatesListView,
HealthView,
HomeView,
OrganizationDetailView,
OrganizationListView,
Expand All @@ -29,6 +30,7 @@

urlpatterns = [
path("", HomeView.as_view(), name="home"),
path(_("health/"), HealthView.as_view(), name="health"),
path(_("candidates/"), CandidateListView.as_view(), name="candidates"),
path(
_("candidates/register/"),
Expand Down
52 changes: 52 additions & 0 deletions backend/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,58 @@
UserModel = get_user_model()


class HealthView(View):
# noinspection PyMethodMayBeStatic
def get(self, request):
base_response = {
"status": "ok",
"timestamp": datetime.now().isoformat(),
"version": settings.VERSION,
"revision": settings.REVISION,
}

user = request.user

if user.is_anonymous:
return JsonResponse(base_response)

base_response["user"] = {
"email": user.email,
}

if user.organization:
base_response["user"]["organization"] = {
"name": user.organization.name,
"raf": user.organization.registration_number,
}

if not user.is_impersonate and not user.is_staff:
return JsonResponse(base_response)

if user.is_staff:
base_response["user"].update(
{
"is_staff": user.is_staff,
"is_superuser": user.is_superuser,
"is_impersonate": user.is_impersonate,
}
)

if not user.is_impersonate:
return JsonResponse(base_response)

base_response["user"]["is_impersonate"] = user.is_impersonate

base_response["impersonator"] = {
"email": user.impersonator.email,
"is_staff": user.impersonator.is_staff,
"is_superuser": user.impersonator.is_superuser,
"is_impersonate": user.impersonator.is_impersonate,
}

return JsonResponse(base_response)


class MenuMixin(ContextMixin):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down
58 changes: 31 additions & 27 deletions backend/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-29 17:00+0200\n"
"POT-Creation-Date: 2024-10-30 10:15+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -522,7 +522,7 @@ msgstr ""
msgid "I agree to the {terms_url} of the VotONG platform"
msgstr ""

#: hub/forms.py:105 hub/forms.py:188 hub/views.py:409
#: hub/forms.py:105 hub/forms.py:188 hub/views.py:458
msgid "An organization with the same email address is already registered."
msgstr ""

Expand Down Expand Up @@ -1497,110 +1497,114 @@ msgstr ""
msgid "published"
msgstr ""

#: hub/urls.py:32
msgid "candidates/"
#: hub/urls.py:33
msgid "health/"
msgstr ""

#: hub/urls.py:34
msgid "candidates/"
msgstr ""

#: hub/urls.py:36
msgid "candidates/register/"
msgstr ""

#: hub/urls.py:38
#: hub/urls.py:40
msgid "candidates/<int:pk>/"
msgstr ""

#: hub/urls.py:39
#: hub/urls.py:41
msgid "candidates/<int:pk>/vote/"
msgstr ""

#: hub/urls.py:40
#: hub/urls.py:42
msgid "candidates/<int:pk>/support/"
msgstr ""

#: hub/urls.py:41
#: hub/urls.py:43
msgid "candidates/<int:pk>/revoke/"
msgstr ""

#: hub/urls.py:42
#: hub/urls.py:44
msgid "candidates/<int:pk>/status-confirm/"
msgstr ""

#: hub/urls.py:43
#: hub/urls.py:45
msgid "candidates/<int:pk>/update/"
msgstr ""

#: hub/urls.py:44
#: hub/urls.py:46
msgid "candidates/votes/"
msgstr ""

#: hub/urls.py:45
#: hub/urls.py:47
msgid "candidates/results/"
msgstr ""

#: hub/urls.py:47
#: hub/urls.py:49
msgid "candidates/ces-results/"
msgstr ""

#: hub/urls.py:49
#: hub/urls.py:51
msgid "committee/ngos/"
msgstr ""

#: hub/urls.py:50
#: hub/urls.py:52
msgid "committee/candidates/"
msgstr ""

#: hub/urls.py:51
#: hub/urls.py:53
msgid "ngos/"
msgstr ""

#: hub/urls.py:53
#: hub/urls.py:55
msgid "ngos/register"
msgstr ""

#: hub/urls.py:57
#: hub/urls.py:59
msgid "ngos/<int:pk>"
msgstr ""

#: hub/urls.py:58
#: hub/urls.py:60
msgid "ngos/<int:pk>/vote/<str:action>"
msgstr ""

#: hub/urls.py:59
#: hub/urls.py:61
msgid "ngos/<int:pk>/update"
msgstr ""

#: hub/urls.py:60
#: hub/urls.py:62
msgid "ngo-update/<int:pk>"
msgstr ""

#: hub/views.py:69
#: hub/views.py:118
msgid "Thank you! We'll get in touch soon!"
msgstr ""

#: hub/views.py:320
#: hub/views.py:369
#, python-format
msgid ""
"Thank you for signing up! The form you filled in has reached us. Someone "
"from our team will reach out to you as soon as your organization is "
"validated. If you have any further questions, send us a message at %s."
msgstr ""

#: hub/views.py:361
#: hub/views.py:410
msgid ""
"The organization does not have the voting domain set. To be able to vote, "
"please set the voting domain."
msgstr ""

#: hub/views.py:402
#: hub/views.py:451
msgid "You must write a rejection message."
msgstr ""

#: hub/views.py:859
#: hub/views.py:908
#, python-format
msgid "Please wait %(minutes_threshold)s minutes before updating again."
msgstr ""

#: hub/workers/update_organization.py:228
#: hub/workers/update_organization.py:226
msgid "Error updating organization"
msgstr ""

Expand Down
58 changes: 31 additions & 27 deletions backend/locale/ro/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-29 17:00+0200\n"
"POT-Creation-Date: 2024-10-30 10:15+0200\n"
"PO-Revision-Date: 2020-04-23 17:54+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -536,7 +536,7 @@ msgstr "Termeni și condiții"
msgid "I agree to the {terms_url} of the VotONG platform"
msgstr "Sunt de acord cu {terms_url} ale platformei VotONG"

#: hub/forms.py:105 hub/forms.py:188 hub/views.py:409
#: hub/forms.py:105 hub/forms.py:188 hub/views.py:458
msgid "An organization with the same email address is already registered."
msgstr "O organizație cu aceeași adresă de email este deja înregistrată."

Expand Down Expand Up @@ -1558,87 +1558,91 @@ msgstr "publicat la"
msgid "published"
msgstr "publicat"

#: hub/urls.py:32
#: hub/urls.py:33
msgid "health/"
msgstr "health/"

#: hub/urls.py:34
msgid "candidates/"
msgstr "candidatura/"

#: hub/urls.py:34
#: hub/urls.py:36
msgid "candidates/register/"
msgstr "candidatura/inregistrare/"

#: hub/urls.py:38
#: hub/urls.py:40
msgid "candidates/<int:pk>/"
msgstr "candidatura/<int:pk>"

#: hub/urls.py:39
#: hub/urls.py:41
msgid "candidates/<int:pk>/vote/"
msgstr "candidatura/<int:pk>/vot/"

#: hub/urls.py:40
#: hub/urls.py:42
msgid "candidates/<int:pk>/support/"
msgstr "candidatura/<int:pk>/sustinere/"

#: hub/urls.py:41
#: hub/urls.py:43
msgid "candidates/<int:pk>/revoke/"
msgstr "candidatura/<int:pk>/revocare/"

#: hub/urls.py:42
#: hub/urls.py:44
msgid "candidates/<int:pk>/status-confirm/"
msgstr "candidatura/<int:pk>/confirma-starea/"

#: hub/urls.py:43
#: hub/urls.py:45
msgid "candidates/<int:pk>/update/"
msgstr "candidatura/<int:pk>/actualizare/"

#: hub/urls.py:44
#: hub/urls.py:46
msgid "candidates/votes/"
msgstr "candidatura/voturi/"

#: hub/urls.py:45
#: hub/urls.py:47
msgid "candidates/results/"
msgstr "candidatura/rezultate/"

#: hub/urls.py:47
#: hub/urls.py:49
msgid "candidates/ces-results/"
msgstr "candidatura/ces-rezultate/"

#: hub/urls.py:49
#: hub/urls.py:51
msgid "committee/ngos/"
msgstr "comisie/organizatii/"

#: hub/urls.py:50
#: hub/urls.py:52
msgid "committee/candidates/"
msgstr "comisie/candidatura/"

#: hub/urls.py:51
#: hub/urls.py:53
msgid "ngos/"
msgstr "organizatii/"

#: hub/urls.py:53
#: hub/urls.py:55
msgid "ngos/register"
msgstr "organizatii/inregistrare"

#: hub/urls.py:57
#: hub/urls.py:59
msgid "ngos/<int:pk>"
msgstr "organizatii/<int:pk>"

#: hub/urls.py:58
#: hub/urls.py:60
msgid "ngos/<int:pk>/vote/<str:action>"
msgstr "organizatii/<int:pk>/vot/<str:action>"

#: hub/urls.py:59
#: hub/urls.py:61
msgid "ngos/<int:pk>/update"
msgstr "organizatii/<int:pk>/actualizare"

#: hub/urls.py:60
#: hub/urls.py:62
msgid "ngo-update/<int:pk>"
msgstr "org-actualizare/<int:pk>"

#: hub/views.py:69
#: hub/views.py:118
msgid "Thank you! We'll get in touch soon!"
msgstr "Mulțumim! Vă vom contacta în curând!"

#: hub/views.py:320
#: hub/views.py:369
#, python-format
msgid ""
"Thank you for signing up! The form you filled in has reached us. Someone "
Expand All @@ -1649,7 +1653,7 @@ msgstr ""
"noastră vă va contacta imediat ce organizația trece de procesul de validare. "
"Dacă aveți întrebări suplimentare, ne puteți trimite un mesaj la %s."

#: hub/views.py:361
#: hub/views.py:410
msgid ""
"The organization does not have the voting domain set. To be able to vote, "
"please set the voting domain."
Expand All @@ -1658,18 +1662,18 @@ msgstr ""
"exercita votul) pentru a te înscrie ca elector sau pentru a nominaliza un "
"candidat."

#: hub/views.py:402
#: hub/views.py:451
msgid "You must write a rejection message."
msgstr "Trebuie să completați un motiv de respingere."

#: hub/views.py:859
#: hub/views.py:908
#, python-format
msgid "Please wait %(minutes_threshold)s minutes before updating again."
msgstr ""
"Vă rugăm așteptați %(minutes_threshold)s minute înainte de a actualiza din "
"nou organizația."

#: hub/workers/update_organization.py:228
#: hub/workers/update_organization.py:226
msgid "Error updating organization"
msgstr "Eroare la actualizarea organizației"

Expand Down

0 comments on commit a1b7ba7

Please sign in to comment.