示例#1
0
    def get(self, worklist_id):
        """Get items inside a worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/49/items

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        if worklist.automatic:
            return [wmodels.WorklistItem(**item)
                    for item in worklists_api.filter_items(worklist)]

        if worklist.items is None:
            return []

        worklist.items.order_by(models.WorklistItem.list_position)

        visible_items = worklists_api.get_visible_items(
            worklist, current_user=request.current_user_id)
        return [
            wmodels.WorklistItem.from_db_model(item)
            for item in visible_items
        ]
示例#2
0
    def get_one(self, worklist_id):
        """Retrieve details about one worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/27

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)

        user_id = request.current_user_id
        story_cache = {story.id: story for story in stories_api.story_get_all(
                       worklist_id=worklist_id, current_user=user_id)}
        task_cache = {task.id: task for task in tasks_api.task_get_all(
                      worklist_id=worklist_id, current_user=user_id)}
        if worklist and worklists_api.visible(worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(worklist)
            worklist_model.resolve_items(worklist, story_cache, task_cache)
            worklist_model.resolve_permissions(worklist)
            worklist_model.resolve_filters(worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#3
0
    def put(self, id, worklist):
        """Modify this worklist.

        :param id: The ID of the worklist.
        :param worklist: A worklist within the request body.

        """
        user_id = request.current_user_id
        if not worklists_api.editable(worklists_api.get(id), user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)

        # We don't use this endpoint to update the worklist's contents
        if worklist.items != wtypes.Unset:
            del worklist.items

        # We don't use this endpoint to update the worklist's filters either
        if worklist.filters != wtypes.Unset:
            del worklist.filters

        worklist_dict = worklist.as_dict(omit_unset=True)

        updated_worklist = worklists_api.update(id, worklist_dict)

        if worklists_api.visible(updated_worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(updated_worklist)
            worklist_model.resolve_items(updated_worklist)
            worklist_model.resolve_permissions(updated_worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found"))
示例#4
0
    def put(self, id, worklist):
        """Modify this worklist.

        :param id: The ID of the worklist.
        :param worklist: A worklist within the request body.

        """
        user_id = request.current_user_id
        if not worklists_api.editable(worklists_api.get(id), user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)

        # We don't use this endpoint to update the worklist's contents
        if worklist.items != wtypes.Unset:
            del worklist.items

        # We don't use this endpoint to update the worklist's filters either
        if worklist.filters != wtypes.Unset:
            del worklist.filters

        worklist_dict = worklist.as_dict(omit_unset=True)

        updated_worklist = worklists_api.update(id, worklist_dict)

        if worklists_api.visible(updated_worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(updated_worklist)
            worklist_model.resolve_items(updated_worklist)
            worklist_model.resolve_permissions(updated_worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found"))
示例#5
0
    def get(self, worklist_id):
        """Get items inside a worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/49/items

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        if worklist.automatic:
            return [
                wmodels.WorklistItem(**item)
                for item in worklists_api.filter_items(worklist)
            ]

        if worklist.items is None:
            return []

        worklist.items.order_by(models.WorklistItem.list_position)

        visible_items = worklists_api.get_visible_items(
            worklist, current_user=request.current_user_id)
        return [
            wmodels.WorklistItem.from_db_model(item) for item in visible_items
        ]
示例#6
0
    def get_one(self, worklist_id):
        """Retrieve details about one worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/27

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)

        user_id = request.current_user_id
        story_cache = {
            story.id: story
            for story in stories_api.story_get_all(worklist_id=worklist_id,
                                                   current_user=user_id)
        }
        task_cache = {
            task.id: task
            for task in tasks_api.task_get_all(worklist_id=worklist_id,
                                               current_user=user_id)
        }
        if worklist and worklists_api.visible(worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(worklist)
            worklist_model.resolve_items(worklist, story_cache, task_cache)
            worklist_model.resolve_permissions(worklist)
            worklist_model.resolve_filters(worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#7
0
    def get(self, worklist_id):
        """Get items inside a worklist.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        if worklist.automatic:
            return [wmodels.WorklistItem(**item)
                    for item in worklists_api.filter_items(worklist)]

        if worklist.items is None:
            return []

        worklist.items.sort(key=lambda i: i.list_position)

        visible_items = worklists_api.get_visible_items(
            worklist, current_user=request.current_user_id)
        return [
            wmodels.WorklistItem.from_db_model(item)
            for item in visible_items
        ]
示例#8
0
    def get(self, worklist_id):
        """Get worklist permissions for the current user.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        if worklists_api.visible(worklist, request.current_user_id):
            return worklists_api.get_permissions(worklist, request.current_user_id)
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#9
0
    def get(self, worklist_id):
        """Get worklist permissions for the current user.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        if worklists_api.visible(worklist, request.current_user_id):
            return worklists_api.get_permissions(worklist,
                                                 request.current_user_id)
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#10
0
    def get(self, worklist_id):
        """Get filters for an automatic worklist.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        return [wmodels.WorklistFilter.from_db_model(filter) for filter in worklist.filters]
示例#11
0
    def get(self, worklist_id):
        """Get filters for an automatic worklist.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        return [wmodels.WorklistFilter.from_db_model(filter)
                for filter in worklist.filters]
示例#12
0
def subscription_get_resource(target_type, target_id, current_user=None):
    if target_type not in SUPPORTED_TYPES:
        return None
    if target_type == 'story':
        return stories_api.story_get(target_id, current_user=current_user)
    elif target_type == 'task':
        return tasks_api.task_get(target_id, current_user=current_user)
    elif target_type == 'worklist':
        worklist = worklists_api.get(target_id)
        if worklists_api.visible(worklist, current_user):
            return worklist
        return None

    return api_base.entity_get(SUPPORTED_TYPES[target_type], target_id)
示例#13
0
def subscription_get_resource(target_type, target_id, current_user=None):
    if target_type not in SUPPORTED_TYPES:
        return None
    if target_type == 'story':
        return stories_api.story_get(target_id, current_user=current_user)
    elif target_type == 'task':
        return tasks_api.task_get(target_id, current_user=current_user)
    elif target_type == 'worklist':
        worklist = worklists_api.get(target_id)
        if worklists_api.visible(worklist, current_user):
            return worklist
        return None

    return api_base.entity_get(SUPPORTED_TYPES[target_type], target_id)
示例#14
0
    def get_all(self, title=None, creator_id=None, project_id=None,
                archived=False, user_id=None, story_id=None, task_id=None,
                hide_lanes=True, sort_field='id', sort_dir='asc',
                board_id=None):
        """Retrieve definitions of all of the worklists.

        :param title: A string to filter the title by.
        :param creator_id: Filter worklists by their creator.
        :param project_id: Filter worklists by project ID.
        :param archived: Filter worklists by whether they are archived or not.
        :param user_id: Filter worklists by the users with permissions.
        :param story_id: Filter worklists by whether they contain a story.
        :param task_id: Filter worklists by whether they contain a task.
        :param hide_lanes: If true, don't return worklists which are lanes in
        a board.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).
        :param board_id: Get all worklists in the board with this id. Other
        filters are not applied.

        """
        worklists = worklists_api.get_all(title=title,
                                          creator_id=creator_id,
                                          project_id=project_id,
                                          archived=archived,
                                          board_id=board_id,
                                          user_id=user_id,
                                          story_id=story_id,
                                          task_id=task_id,
                                          sort_field=sort_field,
                                          sort_dir=sort_dir)

        user_id = request.current_user_id
        visible_worklists = []
        for worklist in worklists:
            if (worklists_api.visible(worklist, user_id, hide_lanes) and
                worklist.archived == archived):
                worklist_model = wmodels.Worklist.from_db_model(worklist)
                worklist_model.resolve_permissions(worklist)
                worklist_model.items = [
                    wmodels.WorklistItem.from_db_model(item)
                    for item in worklist.items
                ]
                visible_worklists.append(worklist_model)

        # Apply the query response headers
        response.headers['X-Total'] = str(len(visible_worklists))

        return visible_worklists
示例#15
0
    def get_one(self, worklist_id, filter_id):
        """Get a single filter for the worklist.

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        filter = worklists_api.get_filter(worklist, filter_id)

        return wmodels.WorklistFilter.from_db_model(filter)
示例#16
0
    def get_one(self, worklist_id, filter_id):
        """Get a single filter for the worklist.

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        filter = worklists_api.get_filter(worklist, filter_id)

        return wmodels.WorklistFilter.from_db_model(filter)
示例#17
0
    def put(self, id, worklist):
        """Modify this worklist.

        Example::

          TODO

        :param id: The ID of the worklist.
        :param worklist: A worklist within the request body.

        """
        user_id = request.current_user_id
        if not worklists_api.editable(worklists_api.get(id), user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)

        story_cache = {
            story.id: story
            for story in stories_api.story_get_all(worklist_id=id,
                                                   current_user=user_id)
        }
        task_cache = {
            task.id: task
            for task in tasks_api.task_get_all(worklist_id=id,
                                               current_user=user_id)
        }

        # We don't use this endpoint to update the worklist's contents
        if worklist.items != wtypes.Unset:
            del worklist.items

        # We don't use this endpoint to update the worklist's filters either
        if worklist.filters != wtypes.Unset:
            del worklist.filters

        worklist_dict = worklist.as_dict(omit_unset=True)

        original = copy.deepcopy(worklists_api.get(id))
        updated_worklist = worklists_api.update(id, worklist_dict)

        post_timeline_events(original, updated_worklist)
        if worklists_api.visible(updated_worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(updated_worklist)
            worklist_model.resolve_items(updated_worklist, story_cache,
                                         task_cache)
            worklist_model.resolve_permissions(updated_worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found"))
示例#18
0
    def get(self, worklist_id):
        """Get worklist permissions for the current user.

        Example::

          curl https://my.example.org/api/v1/worklists/31/permissions \\
          -H 'Authorization: Bearer MY_ACCESS_TOKEN'

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        if worklists_api.visible(worklist, request.current_user_id):
            return worklists_api.get_permissions(worklist,
                                                 request.current_user_id)
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#19
0
    def get_one(self, worklist_id):
        """Retrieve details about one worklist.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)

        user_id = request.current_user_id
        if worklist and worklists_api.visible(worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(worklist)
            worklist_model.resolve_items(worklist)
            worklist_model.resolve_permissions(worklist)
            worklist_model.resolve_filters(worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#20
0
    def get(self, worklist_id):
        """Get worklist permissions for the current user.

        Example::

          curl https://my.example.org/api/v1/worklists/31/permissions \\
          -H 'Authorization: Bearer MY_ACCESS_TOKEN'

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        if worklists_api.visible(worklist, request.current_user_id):
            return worklists_api.get_permissions(worklist,
                                                 request.current_user_id)
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#21
0
    def get_one(self, worklist_id):
        """Retrieve details about one worklist.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)

        user_id = request.current_user_id
        if worklist and worklists_api.visible(worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(worklist)
            worklist_model.resolve_items(worklist)
            worklist_model.resolve_permissions(worklist)
            worklist_model.resolve_filters(worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
示例#22
0
    def put(self, id, worklist):
        """Modify this worklist.

        Example::

          TODO

        :param id: The ID of the worklist.
        :param worklist: A worklist within the request body.

        """
        user_id = request.current_user_id
        if not worklists_api.editable(worklists_api.get(id), user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)

        story_cache = {story.id: story for story in stories_api.story_get_all(
                       worklist_id=id, current_user=user_id)}
        task_cache = {task.id: task for task in tasks_api.task_get_all(
                      worklist_id=id, current_user=user_id)}

        # We don't use this endpoint to update the worklist's contents
        if worklist.items != wtypes.Unset:
            del worklist.items

        # We don't use this endpoint to update the worklist's filters either
        if worklist.filters != wtypes.Unset:
            del worklist.filters

        worklist_dict = worklist.as_dict(omit_unset=True)

        original = copy.deepcopy(worklists_api.get(id))
        updated_worklist = worklists_api.update(id, worklist_dict)

        post_timeline_events(original, updated_worklist)
        if worklists_api.visible(updated_worklist, user_id):
            worklist_model = wmodels.Worklist.from_db_model(updated_worklist)
            worklist_model.resolve_items(
                updated_worklist, story_cache, task_cache)
            worklist_model.resolve_permissions(updated_worklist)
            return worklist_model
        else:
            raise exc.NotFound(_("Worklist %s not found"))
示例#23
0
    def get_one(self, worklist_id, filter_id):
        """Get a single filter for the worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/49/filters/20

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        filter = worklists_api.get_filter(filter_id)
        wmodel = wmodels.WorklistFilter.from_db_model(filter)
        wmodel.resolve_criteria(filter)

        return wmodel
示例#24
0
    def get_one(self, worklist_id, filter_id):
        """Get a single filter for the worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/49/filters/20

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        filter = worklists_api.get_filter(filter_id)
        wmodel = wmodels.WorklistFilter.from_db_model(filter)
        wmodel.resolve_criteria(filter)

        return wmodel
示例#25
0
    def get(self, worklist_id):
        """Get items inside a worklist.

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        if worklist.automatic:
            return [wmodels.WorklistItem(**item) for item in worklists_api.filter_items(worklist)]

        if worklist.items is None:
            return []

        worklist.items.sort(key=lambda i: i.list_position)

        visible_items = worklists_api.get_visible_items(worklist, current_user=request.current_user_id)
        return [wmodels.WorklistItem.from_db_model(item) for item in visible_items]
示例#26
0
    def get(self, worklist_id):
        """Get filters for an automatic worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/49/filters

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        resolved = []
        for filter in worklist.filters:
            wmodel = wmodels.WorklistFilter.from_db_model(filter)
            wmodel.resolve_criteria(filter)
            resolved.append(wmodel)

        return resolved
示例#27
0
    def get(self, worklist_id):
        """Get filters for an automatic worklist.

        Example::

          curl https://my.example.org/api/v1/worklists/49/filters

        :param worklist_id: The ID of the worklist.

        """
        worklist = worklists_api.get(worklist_id)
        user_id = request.current_user_id
        if not worklist or not worklists_api.visible(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)

        resolved = []
        for filter in worklist.filters:
            wmodel = wmodels.WorklistFilter.from_db_model(filter)
            wmodel.resolve_criteria(filter)
            resolved.append(wmodel)

        return resolved