예제 #1
0
    def validate_email(self):
        # Manually validate an email address, without the admin having to click on a confirmation link
        uuid = flask.request.form.get("uuid")
        email = flask.request.form.get("email")
        library = self.library_for_request(uuid)
        if isinstance(library, ProblemDetail):
            return library
        email_types = {
            "contact_email": Hyperlink.INTEGRATION_CONTACT_REL,
            "help_email": Hyperlink.HELP_REL,
            "copyright_email": Hyperlink.COPYRIGHT_DESIGNATED_AGENT_REL
        }
        hyperlink = None
        if email_types.get(email):
            hyperlink = Library.get_hyperlink(library, email_types[email])
        if not hyperlink or not hyperlink.resource or isinstance(
                hyperlink, ProblemDetail):
            return INVALID_CONTACT_URI.detailed(
                "The contact URI for this library is missing or invalid")
        validation, is_new = get_one_or_create(self._db,
                                               Validation,
                                               resource=hyperlink.resource)
        validation.restart()
        validation.mark_as_successful()

        return self.library_details(uuid)
예제 #2
0
    def library_details(self, uuid, library=None):
        # Return complete information about one specific library.
        if not library:
            library = self.library_for_request(uuid)

        if isinstance(library, ProblemDetail):
            return library

        hyperlink_types = [
            Hyperlink.INTEGRATION_CONTACT_REL, Hyperlink.HELP_REL,
            Hyperlink.COPYRIGHT_DESIGNATED_AGENT_REL
        ]
        hyperlinks = [
            Library.get_hyperlink(library, x) for x in hyperlink_types
        ]
        contact_email, help_email, copyright_email = [
            self._get_email(x) for x in hyperlinks
        ]
        contact_email_validated_at, help_email_validated_at, copyright_email_validated_at = [
            self._validated_at(x) for x in hyperlinks
        ]
        contact_email_hyperlink, help_email_hyperlink, copyright_email_hyperlink = hyperlinks

        basic_info = dict(name=library.name,
                          short_name=library.short_name,
                          description=library.description,
                          timestamp=library.timestamp,
                          internal_urn=library.internal_urn,
                          online_registration=str(library.online_registration),
                          pls_id=library.pls_id.value,
                          number_of_patrons=str(library.number_of_patrons))
        urls_and_contact = dict(
            contact_email=contact_email,
            contact_validated=contact_email_validated_at,
            help_email=help_email,
            help_validated=help_email_validated_at,
            copyright_email=copyright_email,
            copyright_validated=copyright_email_validated_at,
            authentication_url=library.authentication_url,
            opds_url=library.opds_url,
            web_url=library.web_url,
        )
        areas = self._areas(library.service_areas)
        stages = dict(
            library_stage=library._library_stage,
            registry_stage=library.registry_stage,
        )
        return dict(uuid=uuid,
                    basic_info=basic_info,
                    urls_and_contact=urls_and_contact,
                    areas=areas,
                    stages=stages)