Skip to content

Commit

Permalink
Remove SettingsController from IndividualAdminSettingsController (PP-893
Browse files Browse the repository at this point in the history
) (#1635)

* Remove SettingsController from IndividualAdminSettingsController
  • Loading branch information
jonathangreen authored Jan 30, 2024
1 parent 178f69c commit f39f292
Show file tree
Hide file tree
Showing 3 changed files with 328 additions and 287 deletions.
2 changes: 1 addition & 1 deletion api/admin/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setup_admin_controllers(manager: CirculationManager):
)
manager.admin_library_settings_controller = LibrarySettingsController(manager)
manager.admin_individual_admin_settings_controller = (
IndividualAdminSettingsController(manager)
IndividualAdminSettingsController(manager._db)
)
manager.admin_catalog_services_controller = CatalogServicesController(manager)
manager.admin_announcement_service = AnnouncementSettings(manager)
Expand Down
19 changes: 14 additions & 5 deletions api/admin/controller/individual_admin_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import flask
from flask import Response
from flask_babel import lazy_gettext as _
from pydantic import EmailStr, parse_obj_as
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.orm import Session

from api.admin.controller.settings import SettingsController
from api.admin.controller.base import AdminPermissionsControllerMixin
from api.admin.exceptions import AdminNotAuthorized
from api.admin.problem_details import (
ADMIN_AUTH_NOT_CONFIGURED,
INCOMPLETE_CONFIGURATION,
INVALID_EMAIL,
MISSING_ADMIN,
MISSING_PGCRYPTO_EXTENSION,
UNKNOWN_ROLE,
Expand All @@ -19,7 +22,10 @@
from core.util.problem_detail import ProblemDetail


class IndividualAdminSettingsController(SettingsController):
class IndividualAdminSettingsController(AdminPermissionsControllerMixin):
def __init__(self, db: Session):
self._db = db

def process_individual_admins(self):
if flask.request.method == "GET":
return self.process_get()
Expand Down Expand Up @@ -290,9 +296,12 @@ def validate_form_fields(self, email):
_("The email field cannot be blank.")
)

email_error = self.validate_formats(email)
if email_error:
return email_error
try:
parse_obj_as(EmailStr, email)
except ValueError:
return INVALID_EMAIL.detailed(
_('"%(email)s" is not a valid email address.', email=email)
)

def validate_role_exists(self, role):
if role.get("role") not in AdminRole.ROLES:
Expand Down
Loading

0 comments on commit f39f292

Please sign in to comment.