api.admin.controller package¶
Submodules¶
api.admin.controller.admin_auth_services module¶
- class api.admin.controller.admin_auth_services.AdminAuthServicesController(manager)[source]¶
Bases:
SettingsController
- process_admin_auth_services()[source]¶
Fetch, create, or update admin_auth_services
- Returns:
dict: if Get request returns a dict of auth services and protocols Response: If POST request updates or creates auth services and protocols.
- process_delete(protocol)[source]¶
Delete an auth service from the database
- Args:
protocol (string): Name of protocol to search for the service to be deleted.
- Returns:
Response: (‘Deleted’, 200)
- process_get()[source]¶
Return dict of auth services and protocols available to library
- Returns:
dict: auth_services and protocols available
api.admin.controller.analytics_services module¶
- class api.admin.controller.analytics_services.AnalyticsServicesController(manager)[source]¶
Bases:
SettingsController
api.admin.controller.catalog_services module¶
- class api.admin.controller.catalog_services.CatalogServicesController(manager)[source]¶
Bases:
SettingsController
api.admin.controller.cdn_services module¶
- class api.admin.controller.cdn_services.CDNServicesController(manager)[source]¶
Bases:
SettingsController
api.admin.controller.collection_library_registrations module¶
- class api.admin.controller.collection_library_registrations.CollectionLibraryRegistrationsController(manager)[source]¶
Bases:
SettingsController
Use the OPDS Directory Registration Protocol to register a Collection with its remote source of truth.
- Parameters:
registration_class – Mock class to use instead of Registration.
- get_library_info(library, collection)[source]¶
Find the relevant information about the library which the user is trying to register
- look_up_collection(collection_id)[source]¶
Find the collection that the user is trying to register the library with, and check that it actually exists.
- look_up_library(library_short_name)[source]¶
Find the library the user is trying to register, and check that it actually exists.
- look_up_registry(external_integration)[source]¶
Find the remote registry that the user is trying to register the collection with, and check that it is in the list of recognized protocols (currently just SharedODLAPI)
api.admin.controller.collection_self_tests module¶
- class api.admin.controller.collection_self_tests.CollectionSelfTestsController(manager)[source]¶
Bases:
SelfTestsController
- get_info(collection)[source]¶
Compile information about this collection, including the results from the last time, if ever, that the self tests were run.
api.admin.controller.collection_settings module¶
- class api.admin.controller.collection_settings.CollectionSettingsController(manager)[source]¶
Bases:
SettingsController
- find_protocol_class(collection_object)[source]¶
Figure out which class this collection’s protocol belongs to, from the list of possible protocols defined in PROVIDER_APIS (in SettingsController)
- load_libraries(collection_object, user, protocol)[source]¶
Get a list of the libraries that 1) are associated with this collection and 2) the user is affiliated with
- load_settings(protocol_settings, collection_object, collection_settings)[source]¶
Compile the information about the collection that corresponds to the settings externally imposed by the collection’s protocol.
- process_libraries(protocol, collection)[source]¶
Go through the libraries that the user is trying to associate with this collection; check that each library actually exists, and that the library-related configuration settings that the user has submitted are complete and valid. If the library passes all of the validations, go ahead and associate it with this collection.
- process_settings(settings, collection)[source]¶
Go through the settings that the user has just submitted for this collection, and check that each setting is valid and that no required settings are missing. If the setting passes all of the validations, go ahead and set it for this collection.
- validate_collection(**fields)[source]¶
The protocol of an existing collection cannot be changed, and collections must have unique names.
- validate_external_account_id_setting(value, setting)[source]¶
Check that the user has submitted any required values for associating this collection with an external account.
- validate_form_fields(is_new, protocols, **fields)[source]¶
Check that 1) the required fields aren’t blank, 2) the protocol is on the list of recognized protocols, 3) the collection (if there is one) is valid, and 4) the URL is valid
- validate_parent(protocol, collection)[source]¶
Verify that the parent collection is set properly, then determine the type of the settings that need to be validated: are they 1) settings for a regular collection (e.g. client key and client secret for an Overdrive collection), or 2) settings for a child collection (e.g. library ID for an Overdrive Advantage collection)?
api.admin.controller.discovery_service_library_registrations module¶
- class api.admin.controller.discovery_service_library_registrations.DiscoveryServiceLibraryRegistrationsController(manager)[source]¶
Bases:
SettingsController
List the libraries that have been registered with a specific RemoteRegistry, and allow the admin to register a library with a RemoteRegistry.
- Parameters:
registration_class – Mock class to use instead of Registration.
- get_library_info(registration)[source]¶
Find the relevant information about the library which the user is trying to register
- look_up_library(library_short_name)[source]¶
Find the library the user is trying to register, and check that it actually exists.
- look_up_registry(integration_id)[source]¶
Find the RemoteRegistry that the user is trying to register the library with, and check that it actually exists.
- process_discovery_service_library_registrations(registration_class=None, do_get=<bound method HTTP.debuggable_get of <class 'core.util.http.HTTP'>>, do_post=<bound method HTTP.debuggable_post of <class 'core.util.http.HTTP'>>)[source]¶
api.admin.controller.discovery_services module¶
- class api.admin.controller.discovery_services.DiscoveryServicesController(manager)[source]¶
Bases:
SettingsController
- look_up_service_from_registry(protocol, id)[source]¶
Find an existing service, and make sure that the user is not trying to edit its protocol.
api.admin.controller.individual_admin_settings module¶
- class api.admin.controller.individual_admin_settings.IndividualAdminSettingsController(manager)[source]¶
Bases:
SettingsController
- check_permissions(admin, settingUp)[source]¶
Before going any further, check that the user actually has permission to create/edit this type of admin
- handle_password(password, admin, is_new, settingUp)[source]¶
Check that the user has permission to change this type of admin’s password
- handle_roles(admin, roles, settingUp)[source]¶
Compare the admin’s existing set of roles against the roles submitted in the form, and, unless there’s a problem with the roles or the permissions, modify the admin’s roles accordingly
- look_up_library_for_role(role)[source]¶
If the role is affiliated with a particular library, as opposed to being sitewide, find the library (and check that it actually exists).
api.admin.controller.library_settings module¶
- class api.admin.controller.library_settings.LibrarySettingsController(manager)[source]¶
Bases:
SettingsController
- check_web_color_contrast(settings)[source]¶
Verify that the web primary and secondary color both contrast well on white, as these colors will serve as button backgrounds with white test, as well as text color on white backgrounds.
- current_value(setting, library)[source]¶
Retrieve the current value of the given setting from the database.
- image_setting(setting)[source]¶
Retrieve an uploaded image for the given setting from the current HTTP request.
- library_configuration_settings(library, validators_by_format, settings=None)[source]¶
Validate and update a library’s configuration settings based on incoming new values.
- Parameters:
library – A Library
validators_by_format – A dictionary mapping the ‘format’ field from a setting configuration to a corresponding validator object.
settings – A list of setting configurations to use in tests instead of Configuration.LIBRARY_SETTINGS
- list_setting(setting, json_objects=False)[source]¶
Retrieve the list of values for the given setting from the current HTTP request.
- Parameters:
json_objects – If this is True, the incoming settings are JSON-encoded objects and not regular strings.
- Returns:
A JSON-encoded string encoding the list of values set for the given setting in the current request.
api.admin.controller.metadata_service_self_tests module¶
Self-tests for metadata integrations.
api.admin.controller.metadata_services module¶
- class api.admin.controller.metadata_services.MetadataServicesController(manager)[source]¶
Bases:
SitewideRegistrationController
- process_post(do_get=<bound method HTTP.debuggable_get of <class 'core.util.http.HTTP'>>, do_post=<bound method HTTP.debuggable_post of <class 'core.util.http.HTTP'>>)[source]¶
api.admin.controller.patron_auth_service_self_tests module¶
api.admin.controller.patron_auth_services module¶
- class api.admin.controller.patron_auth_services.PatronAuthServicesController(manager)[source]¶
Bases:
SettingsController
- check_external_type(library, auth_service)[source]¶
Check that the library’s external type regular expression is valid, if it was set.
- check_identifier_restriction(library, auth_service)[source]¶
Check whether the library’s identifier restriction regular expression is set and is supposed to be a regular expression; if so, check that it’s valid.
- check_libraries(auth_service)[source]¶
Run the three library validation methods on each of the libraries for which the user is trying to configure this patron auth service.
api.admin.controller.search_service_self_tests module¶
api.admin.controller.self_tests module¶
- class api.admin.controller.self_tests.SelfTestsController(manager)[source]¶
Bases:
SettingsController
api.admin.controller.sitewide_services module¶
- class api.admin.controller.sitewide_services.LoggingServicesController(manager)[source]¶
Bases:
SitewideServicesController
- class api.admin.controller.sitewide_services.SearchServicesController(manager)[source]¶
Bases:
SitewideServicesController
- class api.admin.controller.sitewide_services.SitewideServicesController(manager)[source]¶
Bases:
SettingsController
api.admin.controller.sitewide_settings module¶
api.admin.controller.storage_services module¶
api.admin.controller.work_editor module¶
- class api.admin.controller.work_editor.WorkController(manager)[source]¶
Bases:
AdminCirculationManagerController
- BOTTOM = 'bottom'¶
- CENTER = 'center'¶
- MINIMUM_COVER_HEIGHT = 900¶
- MINIMUM_COVER_WIDTH = 600¶
- STAFF_WEIGHT = 1000¶
- TITLE_POSITIONS = ['top', 'center', 'bottom']¶
- TOP = 'top'¶
- change_book_cover(identifier_type, identifier, mirrors=None)[source]¶
Save a new book cover based on the submitted form.
- classifications(identifier_type, identifier)[source]¶
Return list of this work’s classifications.
- Args:
identifier_type (string): Type of identifier e.g ISBN identifier (string): Identifier for a work
- Returns:
dict: A dict of work with list of classifications for the work.
- details(identifier_type, identifier)[source]¶
Return an OPDS entry with detailed information for admins.
This includes relevant links for editing the book.
- Returns:
An OPDSEntryResponse
- edit_classifications(identifier_type, identifier)[source]¶
Edit a work’s audience, target age, fiction status, and genres.
- preview_book_cover(identifier_type, identifier)[source]¶
Return a preview of the submitted cover image information.
- refresh_metadata(identifier_type, identifier, provider=None)[source]¶
Refresh the metadata for a book from the content server
- resolve_complaints(identifier_type, identifier)[source]¶
Resolve all complaints for a particular license pool and complaint type.
Module contents¶
- class api.admin.controller.AdminCirculationManagerController(manager)[source]¶
Bases:
CirculationManagerController
Parent class that provides methods for verifying an admin’s roles.
- class api.admin.controller.AdminController(manager)[source]¶
Bases:
object
- admin_auth_provider(type)[source]¶
Return an auth provider with the given type. If no auth provider has this type, return None.
- property admin_auth_providers¶
- class api.admin.controller.DashboardController(manager)[source]¶
- class api.admin.controller.PatronController(manager)[source]¶
- class api.admin.controller.SettingsController(manager)[source]¶
Bases:
AdminCirculationManagerController
- METADATA_SERVICE_URI_TYPE = 'application/opds+json;profile=https://librarysimplified.org/rel/profile/metadata-service'¶
- NO_MIRROR_INTEGRATION = 'NO_MIRROR'¶
- PROVIDER_APIS = [<class 'core.opds_import.OPDSImporter'>, <class 'api.opds_for_distributors.OPDSForDistributorsAPI'>, <class 'core.opds2_import.OPDS2Importer'>, <class 'api.proquest.importer.ProQuestOPDS2Importer'>, <class 'api.overdrive.OverdriveAPI'>, <class 'api.odilo.OdiloAPI'>, <class 'api.bibliotheca.BibliothecaAPI'>, <class 'api.axis.Axis360API'>, <class 'api.rbdigital.RBDigitalAPI'>, <class 'api.enki.EnkiAPI'>, <class 'api.odl.ODLAPI'>, <class 'api.odl.SharedODLAPI'>, <class 'api.feedbooks.FeedbooksOPDSImporter'>, <class 'api.lcp.collection.LCPAPI'>]¶
- check_name_unique(new_service, name)[source]¶
A service cannot be created with, or edited to have, the same name as a service that already exists. This method is used by analytics_services, cdn_services, discovery_services, metadata_services, and sitewide_services.
- check_url_unique(new_service, url, protocol, goal)[source]¶
Enforce a rule that a given circulation manager can only have one integration that uses a given URL for a certain purpose.
Whether to enforce this rule for a given type of integration is up to you – it’s a good general rule but there are conceivable exceptions.
This method is used by discovery_services.
- look_up_service_by_id(id, protocol, goal=None)[source]¶
Find an existing service, and make sure that the user is not trying to edit its protocol. This method is used by analytics_services, cdn_services, metadata_services, and sitewide_services.
- set_protocols(service, protocol, protocols=None)[source]¶
Validate the protocol that the user has submitted; depending on whether the validations pass, either save it to this metadata service or return an error message. This method is used by analytics_services, cdn_services, discovery_services, metadata_services, and sitewide_services.
- classmethod url_variants(url, check_protocol_variant=True)[source]¶
Generate minor variants of a URL – HTTP vs HTTPS, trailing slash vs not, etc.
Technically these are all distinct URLs, but in real life they generally mean someone typed the same URL slightly differently. Since this isn’t an exact science, this doesn’t need to catch all variant URLs, only the most common ones.
- class api.admin.controller.SignInController(manager)[source]¶
Bases:
AdminController
- ERROR_RESPONSE_TEMPLATE = '<!DOCTYPE HTML><html lang="en"><head><meta charset="utf8"></head><body style="\n margin: 10vh auto;\n font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;\n padding: 25px 15px;\n width: 40vw;\n color: #403d37;\n border: 1px solid #DDD;\n border-radius: 4px;\n display: flex;\n flex-direction: column;\n align-items: center;\n\n border-color: #D0343A;\n"><p><strong>%(status_code)d ERROR:</strong> %(message)s</p><hr style="\n width: 10vw;\n margin: 3px 0 0 0;\n border: none;\n border-bottom: 1px solid #403d37;\n"><a href="/admin/sign_in" style="\n background: #1B7FA7;\n text-align: center;\n text-decoration: none;\n border-color: #1B7FA7;\n border-radius: .25em;\n color: #fff;\n padding: 10px;\n font-size: 1rem;\n cursor: pointer;\n display: block;\n width: 25vw;\n margin: 2vh auto;\n\n width: 5vw;\n margin-bottom: 0;\n">Try again</a></body></html>'¶
- SIGN_IN_TEMPLATE = '<!DOCTYPE HTML><html lang="en"><head><meta charset="utf8"></head><body style="\n margin: 10vh auto;\n font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;\n padding: 25px 15px;\n width: 40vw;\n color: #403d37;\n border: 1px solid #DDD;\n border-radius: 4px;\n display: flex;\n flex-direction: column;\n align-items: center;\n"><h1>Library Simplified</h1>%(auth_provider_html)s</body></html>'¶
- class api.admin.controller.SitewideRegistrationController(manager)[source]¶
Bases:
SettingsController
A controller for managing a circulation manager’s registrations with external services.
Currently the only supported site-wide registration is with a metadata wrangler. The protocol for registration with library registries and ODL collections is similar, but those registrations happen on the level of the individual library, not on the level of the circulation manager.
- check_content_type(catalog_response)[source]¶
Make sure the catalog for the service is in a valid format.
Find the shared secret which we need to use in order to register this service, or return an error message if there is no shared secret.
- process_sitewide_registration(integration, do_get=<bound method HTTP.debuggable_get of <class 'core.util.http.HTTP'>>, do_post=<bound method HTTP.debuggable_post of <class 'core.util.http.HTTP'>>)[source]¶
Performs a sitewide registration for a particular service.
- Returns:
A ProblemDetail or, if successful, None
- register(register_url, headers, do_post)[source]¶
Register this server using the sitewide registration document.
- class api.admin.controller.TimestampsController(manager)[source]¶
Bases:
AdminCirculationManagerController
Returns a dict: each key is a type of service (script, monitor, or coverage provider); each value is a nested dict in which timestamps are organized by service name and then by collection ID.
- class api.admin.controller.ViewController(manager)[source]¶
Bases:
AdminController