Verified Commit 1d0e5ed9 authored by Tom Teichler's avatar Tom Teichler 🍻

[Reformat] Sort imports and fix code style

parent a727fc1e
Pipeline #2548 failed with stages
in 5 minutes and 55 seconds
from typing import Optional, Any
from typing import Any, Optional
from django.apps import AppConfig
from dynamic_preferences.registries import preference_models
from dynamic_preferences.signals import preference_updated
from .registries import (
group_preferences_registry,
site_preferences_registry,
)
from .registries import group_preferences_registry, site_preferences_registry
from .util.sass_helpers import clean_scss
class InfrablueConfig(AppConfig):
name = 'infrablue'
name = "infrablue"
def ready(self):
super().ready()
......@@ -28,13 +24,13 @@ class InfrablueConfig(AppConfig):
preference_models.register(grouppreferencemodel, group_preferences_registry)
def preference_updated(
self,
sender: Any,
section: Optional[str] = None,
name: Optional[str] = None,
old_value: Optional[Any] = None,
new_value: Optional[Any] = None,
**kwargs,
self,
sender: Any,
section: Optional[str] = None,
name: Optional[str] = None,
old_value: Optional[Any] = None,
new_value: Optional[Any] = None,
**kwargs,
) -> None:
if section == "theme":
if name in ("primary", "secondary"):
......@@ -47,7 +43,7 @@ class InfrablueConfig(AppConfig):
if new_value:
Favicon.on_site.update_or_create(
title=name,
defaults={"isFavicon": name == "favicon", "faviconImage": new_value, },
defaults={"isFavicon": name == "favicon", "faviconImage": new_value,},
)
else:
Favicon.on_site.filter(title=name, isFavicon=is_favicon).delete()
......@@ -11,6 +11,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'infrablue.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "infrablue.settings")
application = get_asgi_application()
from django.forms.models import inlineformset_factory
from bigbluebutton.django.models import BigBlueButton, BigBlueButtonGroup
from dynamic_preferences.forms import PreferenceForm
from dynamic_preferences.users.forms import UserPreferenceForm
from bigbluebutton.django.models import BigBlueButton, BigBlueButtonGroup
from .registries import site_preferences_registry, group_preferences_registry
from .registries import group_preferences_registry, site_preferences_registry
ServerFormset = inlineformset_factory(
BigBlueButtonGroup, BigBlueButton, fields=('name', 'url', "salt")
BigBlueButtonGroup, BigBlueButton, fields=("name", "url", "salt")
)
......@@ -22,4 +21,3 @@ class GroupPreferenceForm(PreferenceForm):
"""Form to edit site preferences."""
registry = group_preferences_registry
......@@ -15,7 +15,6 @@ MENUS = {
"icon": "how_to_reg",
"validators": ["menu_generator.validators.is_anonymous"],
},
{
"name": _("Home"),
"url": "index",
......@@ -51,7 +50,7 @@ MENUS = {
"name": _("Backend Admin"),
"url": "admin:index",
"icon": "settings",
"validators": ["menu_generator.validators.is_superuser", ],
"validators": ["menu_generator.validators.is_superuser",],
},
],
},
......@@ -61,6 +60,5 @@ MENUS = {
"icon": "exit_to_app",
"validators": ["menu_generator.validators.is_authenticated"],
},
],
}
from django.db import models
from django.contrib.sites.models import Site
from django.contrib.auth.models import Group
from django.contrib.sites.models import Site
from django.db import models
from dynamic_preferences.models import PerInstancePreferenceModel
......
......@@ -5,14 +5,14 @@ from django.utils.translation import gettext_lazy as _
from dynaconf import LazySettings
ENVVAR_PREFIX_FOR_DYNACONF = 'INFRABLUE'
DIRS_FOR_DYNACONF = ['/etc/infrablue']
ENVVAR_PREFIX_FOR_DYNACONF = "INFRABLUE"
DIRS_FOR_DYNACONF = ["/etc/infrablue"]
SETTINGS_FILE_FOR_DYNACONF = []
for directory in DIRS_FOR_DYNACONF:
SETTINGS_FILE_FOR_DYNACONF += glob(os.path.join(directory, '*.ini'))
SETTINGS_FILE_FOR_DYNACONF += glob(os.path.join(directory, '*.yaml'))
SETTINGS_FILE_FOR_DYNACONF += glob(os.path.join(directory, '*.toml'))
SETTINGS_FILE_FOR_DYNACONF += glob(os.path.join(directory, "*.ini"))
SETTINGS_FILE_FOR_DYNACONF += glob(os.path.join(directory, "*.yaml"))
SETTINGS_FILE_FOR_DYNACONF += glob(os.path.join(directory, "*.toml"))
_settings = LazySettings(
ENVVAR_PREFIX_FOR_DYNACONF=ENVVAR_PREFIX_FOR_DYNACONF,
......@@ -23,7 +23,7 @@ _settings = LazySettings(
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = _settings.get('secret_key', 'DoNotUseInProduction')
SECRET_KEY = _settings.get("secret_key", "DoNotUseInProduction")
DEBUG = _settings.get("maintenance.debug", False)
......@@ -32,27 +32,27 @@ ALLOWED_HOSTS = _settings.get("http.allowed_hosts", [])
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'infrablue.apps.InfrablueConfig',
'material',
'menu_generator',
'django_yarnpkg',
'favicon',
'django_any_js',
'sass_processor',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.sites",
"django.contrib.staticfiles",
"infrablue.apps.InfrablueConfig",
"material",
"menu_generator",
"django_yarnpkg",
"favicon",
"django_any_js",
"sass_processor",
"django_otp.plugins.otp_totp",
"django_otp.plugins.otp_static",
"django_otp",
"otp_yubikey",
"dynamic_preferences",
"dynamic_preferences.users.apps.UserPreferencesConfig",
'bigbluebutton.django.apps.BigbluebuttonConfig',
"bigbluebutton.django.apps.BigbluebuttonConfig",
"django_registration",
"two_factor",
]
......@@ -65,36 +65,36 @@ STATICFILES_FINDERS = [
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sites.middleware.CurrentSiteMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.contrib.sites.middleware.CurrentSiteMiddleware",
]
ROOT_URLCONF = 'infrablue.urls'
ROOT_URLCONF = "infrablue.urls"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"dynamic_preferences.processors.global_preferences",
],
},
},
]
WSGI_APPLICATION = 'infrablue.wsgi.application'
WSGI_APPLICATION = "infrablue.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
......@@ -123,39 +123,29 @@ if _settings.get("caching.memcached.enabled", False):
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
]
# Authentication backends are dynamically populated
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend'
]
AUTHENTICATION_BACKENDS = ["django.contrib.auth.backends.ModelBackend"]
if _settings.get("auth.social", None):
CONTEXT_PROCESSORS = [
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
"social_django.context_processors.backends",
"social_django.context_processors.login_redirect",
]
TEMPLATES[0]["OPTIONS"]["context_processors"].append(CONTEXT_PROCESSORS)
BACKENDS = [
'social_core.backends.open_id.OpenIdAuth',
'social_core.backends.google.GoogleOpenId',
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.google.GoogleOAuth',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.yahoo.YahooOpenId',
"social_core.backends.open_id.OpenIdAuth",
"social_core.backends.google.GoogleOpenId",
"social_core.backends.google.GoogleOAuth2",
"social_core.backends.google.GoogleOAuth",
"social_core.backends.twitter.TwitterOAuth",
"social_core.backends.yahoo.YahooOpenId",
]
AUTHENTICATION_BACKENDS.append(BACKENDS)
......@@ -164,8 +154,12 @@ if _settings.get("auth.social", None):
if _settings.get("ldap.uri", None):
# LDAP dependencies are not necessarily installed, so import them here
import ldap # noqa
from django_auth_ldap.config import LDAPSearch, NestedGroupOfNamesType, NestedGroupOfUniqueNamesType, \
PosixGroupType # noqa
from django_auth_ldap.config import (
LDAPSearch,
NestedGroupOfNamesType,
NestedGroupOfUniqueNamesType,
PosixGroupType,
) # noqa
# Enable Django's integration to LDAP
AUTHENTICATION_BACKENDS.append("django_auth_ldap.backend.LDAPBackend")
......@@ -196,7 +190,10 @@ if _settings.get("ldap.uri", None):
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
_settings.get("ldap.groups.base"),
ldap.SCOPE_SUBTREE,
_settings.get("ldap.groups.filter", "(objectClass=%s)" % _settings.get("ldap.groups.type", "groupOfNames")),
_settings.get(
"ldap.groups.filter",
"(objectClass=%s)" % _settings.get("ldap.groups.type", "groupOfNames"),
),
)
_group_type = _settings.get("ldap.groups.type", "groupOfNames").lower()
......@@ -207,16 +204,20 @@ if _settings.get("ldap.uri", None):
elif _group_type == "posixgroup":
AUTH_LDAP_GROUP_TYPE = PosixGroupType()
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
}
AUTH_LDAP_USER_FLAGS_BY_GROUP = {}
for _flag in ["is_active", "is_staff", "is_superuser"]:
_dn = _settings.get("ldap.groups.flags.%s" % _flag, None)
if _dn:
AUTH_LDAP_USER_FLAGS_BY_GROUP[_flag] = _dn
# Backend admin requires superusers to also be staff members
if "is_superuser" in AUTH_LDAP_USER_FLAGS_BY_GROUP and "is_staff" not in AUTH_LDAP_USER_FLAGS_BY_GROUP:
AUTH_LDAP_USER_FLAGS_BY_GROUP["is_staff"] = AUTH_LDAP_USER_FLAGS_BY_GROUP["is_superuser"]
if (
"is_superuser" in AUTH_LDAP_USER_FLAGS_BY_GROUP
and "is_staff" not in AUTH_LDAP_USER_FLAGS_BY_GROUP
):
AUTH_LDAP_USER_FLAGS_BY_GROUP["is_staff"] = AUTH_LDAP_USER_FLAGS_BY_GROUP[
"is_superuser"
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
......
from django.conf import settings
from django.urls import path, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import include, path
from django.views import generic
from django.views.generic import TemplateView
from django.contrib.auth import views as auth_views
from django.contrib import admin
from . import views
from two_factor.urls import urlpatterns as tf_urls
from . import views
urlpatterns = [
path("", include(tf_urls)),
path('', views.index, name="index"),
path('accounts/', include('django_registration.backends.activation.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path("", views.index, name="index"),
path("accounts/", include("django_registration.backends.activation.urls")),
path("accounts/", include("django.contrib.auth.urls")),
path("accounts/logout/", auth_views.LogoutView.as_view(), name="logout"),
path("admin/", admin.site.urls),
path(
......@@ -85,27 +85,14 @@ urlpatterns = [
{"registry_name": "group"},
name="preferences_group",
),
path("server_group/", views.ServerGroupList.as_view(), name="server_group_list",),
path("server_group/create/", views.ServerGroupCreate.as_view(), name="server_group_create",),
path(
"server_group/",
views.ServerGroupList.as_view(),
name="server_group_list",
),
path(
"server_group/create/",
views.ServerGroupCreate.as_view(),
name="server_group_create",
"server_group/<pk>/update/", views.ServerGroupUpdate.as_view(), name="server_group_update",
),
path(
"server_group/<pk>/update/",
views.ServerGroupUpdate.as_view(),
name="server_group_update",
"server_group/<pk>/delete/", views.ServerGroupDelete.as_view(), name="server_group_delete",
),
path(
"server_group/<pk>/delete/",
views.ServerGroupDelete.as_view(),
name="server_group_delete",
),
]
if "social_django" in settings.INSTALLED_APPS:
......
from typing import Optional
from django.contrib import messages
from django.contrib.auth.models import Group, User
from django.core.exceptions import PermissionDenied
from django.http import HttpRequest, HttpResponse, HttpResponseNotFound
from django.shortcuts import redirect, render
from django.core.exceptions import PermissionDenied
from django.contrib.auth.models import User, Group
from django.contrib import messages
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.views.generic.list import ListView
from django.urls import reverse_lazy
from bigbluebutton.django.models import BigBlueButton, BigBlueButtonGroup
from dynamic_preferences.forms import preference_form_builder
from dynamic_preferences.users.registries import user_preferences_registry
from dynamic_preferences.users.forms import UserPreferenceForm
from bigbluebutton.django.models import BigBlueButton, BigBlueButtonGroup
from .forms import (
ServerFormset,
SitePreferenceForm,
GroupPreferenceForm,
)
from .registries import (
site_preferences_registry,
group_preferences_registry,
)
from dynamic_preferences.users.registries import user_preferences_registry
from .forms import GroupPreferenceForm, ServerFormset, SitePreferenceForm
from .registries import group_preferences_registry, site_preferences_registry
from .util.helper import objectgetter_optional
......@@ -34,10 +25,10 @@ def index(request: HttpRequest) -> HttpResponse:
def preferences(
request: HttpRequest,
registry_name: str = "person",
pk: Optional[int] = None,
section: Optional[str] = None,
request: HttpRequest,
registry_name: str = "person",
pk: Optional[int] = None,
section: Optional[str] = None,
) -> HttpResponse:
"""View for changing preferences."""
context = {}
......@@ -92,31 +83,28 @@ def preferences(
class ServerGroupList(ListView):
model = BigBlueButtonGroup
paginate_by = 100
template_name = 'infrablue/server_group_list.html'
fields = ['name', 'apis.name']
template_name = "infrablue/server_group_list.html"
fields = ["name", "apis.name"]
class ServerGroupUpdate(UpdateView):
model = BigBlueButtonGroup
paginate_by = 100
template_name = 'infrablue/server_group_update.html'
template_name = "infrablue/server_group_update.html"
success_url = reverse_lazy("server_group_list")
fields = ['name']
fields = ["name"]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if self.request.POST:
context['servers'] = ServerFormset(
self.request.POST or None,
instance=self.object
)
context["servers"] = ServerFormset(self.request.POST or None, instance=self.object)
else:
context['servers'] = ServerFormset(instance=self.object)
context["servers"] = ServerFormset(instance=self.object)
return context
def form_valid(self, form):
context = self.get_context_data()
servers = context['servers']
servers = context["servers"]
self.object = form.save()
if servers.is_valid():
servers.instance = self.object
......@@ -126,21 +114,21 @@ class ServerGroupUpdate(UpdateView):
class ServerGroupCreate(CreateView):
model = BigBlueButtonGroup
template_name = 'infrablue/server_group_update.html'
template_name = "infrablue/server_group_update.html"
success_url = reverse_lazy("server_group_list")
fields = ['name']
fields = ["name"]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if self.request.POST:
context['servers'] = ServerFormset(self.request.POST or None)
context["servers"] = ServerFormset(self.request.POST or None)
else:
context['servers'] = ServerFormset()
context["servers"] = ServerFormset()
return context
def form_valid(self, form):
context = self.get_context_data()
servers = context['servers']
servers = context["servers"]
self.object = form.save()
if servers.is_valid():
servers.instance = self.object
......@@ -150,6 +138,5 @@ class ServerGroupCreate(CreateView):
class ServerGroupDelete(DeleteView):
model = BigBlueButtonGroup
template_name = 'infrablue/server_group_delete.html'
template_name = "infrablue/server_group_delete.html"
success_url = reverse_lazy("server_group_list")
......@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'infrablue.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "infrablue.settings")
application = get_wsgi_application()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment