示例#1
0
文件: organization.py 项目: kaydoh/h
    def get_default(self, authority=None):
        """
        Get the default org with an option to create it if missing.

        :param authority: Create an org with this authority if none is found
        :return: The public organization or None.
        """

        query_extra = {"authority": authority} if authority else {}

        default_org = (
            self.session.query(Organization)
            .filter_by(pubid=Organization.DEFAULT_PUBID, **query_extra)
            .one_or_none()
        )

        if not default_org and authority:
            default_org = Organization(
                name="Hypothesis", authority=authority, pubid=Organization.DEFAULT_PUBID
            )

            default_org.logo = (
                importlib_resources.files("h") / "static/images/icons/logo.svg"
            ).read_text()

            self.session.add(default_org)

        return default_org
示例#2
0
    def test_default_property_if_default_organization(self, factories,
                                                      pyramid_request):
        organization = Organization.default(pyramid_request.db)

        organization_context = OrganizationContext(organization,
                                                   pyramid_request)

        assert organization_context.default is True
示例#3
0
    def test_default_property_if_default_organization(self, factories,
                                                      pyramid_request):
        organization = Organization.default(pyramid_request.db)

        organization_resource = OrganizationResource(organization,
                                                     pyramid_request)

        assert organization_resource.default is True
示例#4
0
    def create(self, name, authority, logo=None):
        """
        Create a new organization.

        An organization is a group of groups.

        :param name: the human-readable name of the organization
        :param authority: the authority to which the organization belongs
        :param logo: the logo of the organization in svg format

        :returns: the created organization
        """
        organization = Organization(name=name, authority=authority, logo=logo)
        self.session.add(organization)
        return organization
示例#5
0
    def _create(self,
                name,
                userid,
                description,
                type_flags,
                origins=[],
                add_creator_as_member=False,
                organization=None):
        """
        Create a group and save it to the DB.

        :param name: the human-readable name of the group
        :param userid: the userid of the group creator
        :param description: the description of the group
        :param type_flags: the type of this group
        :param origins: the list of origins that the group will be scoped to
        :param add_creator_as_member: if the group creator should be added as a member
        :param organization: the organization that this group belongs to
        :type organization: h.models.Organization
        """
        creator = self.user_fetcher(userid)
        scopes = [GroupScope(origin=o) for o in origins]
        if organization is None:
            organization = Organization.default(self.session)
        self._validate_authorities_match(creator.authority,
                                         organization.authority)
        group = Group(
            name=name,
            authority=creator.authority,
            creator=creator,
            description=description,
            joinable_by=type_flags.joinable_by,
            readable_by=type_flags.readable_by,
            writeable_by=type_flags.writeable_by,
            scopes=scopes,
            organization=organization,
        )
        self.session.add(group)

        if add_creator_as_member:
            group.members.append(group.creator)

            # Flush the DB to generate group.pubid before publish()ing it.
            self.session.flush()

            self.publish('group-join', group.pubid, group.creator.userid)

        return group
示例#6
0
def default_orgs(db_session):
    return [Organization.default(db_session)]
示例#7
0
def default_org(db_session):
    return Organization.default(db_session)
示例#8
0
def list_orgs_svc(pyramid_config, db_session):
    svc = mock.Mock(spec_set=ListOrganizationsService(db_session))
    svc.organizations.return_value = [Organization.default(db_session)]
    pyramid_config.register_service(svc, name='list_organizations')
    return svc
示例#9
0
def default_org(db_session):
    return Organization.default(db_session)
示例#10
0
def list_orgs_svc(pyramid_config, db_session):
    svc = mock.Mock(spec_set=ListOrganizationsService(db_session))
    svc.organizations.return_value = [Organization.default(db_session)]
    pyramid_config.register_service(svc, name="list_organizations")
    return svc
示例#11
0
def default_orgs(db_session):
    return [
        Organization.default(db_session)
    ]
示例#12
0
    def test_default_property_if_default_organization(self, factories, pyramid_request):
        organization = Organization.default(pyramid_request.db)

        organization_context = OrganizationContext(organization, pyramid_request)

        assert organization_context.default is True