fedora-infra / freeipa-fas

IPA schema extensions for FAS
GNU General Public License v3.0
12 stars 16 forks source link

add blog / website URL attribute #106

Closed ryanlerch closed 4 years ago

ryanlerch commented 4 years ago

add the new faswebsiteurl attribute to fasuser

Resolves: fedora-infra/noggin#188

Signed-off-by: Ryan Lerch rlerch@redhat.com

tiran commented 4 years ago

How about a custom data type for URLs? We can reuse the data type for group page, agreement, mailing list URL, bug tracker etc.

from urllib.parse import urlparse

from ipalib.parameters import Str

class URL(Str):
    kwargs = Str.kwargs + (
        ("url_schemes", frozenset, frozenset({"http", "https"})),
    )

    def _rule_url_scheme(self, _, value):
        try:
            url = urlparse(value)
        except Exception as e:
            return _("cannot parse url '{url}', {error}").format(
                url=value, error=str(e)
            )
        if url.scheme not in self.url_schemes:
            return _(
                "unsupported scheme, url must start with: {scheme}"
            ).format(scheme=", ".join(sorted(self.url_schemes)))
        if not url.netloc:
            return _("empty host name")
        return None
ryanlerch commented 4 years ago

How about a custom data type for URLs? We can reuse the data type for group page, agreement, mailing list URL, bug tracker etc.

from urllib.parse import urlparse

from ipalib.parameters import Str

class URL(Str):
    kwargs = Str.kwargs + (
        ("url_schemes", frozenset, frozenset({"http", "https"})),
    )

    def _rule_url_scheme(self, _, value):
        try:
            url = urlparse(value)
        except Exception as e:
            return _("cannot parse url '{url}', {error}").format(
                url=value, error=str(e)
            )
        if url.scheme not in self.url_schemes:
            return _(
                "unsupported scheme, url must start with: {scheme}"
            ).format(scheme=", ".join(sorted(self.url_schemes)))
        if not url.netloc:
            return _("empty host name")
        return None

okies, updated to do this. the only change from your code above, was changing the def from _rule_url_scheme to _rule_url_schemes. From what i could gather looking at how the _rule code worked in ipalib.parameters, this needed to be the same as the arg (but without the _rule_ part of course)