Ejemplo n.º 1
0
    def add_member_division(self, division, permissions):
        """
        Add a member (team) to a volume.
        :param division: Division object or division identifier.
        :param permissions: Permissions dictionary.
        :return: Member object.
        """
        division = Transform.to_division(division)

        if 'execute' in permissions:
            permissions.pop('execute')

        data = {'username': division, 'type': 'DIVISION'}
        if isinstance(permissions, dict):
            data.update({'permissions': permissions})

        extra = {
            'resource': type(self).__name__,
            'query': {
                'id': self.id,
                'data': data,
            }
        }
        logger.info('Adding volume division member', extra=extra)
        response = self._api.post(
            url=self._URL['members_query'].format(id=self.id), data=data)
        member_data = response.json()
        return Member(api=self._api, **member_data)
Ejemplo n.º 2
0
    def add_member_division(self, division, permissions):
        """
        Add a member (team) to a project.
        :param division: Division object or division identifier.
        :param permissions: Permissions dictionary.
        :return: Member object.
        """
        division = Transform.to_division(division)
        data = {'id': division, 'type': 'DIVISION'}
        if isinstance(permissions, dict):
            data.update({
                'permissions': permissions
            })

        extra = {
            'resource': self.__class__.__name__,
            'query': {
                'id': self.id,
                'data': data,
            }
        }
        logger.info('Adding team member using division id', extra=extra)
        response = self._api.post(
            url=self._URL['members_query'].format(id=self.id), data=data)
        member_data = response.json()
        return Member(api=self._api, **member_data)
Ejemplo n.º 3
0
 def query(cls, division, offset=None, limit=None, api=None):
     division = Transform.to_division(division)
     api = api if api else cls._API
     return super(Team, cls)._query(
         url=cls._URL['query'], division=division, offset=offset,
         limit=limit, fields='_all', api=api
     )
Ejemplo n.º 4
0
    def create(cls, name, division, api=None):
        """
        Create team within a division
        :param name:  Team name.
        :param division: Parent division.
        :param api: Api instance.
        :return: Team object.
        """

        division = Transform.to_division(division)
        api = api if api else cls._API
        data = {'name': name, 'division': division}

        extra = {'resource': cls.__name__, 'query': data}
        logger.info('Creating team', extra=extra)
        created_team = api.post(cls._URL['query'], data=data).json()
        return Team(api=api, **created_team)
Ejemplo n.º 5
0
    def query(cls, division, role=None, offset=None, limit=None, api=None):
        """Query division users
        :param division: Division slug.
        :param role: User role in division.
        :param offset: Pagination offset.
        :param limit: Pagination limit.
        :param api: Api instance.
        :return: Collection object.
        """
        api = api or cls._API
        params = {
            'division': Transform.to_division(division),
        }
        if role:
            params['role'] = role

        return super()._query(url=cls._URL['query'],
                              api=api,
                              offset=offset,
                              limit=limit,
                              **params)
Ejemplo n.º 6
0
 def query(cls,
           division,
           list_all=False,
           offset=None,
           limit=None,
           api=None):
     """
     :param division: Division slug.
     :param list_all: List all teams in division.
     :param offset: Pagination offset.
     :param limit: Pagination limit.
     :param api: Api instance.
     :return: Collection object.
     """
     division = Transform.to_division(division)
     api = api if api else cls._API
     return super(Team, cls)._query(url=cls._URL['query'],
                                    division=division,
                                    _all=list_all,
                                    offset=offset,
                                    limit=limit,
                                    fields='_all',
                                    api=api)
Ejemplo n.º 7
0
    def create(cls, name, division, api=None):
        """
        Create team within a division
        :param name:  Team name.
        :param division: Parent division.
        :param api: Api instance.
        :return: Team object.
        """

        division = Transform.to_division(division)
        api = api if api else cls._API
        data = {
            'name': name,
            'division': division
        }

        extra = {
            'resource': cls.__name__,
            'query': data
        }
        logger.info('Creating team', extra=extra)
        created_team = api.post(cls._URL['query'], data=data).json()
        return Team(api=api, **created_team)
Ejemplo n.º 8
0
def test_transform_divisions(division):
    Transform.to_division(division)