api.admin package

Subpackages

Submodules

api.admin.admin_authentication_provider module

class api.admin.admin_authentication_provider.AdminAuthenticationProvider(integration)[source]

Bases: object

active_credentials(admin)[source]
sign_in_template(redirect_url)[source]

api.admin.announcement_list_validator module

class api.admin.announcement_list_validator.AnnouncementListValidator(maximum_announcements=3, minimum_announcement_length=15, maximum_announcement_length=350, default_duration_days=60)[source]

Bases: Validator

DATE_FORMAT = '%Y-%m-%d'
format_as_string(value)[source]

Format the output of validate_announcements for storage in ConfigurationSetting.value

validate_announcement(announcement)[source]
validate_announcements(announcements)[source]
classmethod validate_date(field, value, minimum=None)[source]

Validate a date value.

Parameters:
  • field – Name of the field, used in error details.

  • value – Proposed value for the field.

  • minimum – The proposed value must not be earlier than this value.

Returns:

A ProblemDetail if validation fails; otherwise a datetime.date.

classmethod validate_length(value, minimum, maximum)[source]

Validate the length of a string value.

Parameters:
  • value – Proposed value for a field.

  • minimum – Minimum length.

  • maximum – Maximum length.

Returns:

A ProblemDetail if the validation fails; otherwise value.

api.admin.exceptions module

exception api.admin.exceptions.AdminNotAuthorized[source]

Bases: Exception

as_problem_detail_document(debug=False)[source]
status_code = 403

api.admin.geographic_validator module

class api.admin.geographic_validator.GeographicValidator[source]

Bases: Validator

ask_registry(service_area_object, db, do_get=<bound method HTTP.debuggable_get of <class 'core.util.http.HTTP'>>)[source]
find_location_through_registry(value, db)[source]
format_as_string(value)[source]

Format the output of validate_geographic_areas for storage in ConfigurationSetting.value.

format_place(zip, city, state_or_province)[source]
is_zip(value, country)[source]
look_up_zip(zip, country, formatted=False)[source]
validate_geographic_areas(values, db)[source]

api.admin.google_oauth_admin_authentication_provider module

class api.admin.google_oauth_admin_authentication_provider.DummyGoogleClient(email='example@nypl.org')[source]

Bases: object

Mock Google OAuth client for testing

class Credentials(email)[source]

Bases: object

Mock OAuth2Credentials object for testing

access_token_expired = False
from_json(credentials)[source]
to_json()[source]
expired = False
flow_from_client_secrets(config, scope=None, redirect_uri=None)[source]
step1_get_authorize_url(state)[source]
step2_exchange(auth_code)[source]
class api.admin.google_oauth_admin_authentication_provider.GoogleOAuthAdminAuthenticationProvider(integration, redirect_uri, test_mode=False)[source]

Bases: AdminAuthenticationProvider

DESCRIPTION = l'How to Configure a Google OAuth Integration'
DOMAINS = 'domains'
INSTRUCTIONS = l'<p>Configuring a Google OAuth integration in the Circulation Manager will allow admins to sign into the Admin interface with their Google/GMail credentials.</p><p>Configure the Google OAuth Service: </p><ol><li>To use this integration, visit the <a href='https://console.developers.google.com/apis/dashboard?pli=1' rel='noopener' rel='noreferer' target='_blank'>Google developer console.</a> Create a project, click 'Create Credentials' in the left sidebar, and select 'OAuth client ID'. If you get a warning about the consent screen, click 'Configure consent screen' and enter your library name as the product name. Save the consent screen information.</li><li>Choose 'Web Application' as the application type.</li><li>Leave 'Authorized JavaScript origins' blank, but under 'Authorized redirect URIs', add the url of your circulation manager followed by '/admin/GoogleAuth/callback', e.g. 'http://mycircmanager.org/admin/GoogleAuth/callback'.</li><li>Click create, and you'll get a popup with your new client ID and secret. Copy these values and enter them in the form below.</li></ol>'
LIBRARY_SETTINGS = [{'key': 'domains', 'label': l'Allowed Domains', 'description': l'Anyone who logs in with an email address from one of these domains will automatically have librarian-level access to this library. Library manager roles must still be granted individually by other admins. If you want to set up admins individually but still allow them to log in with Google, you can create the admin authentication service without adding any libraries.', 'type': 'list'}]
NAME = 'Google OAuth'
SETTINGS = [{'key': 'url', 'label': l'Authentication URI', 'default': 'https://accounts.google.com/o/oauth2/auth', 'required': True, 'format': 'url'}, {'key': 'username', 'label': l'Client ID', 'required': True}, {'key': 'password', 'label': l'Client Secret', 'required': True}]
SITEWIDE = True
TEMPLATE = "\n        <a 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' href=%(auth_uri)s>Sign in with Google</a>\n    "
active_credentials(admin)[source]

