Esempio n. 1
0
    def __init__(self,
                 domain,
                 new_plan_version,
                 changed_privs,
                 date_start=None):
        def get_domain(domain):
            obj = Domain.get_by_name(domain)
            if obj:
                return obj
            else:
                # This could happen in when there is an issue with couch cluster
                #   that makes the obj not available
                time.sleep(5)
                return Domain.get_by_name(domain)

        self.domain = domain if isinstance(domain,
                                           Domain) else get_domain(domain)
        if self.domain is None:
            # This fails down the line anyway
            # and failing now gives a much better traceback
            raise DomainDoesNotExist()
        self.date_start = date_start or datetime.date.today()
        self.new_plan_version = new_plan_version

        self.privileges = [
            x for x in changed_privs if x in self.supported_privileges()
        ]
Esempio n. 2
0
    def __init__(self, domain, new_plan_version, changed_privs, date_start=None):
        self.domain = (
            domain if isinstance(domain, Domain)
            else Domain.get_by_name(domain, strict=True)
        )
        if self.domain is None:
            # This fails down the line anyway
            # and failing now gives a much better traceback
            raise DomainDoesNotExist()
        self.date_start = date_start or datetime.date.today()
        self.new_plan_version = new_plan_version

        self.privileges = [x for x in changed_privs if x in self.supported_privileges()]
Esempio n. 3
0
def link_domains(couch_user, upstream_domain, downstream_domain):
    if not domain_exists(downstream_domain):
        error = gettext("The project space {} does not exist. Verify that the name is correct, and that the "
                        "domain has not been deleted.").format(downstream_domain)
        raise DomainDoesNotExist(error)

    if get_active_domain_link(upstream_domain, downstream_domain):
        error = gettext(
            "The project space {} is already a downstream project space of {}."
        ).format(downstream_domain, upstream_domain)
        raise DomainLinkAlreadyExists(error)

    if not user_has_admin_access_in_all_domains(couch_user, [upstream_domain, downstream_domain]):
        error = gettext("You must be an admin in both project spaces to create a link.")
        raise DomainLinkNotAllowed(error)

    return DomainLink.link_domains(downstream_domain, upstream_domain)