Skip to content

Commit

Permalink
Remove first book auth API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Jan 29, 2024
1 parent 5e5a17c commit 561c939
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 541 deletions.
16 changes: 10 additions & 6 deletions api/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask_pydantic_spec import Response as SpecResponse

from api.admin.config import Configuration as AdminClientConfig
from api.admin.config import OperationalMode

Check warning on line 11 in api/admin/routes.py

View check run for this annotation

Codecov / codecov/patch

api/admin/routes.py#L11

Added line #L11 was not covered by tests
from api.admin.controller.custom_lists import CustomListsController
from api.admin.dashboard_stats import generate_statistics
from api.admin.model.dashboard_statistics import StatisticsResponse
Expand All @@ -18,6 +19,7 @@
)
from api.admin.templates import admin_sign_in_again as sign_in_again_template
from api.app import api_spec, app
from api.controller.static_file import StaticFileController

Check warning on line 22 in api/admin/routes.py

View check run for this annotation

Codecov / codecov/patch

api/admin/routes.py#L22

Added line #L22 was not covered by tests
from api.routes import allows_library, has_library, library_route
from core.app_server import ensure_pydantic_after_problem_detail, returns_problem_detail
from core.util.problem_detail import ProblemDetail, ProblemDetailModel, ProblemError
Expand Down Expand Up @@ -748,9 +750,11 @@ def admin_base(**kwargs):


# This path is used only in debug mode to serve frontend assets.
@app.route("/admin/static/<filename>")
@returns_problem_detail
def admin_static_file(filename):
return app.manager.static_files.static_file(
AdminClientConfig.static_files_directory(), filename
)
if AdminClientConfig.operational_mode() == OperationalMode.development:

@app.route("/admin/static/<filename>")
@returns_problem_detail
def admin_static_file(filename):
return StaticFileController.static_file(

Check warning on line 758 in api/admin/routes.py

View check run for this annotation

Codecov / codecov/patch

api/admin/routes.py#L758

Added line #L758 was not covered by tests
AdminClientConfig.static_files_directory(), filename
)
3 changes: 0 additions & 3 deletions api/circulation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from api.controller.patron_auth_token import PatronAuthTokenController
from api.controller.playtime_entries import PlaytimeEntriesController
from api.controller.profile import ProfileController
from api.controller.static_file import StaticFileController
from api.controller.urn_lookup import URNLookupController
from api.controller.work import WorkController
from api.custom_index import CustomIndexView
Expand Down Expand Up @@ -88,7 +87,6 @@ class CirculationManager(LoggerMixin):
patron_devices: DeviceTokensController
version: ApplicationVersionController
odl_notification_controller: ODLNotificationController
static_files: StaticFileController
playtime_entries: PlaytimeEntriesController

# Admin controllers
Expand Down Expand Up @@ -291,7 +289,6 @@ def setup_one_time_controllers(self):
self.patron_devices = DeviceTokensController(self)
self.version = ApplicationVersionController()
self.odl_notification_controller = ODLNotificationController(self)
self.static_files = StaticFileController(self)
self.patron_auth_token = PatronAuthTokenController(self)
self.playtime_entries = PlaytimeEntriesController(self)

Expand Down
26 changes: 4 additions & 22 deletions api/controller/static_file.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
from __future__ import annotations

import os

import flask

from api.config import Configuration
from api.controller.circulation_manager import CirculationManagerController
from core.model import ConfigurationSetting


class StaticFileController(CirculationManagerController):
def static_file(self, directory, filename):
max_age = ConfigurationSetting.sitewide(
self._db, Configuration.STATIC_FILE_CACHE_TIME
).int_value
return flask.send_from_directory(directory, filename, max_age=max_age)

def image(self, filename):
directory = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"..",
"..",
"resources",
"images",
)
return self.static_file(directory, filename)
class StaticFileController:
@staticmethod
def static_file(directory, filename):
return flask.send_from_directory(directory, filename)
175 changes: 0 additions & 175 deletions api/firstbook2.py

This file was deleted.