Check that existing credentials aren’t expired

auth_uri(redirect_url)[source]
callback(_db, request={})[source]

Google OAuth sign-in flow

property client
property domains
google_error_problem_detail(error)[source]
sign_in_template(redirect_url)[source]
staff_email(_db, email)[source]

api.admin.opds module

class api.admin.opds.AdminAnnotator(circulation, library, test_mode=False)[source]

Bases: LibraryAnnotator

annotate_feed(feed)[source]

Make any custom modifications necessary to integrate this OPDS feed into the application’s workflow.

annotate_work_entry(work, active_license_pool, edition, identifier, feed, entry)[source]

Make any custom modifications necessary to integrate this OPDS entry into the application’s workflow.

Work:

The Work whose OPDS entry is being annotated.

Active_license_pool:

Of all the LicensePools associated with this Work, the client has expressed interest in this one.

Edition:

The Edition to use when associating bibliographic metadata with this entry. You will probably not need to use this, because bibliographic metadata was associated with the entry when it was created.

Identifier:

Of all the Identifiers associated with this Work, the client has expressed interest in this one.

Parameters:
  • feed – An OPDSFeed – the feed in which this entry will be situated.

  • entry – An lxml Element object, the entry that will be added to the feed.

complaints_url(facets, pagination)[source]
suppressed_url(pagination)[source]
class api.admin.opds.AdminFeed(_db, title, url, works, annotator=None, precomposed_entries=[])[source]

Bases: AcquisitionFeed

classmethod complaints(library, title, url, annotator, pagination=None)[source]
classmethod suppressed(_db, title, url, annotator, pagination=None)[source]

api.admin.password_admin_authentication_provider module

class api.admin.password_admin_authentication_provider.PasswordAdminAuthenticationProvider(integration)[source]

Bases: AdminAuthenticationProvider

NAME = 'Password Auth'
TEMPLATE = '\n<form action="%(password_sign_in_url)s" method="post">\n<input type="hidden" name="redirect" value="%(redirect)s"/>\n<label style="\n    font-weight: 700;\n">Email <input type="text" name="email" style="\n    border-radius: .25em;\n    display: block;\n    padding: 10px;\n    border: 1px solid #403d37;\n    box-shadow: none;\n    font-size: 1rem;\n    margin: 1vh 0 3vh 0;\n    width: 25vw;\n" /></label>\n<label style="\n    font-weight: 700;\n">Password <input type="password" name="password" style="\n    border-radius: .25em;\n    display: block;\n    padding: 10px;\n    border: 1px solid #403d37;\n    box-shadow: none;\n    font-size: 1rem;\n    margin: 1vh 0 3vh 0;\n    width: 25vw;\n" /></label>\n<button type="submit" style="\n    background: #1B7FA7;\n    border-color: transparent;\n    border-radius: .25em;\n    color: #fff;\n    padding: 10px;\n    font-size: 1rem;\n    cursor: pointer;\n    display: block;\n    width: 100%%;\n    margin: 2vh auto;\n">Sign In</button>\n</form>'
active_credentials(admin)[source]
sign_in(_db, request={})[source]
sign_in_template(redirect)[source]

api.admin.problem_details module

api.admin.template_styles module

api.admin.templates module

api.admin.validator module

class api.admin.validator.PatronAuthenticationValidatorFactory[source]

Bases: object

Creates Validator instances for particular authentication protocols

VALIDATOR_CLASS_NAME = 'Validator'
VALIDATOR_FACTORY = 'validator_factory'
create(protocol)[source]

Returns a configured validator for a specific protocol

Parameters:

protocol (string) – Patron authentication protocol

Returns:

Validator object (if there is any for the specific protocol)

Return type:

Optional[Validator]

class api.admin.validator.Validator[source]

Bases: object

validate(settings, content)[source]
validate_email(settings, content)[source]

Find any email addresses that the user has submitted, and make sure that they are in a valid format. This method is used by individual_admin_settings and library_settings.

validate_image(settings, content)[source]
validate_language_code(settings, content)[source]
validate_number(settings, content)[source]

Find any numbers that the user has submitted, and make sure that they are 1) actually numbers, 2) positive, and 3) lower than the specified maximum, if there is one.

validate_url(settings, content)[source]

Find any URLs that the user has submitted, and make sure that they are in a valid format.

Module contents