diff --git a/src/servala/core/models/organization.py b/src/servala/core/models/organization.py index fec3fa4..6fd6c67 100644 --- a/src/servala/core/models/organization.py +++ b/src/servala/core/models/organization.py @@ -27,12 +27,6 @@ class Organization(ServalaModelMixin, models.Model): verbose_name=_("Members"), ) - def set_owner(self, user): - OrganizationMembership.objects.filter(user=user, organization=self).delete() - OrganizationMembership.objects.create( - user=user, organization=self, role=OrganizationRole.OWNER - ) - class Meta: verbose_name = _("Organization") verbose_name_plural = _("Organizations") diff --git a/src/servala/frontend/context_processors.py b/src/servala/frontend/context_processors.py deleted file mode 100644 index 1a180d8..0000000 --- a/src/servala/frontend/context_processors.py +++ /dev/null @@ -1,5 +0,0 @@ -def add_organizations(request): - if not request.user.is_authenticated: - return {"user_organizations": []} - - return {"user_organizations": request.user.organizations.all()} diff --git a/src/servala/frontend/forms/__init__.py b/src/servala/frontend/forms/__init__.py deleted file mode 100644 index 8169b61..0000000 --- a/src/servala/frontend/forms/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .organization import OrganizationCreateForm - -__all__ = ["OrganizationCreateForm"] diff --git a/src/servala/frontend/forms/organization.py b/src/servala/frontend/forms/organization.py deleted file mode 100644 index b6a3391..0000000 --- a/src/servala/frontend/forms/organization.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.forms import ModelForm - -from servala.core.models import Organization - - -class OrganizationCreateForm(ModelForm): - class Meta: - model = Organization - fields = ("name",) diff --git a/src/servala/frontend/forms/renderers.py b/src/servala/frontend/forms/renderers.py deleted file mode 100644 index f8cdb5d..0000000 --- a/src/servala/frontend/forms/renderers.py +++ /dev/null @@ -1,28 +0,0 @@ -from django.forms.renderers import TemplatesSetting - - -def inject_class(f, class_name): - def inner(*args, **kwargs): - result = f(*args, **kwargs) - class_list = result.get("class", "") - class_list = f"{class_list} {class_name}".strip() - result["class"] = class_list - return result - - return inner - - -class VerticalFormRenderer(TemplatesSetting): - form_template_name = "frontend/forms/form.html" - field_template_name = "frontend/forms/vertical_field.html" - - def render(self, template_name, context, request=None): - if field := context.get("field"): - if field.field.widget.input_type == "checkbox": - class_name = "form-check-input" - else: - class_name = "form-control" - field.build_widget_attrs = inject_class( - field.build_widget_attrs, class_name - ) - return super().render(template_name, context, request) diff --git a/src/servala/frontend/templates/account/login.html b/src/servala/frontend/templates/account/login.html deleted file mode 100644 index 3100278..0000000 --- a/src/servala/frontend/templates/account/login.html +++ /dev/null @@ -1,53 +0,0 @@ -{% extends "frontend/base.html" %} -{% load static i18n %} -{% load allauth account socialaccount %} -{% block html_title %} - {% block page_title %} - {% translate "Sign In" %} - {% endblock page_title %} -{% endblock html_title %} -{% block content %} -
-
-
-
- {% if SOCIALACCOUNT_ENABLED %} - {% get_providers as socialaccount_providers %} - {% if socialaccount_providers %} - {% for provider in socialaccount_providers %} - {% provider_login_url provider process=process scope=scope auth_params=auth_params as href %} -
- {% csrf_token %} - -
- {% endfor %} - {% endif %} - {% endif %} -
- - - {% translate "Log in with email and password instead" %} - -
- {% url 'account_login' as form_action %} - {% translate "Sign In" as form_submit_label %} - {% include "includes/form.html" %} -
-
-
-
-
-
-{% endblock content %} diff --git a/src/servala/frontend/templates/frontend/forms/form.html b/src/servala/frontend/templates/frontend/forms/form.html deleted file mode 100644 index a9e8c47..0000000 --- a/src/servala/frontend/templates/frontend/forms/form.html +++ /dev/null @@ -1,19 +0,0 @@ -{% if errors %} - -{% endif %} -
-
- {% for field, errors in fields %}{{ field.as_field_group }}{% endfor %} - {% for field in hidden_fields %}{{ field }}{% endfor %} -
-
diff --git a/src/servala/frontend/templates/frontend/forms/vertical_field.html b/src/servala/frontend/templates/frontend/forms/vertical_field.html deleted file mode 100644 index bcbf8d6..0000000 --- a/src/servala/frontend/templates/frontend/forms/vertical_field.html +++ /dev/null @@ -1,26 +0,0 @@ -{% load i18n %} -
-
- {% if field.field.widget.input_type != "checkbox" or field.field.widget.allow_multiple_selected %} - - {% endif %} - {% if field.use_fieldset %} -
- {% endif %} - {{ field }} - {% if field.field.widget.input_type == "checkbox" and not field.field.widget.allow_multiple_selected %} - - {% endif %} - {% if field.use_fieldset %}
{% endif %} - {% for text in field.errors %}
{{ text }}
{% endfor %} - {% if field.help_text %} - {{ field.help_text|safe }} - {% endif %} -
-
diff --git a/src/servala/frontend/templates/frontend/organizations/create.html b/src/servala/frontend/templates/frontend/organizations/create.html deleted file mode 100644 index ca46190..0000000 --- a/src/servala/frontend/templates/frontend/organizations/create.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "frontend/base.html" %} -{% load i18n %} -{% block html_title %} - {% block page_title %} - {% translate "Create a new organization" %} - {% endblock page_title %} -{% endblock html_title %} -{% block content %} -
-
-
-
{% include "includes/form.html" %}
-
-
-
-{% endblock content %} diff --git a/src/servala/frontend/templates/includes/form.html b/src/servala/frontend/templates/includes/form.html deleted file mode 100644 index d8a01e5..0000000 --- a/src/servala/frontend/templates/includes/form.html +++ /dev/null @@ -1,14 +0,0 @@ -{% load i18n %} -
- {% csrf_token %} - {{ form }} - -
diff --git a/src/servala/frontend/templates/includes/sidebar.html b/src/servala/frontend/templates/includes/sidebar.html index 8c47293..287977a 100644 --- a/src/servala/frontend/templates/includes/sidebar.html +++ b/src/servala/frontend/templates/includes/sidebar.html @@ -56,67 +56,42 @@ diff --git a/src/servala/frontend/urls.py b/src/servala/frontend/urls.py deleted file mode 100644 index fbaaa08..0000000 --- a/src/servala/frontend/urls.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.urls import path - -from servala.frontend import views - -urlpatterns = [ - path("accounts/profile/", views.ProfileView.as_view(), name="profile"), - path("accounts/logout/", views.LogoutView.as_view(), name="logout"), - path( - "organizations/create", - views.OrganizationCreateView.as_view(), - name="organization.create", - ), - path("", views.IndexView.as_view(), name="index"), -] diff --git a/src/servala/frontend/views/generic.py b/src/servala/frontend/views.py similarity index 100% rename from src/servala/frontend/views/generic.py rename to src/servala/frontend/views.py diff --git a/src/servala/frontend/views/__init__.py b/src/servala/frontend/views/__init__.py deleted file mode 100644 index 20b4398..0000000 --- a/src/servala/frontend/views/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -from .auth import LogoutView -from .generic import IndexView, ProfileView -from .organization import OrganizationCreateView - -__all__ = [ - "IndexView", - "LogoutView", - "OrganizationCreateView", - "ProfileView", -] diff --git a/src/servala/frontend/views/auth.py b/src/servala/frontend/views/auth.py deleted file mode 100644 index 6b351f1..0000000 --- a/src/servala/frontend/views/auth.py +++ /dev/null @@ -1,12 +0,0 @@ -from allauth.account.internal import flows -from allauth.account.utils import get_next_redirect_url -from django.shortcuts import redirect -from django.views import View - - -class LogoutView(View): - - def post(self, request): - flows.logout.logout(request) - url = get_next_redirect_url(request, "next") or "/" - return redirect(url) diff --git a/src/servala/frontend/views/organization.py b/src/servala/frontend/views/organization.py deleted file mode 100644 index 9bc1397..0000000 --- a/src/servala/frontend/views/organization.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.views.generic import FormView - -from servala.frontend.forms import OrganizationCreateForm - - -class OrganizationCreateView(FormView): - form_class = OrganizationCreateForm - template_name = "frontend/organizations/create.html" - - def form_valid(self, form): - form.save() - form.instance.set_owner(self.request.user) - return super().form_valid(form) - - def get_success_url(self): - return "/" diff --git a/src/servala/settings.py b/src/servala/settings.py index 36d7673..785169a 100644 --- a/src/servala/settings.py +++ b/src/servala/settings.py @@ -95,7 +95,6 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - "django.forms", "servala.frontend", "allauth", "allauth.account", @@ -113,9 +112,7 @@ MIDDLEWARE = [ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "allauth.account.middleware.AccountMiddleware", - "django.contrib.auth.middleware.LoginRequiredMiddleware", ] -LOGIN_URL = "account_login" ROOT_URLCONF = "servala.urls" STATIC_URL = "static/" # CSS, JavaScript, etc. @@ -147,23 +144,22 @@ TEMPLATES = [ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "django.template.context_processors.static", - "servala.frontend.context_processors.add_organizations", ], "loaders": template_loaders, }, }, ] -FORM_RENDERER = "servala.frontend.forms.renderers.VerticalFormRenderer" MESSAGE_TAGS = { messages.ERROR: "danger", } AUTH_USER_MODEL = "core.User" ACCOUNT_USER_MODEL_USERNAME_FIELD = None +ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_UNIQUE_EMAIL = True -ACCOUNT_LOGIN_METHODS = {"email"} -ACCOUNT_SIGNUP_FIELDS = ["email*", "password1*", "password2*"] +ACCOUNT_USERNAME_REQUIRED = False +ACCOUNT_AUTHENTICATION_METHOD = "email" AUTHENTICATION_BACKENDS = [ # Needed to login by username in Django admin, regardless of `allauth` diff --git a/src/servala/static/img/keycloak.svg b/src/servala/static/img/keycloak.svg deleted file mode 100644 index cdcd0fa..0000000 --- a/src/servala/static/img/keycloak.svg +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/src/servala/urls.py b/src/servala/urls.py index d1d40ec..8ddedb6 100644 --- a/src/servala/urls.py +++ b/src/servala/urls.py @@ -6,7 +6,7 @@ from django.urls import path from django.urls.conf import include from django.utils.translation import gettext_lazy as _ -from servala.frontend import urls +from servala.frontend import views admin.site.site_title = _("Servala Admin") admin.site.site_header = _("Servala Management") @@ -14,12 +14,13 @@ admin.site.index_title = _("Dashboard") admin.site.login = secure_admin_login(admin.site.login) urlpatterns = [ - path("admin/", admin.site.urls), - path("", include((urls, "servala.frontend"), namespace="frontend")), # This adds the allauth urls to the project: # - accounts/keycloak/login/ # - accounts/keycloak/login/callback/ path("accounts/", include("allauth.urls")), + path("accounts/profile/", views.ProfileView.as_view(), name="profile"), + path("admin/", admin.site.urls), + path("", views.IndexView.as_view(), name="index"), ] # Serve static and media files in development