2 changes: 0 additions & 2 deletions api/integration/registry/patron_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
class PatronAuthRegistry(IntegrationRegistry["AuthenticationProviderType"]):
def __init__(self) -> None:
super().__init__(Goals.PATRON_AUTH_GOAL)
from api.firstbook2 import FirstBookAuthenticationAPI
from api.kansas_patron import KansasAuthenticationAPI
from api.millenium_patron import MilleniumPatronAPI
from api.saml.provider import SAMLWebSSOAuthenticationProvider
Expand All @@ -27,7 +26,6 @@ def __init__(self) -> None:
)
self.register(MilleniumPatronAPI, canonical="api.millenium_patron")
self.register(SIP2AuthenticationProvider, canonical="api.sip")
self.register(FirstBookAuthenticationAPI, canonical="api.firstbook2")
self.register(KansasAuthenticationAPI, canonical="api.kansas_patron")
self.register(SAMLWebSSOAuthenticationProvider, canonical="api.saml.provider")
self.register(
Expand Down
Binary file removed resources/OpenSans-Bold.ttf
Binary file not shown.
Binary file removed resources/OpenSans-Regular.ttf
Binary file not shown.
Binary file removed resources/images/FirstBookLoginButton280.png
Binary file not shown.
32 changes: 0 additions & 32 deletions tests/api/admin/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from collections.abc import Generator
from pathlib import Path
from typing import Any
from unittest.mock import MagicMock

Expand Down Expand Up @@ -802,37 +801,6 @@ def test_admin_view(self, fixture: AdminRouteFixture):
fixture.assert_request_calls(url, fixture.controller, None, None, path="a/path")


class TestAdminStatic:
CONTROLLER_NAME = "static_files"

@pytest.fixture(scope="function")
def fixture(self, admin_route_fixture: AdminRouteFixture) -> AdminRouteFixture:
admin_route_fixture.set_controller_name(self.CONTROLLER_NAME)
return admin_route_fixture

def test_static_file(self, fixture: AdminRouteFixture):
# Go to the back to the root folder to get the right
# path for the static files.
root_path = Path(__file__).parent.parent.parent.parent
local_path = (
root_path
/ "api/admin/node_modules/@thepalaceproject/circulation-admin/dist"
)

url = "/admin/static/circulation-admin.js"
fixture.assert_request_calls(
url, fixture.controller.static_file, str(local_path), "circulation-admin.js" # type: ignore
)

url = "/admin/static/circulation-admin.css"
fixture.assert_request_calls(
url,
fixture.controller.static_file, # type: ignore
str(local_path),
"circulation-admin.css",
)


def test_returns_json_or_response_or_problem_detail():
@routes.returns_json_or_response_or_problem_detail
def mock_responses(response):
Expand Down
46 changes: 12 additions & 34 deletions tests/api/controller/test_staticfile.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
from __future__ import annotations

import pytest
from werkzeug.exceptions import NotFound

from api.config import Configuration
from core.model import ConfigurationSetting
from tests.fixtures.api_controller import CirculationControllerFixture
from api.controller.static_file import StaticFileController
from tests.fixtures.api_images_files import ImageFilesFixture
from tests.fixtures.flask import FlaskAppFixture


class TestStaticFileController:
def test_static_file(
self,
circulation_fixture: CirculationControllerFixture,
api_image_files_fixture: ImageFilesFixture,
flask_app_fixture: FlaskAppFixture,
):
files = api_image_files_fixture
cache_timeout = ConfigurationSetting.sitewide(
circulation_fixture.db.session, Configuration.STATIC_FILE_CACHE_TIME
)
cache_timeout.value = 10

expected_content = files.sample_data("blue.jpg")
with circulation_fixture.app.test_request_context("/"):
response = circulation_fixture.app.manager.static_files.static_file(
files.directory, "blue.jpg"
)
with flask_app_fixture.test_request_context():
response = StaticFileController.static_file(files.directory, "blue.jpg")

assert 200 == response.status_code
assert "public, max-age=10" == response.headers.get("Cache-Control")
assert expected_content == response.response.file.read()
assert response.status_code == 200
assert response.headers.get("Cache-Control") == "no-cache"
assert response.response.file.read() == expected_content

with circulation_fixture.app.test_request_context("/"):
with flask_app_fixture.test_request_context():
pytest.raises(
NotFound,
circulation_fixture.app.manager.static_files.static_file,
StaticFileController.static_file,
files.directory,
"missing.png",
)

def test_image(
self,
circulation_fixture: CirculationControllerFixture,
resources_files_fixture: ImageFilesFixture,
):
files = resources_files_fixture

filename = "FirstBookLoginButton280.png"
expected_content = files.sample_data(filename)

with circulation_fixture.app.test_request_context("/"):
response = circulation_fixture.app.manager.static_files.image(filename)

assert 200 == response.status_code
assert expected_content == response.response.file.read()
Loading

0 comments on commit 561c939

Please sign in to comment.