Example #1
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"))
Example #2
0
    def put(self, worklist_id, filter_id, filter):
        """Update a filter on the worklist.

        Example::

          TODO

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter to be updated.
        :param filter: The new contents of the filter.

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

        old = serialize_filter(worklists_api.get_filter(filter_id))

        update_dict = filter.as_dict(omit_unset=True)
        updated = worklists_api.update_filter(filter_id, update_dict)

        changes = {
            "old": old,
            "new": serialize_filter(updated)
        }
        events_api.worklist_filters_changed_event(worklist_id,
                                                  user_id,
                                                  updated=changes)

        updated_model = wmodels.WorklistFilter.from_db_model(updated)
        updated_model.resolve_criteria(updated)

        return updated_model
Example #3
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
        ]
Example #4
0
    def post(self, id, item_id, item_type, list_position):
        """Add an item to a worklist.

        :param id: The ID of the worklist.
        :param item_id: The ID of the item.
        :param item_type: The type of the item (i.e. "story" or "task").
        :param list_position: The position in the list to add the item.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id),
                                               user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        item = None
        if item_type == 'story':
            item = stories_api.story_get(
                item_id, current_user=request.current_user_id)
        elif item_type == 'task':
            item = tasks_api.task_get(
                item_id, current_user=request.current_user_id)
        if item is None:
            raise exc.NotFound(_("Item %s refers to a non-existent task or "
                                 "story.") % item_id)

        worklists_api.add_item(
            id, item_id, item_type, list_position,
            current_user=request.current_user_id)

        return wmodels.WorklistItem.from_db_model(
            worklists_api.get_item_at_position(id, list_position))
Example #5
0
    def delete(self, id):
        """Archive this board.

        :param id: The ID of the board to be archived.

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

        # We use copy here because we only need to check changes
        # to the related objects, just the board's own attributes.
        # Also, deepcopy trips up on the lanes' backrefs.
        original = copy.copy(board)
        updated = boards_api.update(id, {"archived": True})

        post_timeline_events(original, updated)

        for lane in board.lanes:
            original = copy.deepcopy(worklists_api.get(lane.worklist.id))
            worklists_api.update(lane.worklist.id, {"archived": True})

            if not original.archived:
                events_api.worklist_details_changed_event(
                    lane.worklist.id, user_id, 'archived', original.archived,
                    True)
Example #6
0
    def post(self, worklist_id, permission):
        """Add a new permission to the worklist.

        Example::

          TODO

        :param worklist_id: The ID of the worklist.
        :param permission: The dict to use to create the permission.

        """
        user_id = request.current_user_id
        if worklists_api.editable(worklists_api.get(worklist_id), user_id):
            created = worklists_api.create_permission(worklist_id, permission)

            users = [{user.id: user.full_name} for user in created.users]
            events_api.worklist_permission_created_event(worklist_id,
                                                         user_id,
                                                         created.id,
                                                         created.codename,
                                                         users)

            return created.codename
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #7
0
    def put(self, worklist_id, filter_id, filter):
        """Update a filter on the worklist.

        Example::

          TODO

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter to be updated.
        :param filter: The new contents of the filter.

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

        old = serialize_filter(worklists_api.get_filter(filter_id))

        update_dict = filter.as_dict(omit_unset=True)
        updated = worklists_api.update_filter(filter_id, update_dict)

        changes = {"old": old, "new": serialize_filter(updated)}
        events_api.worklist_filters_changed_event(worklist_id,
                                                  user_id,
                                                  updated=changes)

        updated_model = wmodels.WorklistFilter.from_db_model(updated)
        updated_model.resolve_criteria(updated)

        return updated_model
Example #8
0
    def post(self, worklist_id, filter):
        """Create a new filter for the worklist.

        Example::

          TODO

        :param worklist_id: The ID of the worklist to set the filter on.
        :param filter: The filter to set.

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

        created = worklists_api.create_filter(worklist_id, filter.as_dict())

        added = serialize_filter(created)
        events_api.worklist_filters_changed_event(worklist_id,
                                                  user_id,
                                                  added=added)

        model = wmodels.WorklistFilter.from_db_model(created)
        model.resolve_criteria(created)
        return model
Example #9
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
        ]
Example #10
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"))
Example #11
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
        ]
Example #12
0
    def put(self, id, item_id, list_position, list_id=None,
            display_due_date=None):
        """Update a WorklistItem.

        This method also updates the positions of other items in affected
        worklists, if necessary.

        :param id: The ID of the worklist.
        :param item_id: The ID of the worklist_item to be moved.
        :param display_due_date: The ID of the due date displayed on the item.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id),
                                               user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        if worklists_api.get_item_by_id(item_id) is None:
            raise exc.NotFound(_("Item %s seems to have been deleted, "
                                 "try refreshing your page.") % item_id)
        worklists_api.move_item(id, item_id, list_position, list_id)

        if display_due_date is not None:
            if display_due_date == -1:
                display_due_date = None
            update_dict = {
                'display_due_date': display_due_date
            }
            worklists_api.update_item(item_id, update_dict)

        updated = worklists_api.get_item_by_id(item_id)
        result = wmodels.WorklistItem.from_db_model(updated)
        result.resolve_due_date(updated)
        return result
Example #13
0
    def delete(self, id):
        """Archive this board.

        :param id: The ID of the board to be archived.

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

        # We use copy here because we only need to check changes
        # to the related objects, just the board's own attributes.
        # Also, deepcopy trips up on the lanes' backrefs.
        original = copy.copy(board)
        updated = boards_api.update(id, {"archived": True})

        post_timeline_events(original, updated)

        for lane in board.lanes:
            original = copy.deepcopy(worklists_api.get(lane.worklist.id))
            worklists_api.update(lane.worklist.id, {"archived": True})

            if not original.archived:
                events_api.worklist_details_changed_event(
                    lane.worklist.id, user_id, 'archived', original.archived,
                    True)
Example #14
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)
Example #15
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"))
Example #16
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)
Example #17
0
    def post(self, worklist_id, filter):
        """Create a new filter for the worklist.

        Example::

          TODO

        :param worklist_id: The ID of the worklist to set the filter on.
        :param filter: The filter to set.

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

        created = worklists_api.create_filter(worklist_id, filter.as_dict())

        added = serialize_filter(created)
        events_api.worklist_filters_changed_event(worklist_id,
                                                  user_id,
                                                  added=added)

        model = wmodels.WorklistFilter.from_db_model(created)
        model.resolve_criteria(created)
        return model
Example #18
0
    def put(self, worklist_id, permission):
        """Update a permission of the worklist.

        Example::

          TODO

        This takes a dict in the form::

            {
                "codename": "my-permission",
                "users": [
                    1,
                    2,
                    3
                ]
            }

        The given codename must match an existing permission's
        codename.

        :param worklist_id: The ID of the worklist.
        :param permission: The new contents of the permission.

        """
        user_id = request.current_user_id
        worklist = worklists_api.get(worklist_id)

        old = None
        for perm in worklist.permissions:
            if perm.codename == permission['codename']:
                old = perm

        if old is None:
            raise exc.NotFound(
                _("Permission with codename %s not found") %
                permission['codename'])

        old_users = {user.id: user.full_name for user in old.users}

        if worklists_api.editable(worklist, user_id):
            updated = worklists_api.update_permission(worklist_id, permission)
            new_users = {user.id: user.full_name for user in updated.users}

            added = [{
                id: name
            } for id, name in six.iteritems(new_users) if id not in old_users]
            removed = [{
                id: name
            } for id, name in six.iteritems(old_users) if id not in new_users]

            if added or removed:
                events_api.worklist_permissions_changed_event(
                    worklist_id, user_id, updated.id, updated.codename, added,
                    removed)
            return updated.codename

        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #19
0
    def put(self, id, due_date):
        """Modify a due date.

        :param id: The ID of the due date to edit.
        :param due_date: The new due date within the request body.

        """
        if not due_dates_api.assignable(due_dates_api.get(id), request.current_user_id):
            raise exc.NotFound(_("Due date %s not found") % id)

        original_due_date = due_dates_api.get(id)

        due_date_dict = due_date.as_dict(omit_unset=True)
        editing = any(prop in due_date_dict for prop in ("name", "date", "private"))
        if editing and not due_dates_api.editable(original_due_date, request.current_user_id):
            raise exc.NotFound(_("Due date %s not found") % id)

        if due_date.creator_id and due_date.creator_id != original_due_date.creator_id:
            abort(400, _("You can't select the creator of a due date."))

        if "tasks" in due_date_dict:
            tasks = due_date_dict.pop("tasks")
            db_tasks = []
            for task in tasks:
                db_tasks.append(tasks_api.task_get(task.id, current_user=request.current_user_id))
            due_date_dict["tasks"] = db_tasks

        if "stories" in due_date_dict:
            stories = due_date_dict.pop("stories")
            db_stories = []
            for story in stories:
                db_stories.append(stories_api.story_get_simple(story.id, current_user=request.current_user_id))
            due_date_dict["stories"] = db_stories

        board = None
        worklist = None
        if "board_id" in due_date_dict:
            board = boards_api.get(due_date_dict["board_id"])

        if "worklist_id" in due_date_dict:
            worklist = worklists_api.get(due_date_dict["worklist_id"])

        updated_due_date = due_dates_api.update(id, due_date_dict)

        if board:
            updated_due_date.boards.append(board)

        if worklist:
            updated_due_date.worklists.append(worklist)

        if due_dates_api.visible(updated_due_date, request.current_user_id):
            due_date_model = wmodels.DueDate.from_db_model(updated_due_date)
            due_date_model.resolve_items(updated_due_date)
            due_date_model.resolve_permissions(updated_due_date, request.current_user_id)
            return due_date_model
        else:
            raise exc.NotFound(_("Due date %s not found") % id)
Example #20
0
    def post(self, due_date):
        """Create a new due date.

        :param due_date: A due date within the request body.

        """
        due_date_dict = due_date.as_dict()
        user_id = request.current_user_id

        if due_date.creator_id and due_date.creator_id != user_id:
            abort(400, _("You can't select the creator of a due date."))
        due_date_dict.update({'creator_id': user_id})

        board_id = due_date_dict.pop('board_id')
        worklist_id = due_date_dict.pop('worklist_id')
        if 'stories' in due_date_dict:
            del due_date_dict['stories']
        if 'tasks' in due_date_dict:
            del due_date_dict['tasks']
        owners = due_date_dict.pop('owners')
        users = due_date_dict.pop('users')
        if not owners:
            owners = [user_id]
        if not users:
            users = []

        created_due_date = due_dates_api.create(due_date_dict)

        if board_id is not None:
            date = due_dates_api.get(created_due_date.id)
            date.boards.append(boards_api.get(board_id))

        if worklist_id is not None:
            date = due_dates_api.get(created_due_date.id)
            date.worklists.append(worklists_api.get(worklist_id))

        edit_permission = {
            'name': 'edit_due_date_%d' % created_due_date.id,
            'codename': 'edit_date',
            'users': owners
        }
        assign_permission = {
            'name': 'assign_due_date_%d' % created_due_date.id,
            'codename': 'assign_date',
            'users': users
        }
        due_dates_api.create_permission(created_due_date.id, edit_permission)
        due_dates_api.create_permission(created_due_date.id, assign_permission)

        created_due_date = due_dates_api.get(created_due_date.id)
        due_date_model = wmodels.DueDate.from_db_model(created_due_date)
        due_date_model.resolve_items(created_due_date)
        due_date_model.resolve_permissions(created_due_date,
                                           request.current_user_id)
        return due_date_model
Example #21
0
    def post(self, due_date):
        """Create a new due date.

        :param due_date: A due date within the request body.

        """
        due_date_dict = due_date.as_dict()
        user_id = request.current_user_id

        if due_date.creator_id and due_date.creator_id != user_id:
            abort(400, _("You can't select the creator of a due date."))
        due_date_dict.update({'creator_id': user_id})

        board_id = due_date_dict.pop('board_id')
        worklist_id = due_date_dict.pop('worklist_id')
        if 'stories' in due_date_dict:
            del due_date_dict['stories']
        if 'tasks' in due_date_dict:
            del due_date_dict['tasks']
        owners = due_date_dict.pop('owners')
        users = due_date_dict.pop('users')
        if not owners:
            owners = [user_id]
        if not users:
            users = []

        created_due_date = due_dates_api.create(due_date_dict)

        if board_id is not None:
            date = due_dates_api.get(created_due_date.id)
            date.boards.append(boards_api.get(board_id))

        if worklist_id is not None:
            date = due_dates_api.get(created_due_date.id)
            date.worklists.append(worklists_api.get(worklist_id))

        edit_permission = {
            'name': 'edit_due_date_%d' % created_due_date.id,
            'codename': 'edit_date',
            'users': owners
        }
        assign_permission = {
            'name': 'assign_due_date_%d' % created_due_date.id,
            'codename': 'assign_date',
            'users': users
        }
        due_dates_api.create_permission(created_due_date.id, edit_permission)
        due_dates_api.create_permission(created_due_date.id, assign_permission)

        created_due_date = due_dates_api.get(created_due_date.id)
        due_date_model = wmodels.DueDate.from_db_model(created_due_date)
        due_date_model.resolve_items(created_due_date)
        due_date_model.resolve_permissions(created_due_date,
                                           request.current_user_id)
        return due_date_model
Example #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"))
Example #23
0
    def post(self, worklist_id, permission):
        """Add a new permission to the worklist.

        :param worklist_id: The ID of the worklist.
        :param permission: The dict to use to create the permission.

        """
        if worklists_api.editable(worklists_api.get(worklist_id), request.current_user_id):
            return worklists_api.create_permission(worklist_id)
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #24
0
    def put(self, worklist_id, permission):
        """Update a permission of the worklist.

        :param worklist_id: The ID of the worklist.
        :param permission: The new contents of the permission.

        """
        if worklists_api.editable(worklists_api.get(worklist_id), request.current_user_id):
            return worklists_api.update_permission(worklist_id, permission).codename
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #25
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)
Example #26
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)
Example #27
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]
Example #28
0
    def delete(self, worklist_id):
        """Archive this worklist.

        :param worklist_id: The ID of the worklist to be archived.

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

        worklists_api.update(worklist_id, {"archived": True})
Example #29
0
    def delete(self, worklist_id):
        """Archive this worklist.

        :param worklist_id: The ID of the worklist to be archived.

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

        worklists_api.update(worklist_id, {"archived": True})
Example #30
0
    def post(self, worklist_id, permission):
        """Add a new permission to the worklist.

        :param worklist_id: The ID of the worklist.
        :param permission: The dict to use to create the permission.

        """
        if worklists_api.editable(worklists_api.get(worklist_id),
                                  request.current_user_id):
            return worklists_api.create_permission(worklist_id)
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #31
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]
Example #32
0
    def put(self, worklist_id, permission):
        """Update a permission of the worklist.

        :param worklist_id: The ID of the worklist.
        :param permission: The new contents of the permission.

        """
        if worklists_api.editable(worklists_api.get(worklist_id),
                                  request.current_user_id):
            return worklists_api.update_permission(
                worklist_id, permission).codename
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #33
0
    def delete(self, worklist_id, filter_id):
        """Delete a filter from a worklist.

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter to be deleted.

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

        worklists_api.delete_filter(filter_id)
Example #34
0
    def delete(self, worklist_id, filter_id):
        """Delete a filter from a worklist.

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter to be deleted.

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

        worklists_api.delete_filter(filter_id)
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)
Example #36
0
    def delete(self, id, item_id):
        """Remove an item from a worklist.

        :param id: The ID of the worklist.
        :param item_id: The ID of the worklist item to be removed.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id), user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        item = worklists_api.get_item_by_id(item_id)
        if item is None:
            raise exc.NotFound(_("Item %s seems to have already been deleted," " try refreshing your page.") % item_id)
        worklists_api.update_item(item_id, {"archived": True})
Example #37
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)
Example #38
0
    def post(self, due_date):
        """Create a new due date.

        :param due_date: A due date within the request body.

        """
        due_date_dict = due_date.as_dict()
        user_id = request.current_user_id

        if due_date.creator_id and due_date.creator_id != user_id:
            abort(400, _("You can't select the creator of a due date."))
        due_date_dict.update({"creator_id": user_id})

        board_id = due_date_dict.pop("board_id")
        worklist_id = due_date_dict.pop("worklist_id")
        if "stories" in due_date_dict:
            del due_date_dict["stories"]
        if "tasks" in due_date_dict:
            del due_date_dict["tasks"]
        owners = due_date_dict.pop("owners")
        users = due_date_dict.pop("users")
        if not owners:
            owners = [user_id]
        if not users:
            users = []

        created_due_date = due_dates_api.create(due_date_dict)

        if board_id is not None:
            date = due_dates_api.get(created_due_date.id)
            date.boards.append(boards_api.get(board_id))

        if worklist_id is not None:
            date = due_dates_api.get(created_due_date.id)
            date.worklists.append(worklists_api.get(worklist_id))

        edit_permission = {"name": "edit_due_date_%d" % created_due_date.id, "codename": "edit_date", "users": owners}
        assign_permission = {
            "name": "assign_due_date_%d" % created_due_date.id,
            "codename": "assign_date",
            "users": users,
        }
        due_dates_api.create_permission(created_due_date.id, edit_permission)
        due_dates_api.create_permission(created_due_date.id, assign_permission)

        created_due_date = due_dates_api.get(created_due_date.id)
        due_date_model = wmodels.DueDate.from_db_model(created_due_date)
        due_date_model.resolve_items(created_due_date)
        due_date_model.resolve_permissions(created_due_date, request.current_user_id)
        return due_date_model
Example #39
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)
Example #40
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)
Example #41
0
    def delete(self, id, item_id):
        """Remove an item from a worklist.

        :param id: The ID of the worklist.
        :param item_id: The ID of the worklist item to be removed.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id),
                                               user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        item = worklists_api.get_item_by_id(item_id)
        if item is None:
            raise exc.NotFound(_("Item %s seems to have already been deleted,"
                                 " try refreshing your page.") % item_id)
        worklists_api.update_item(item_id, {'archived': True})
Example #42
0
    def put(self, id, item_id, list_position, list_id=None,
            display_due_date=None):
        """Update a WorklistItem.

        This method also updates the positions of other items in affected
        worklists, if necessary.

        :param id: The ID of the worklist.
        :param item_id: The ID of the worklist_item to be moved.
        :param display_due_date: The ID of the due date displayed on the item.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id),
                                               user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        card = worklists_api.get_item_by_id(item_id)
        if card is None:
            raise exc.NotFound(_("Item %s seems to have been deleted, "
                                 "try refreshing your page.") % item_id)

        item = None
        if card.item_type == 'story':
            item = stories_api.story_get(
                card.item_id, current_user=request.current_user_id)
        elif card.item_type == 'task':
            item = tasks_api.task_get(
                card.item_id, current_user=request.current_user_id)

        if item is None:
            raise exc.NotFound(_("Item %s refers to a non-existent task or "
                                 "story.") % item_id)

        worklists_api.move_item(id, item_id, list_position, list_id)

        if display_due_date is not None:
            if display_due_date == -1:
                display_due_date = None
            update_dict = {
                'display_due_date': display_due_date
            }
            worklists_api.update_item(item_id, update_dict)

        updated = worklists_api.get_item_by_id(item_id)
        result = wmodels.WorklistItem.from_db_model(updated)
        result.resolve_due_date(updated)
        return result
Example #43
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)
Example #44
0
    def put(self, worklist_id, filter_id, filter):
        """Update a filter on the worklist.

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter to be updated.
        :param filter: The new contents of the filter.

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

        update_dict = filter.as_dict(omit_unset=True)
        updated = worklists_api.update_filter(filter_id, update_dict)

        return wmodels.WorklistFilter.from_db_model(updated)
Example #45
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)
Example #46
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)
Example #47
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)
Example #48
0
    def put(self, worklist_id, filter_id, filter):
        """Update a filter on the worklist.

        :param worklist_id: The ID of the worklist.
        :param filter_id: The ID of the filter to be updated.
        :param filter: The new contents of the filter.

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

        update_dict = filter.as_dict(omit_unset=True)
        updated = worklists_api.update_filter(filter_id, update_dict)

        return wmodels.WorklistFilter.from_db_model(updated)
Example #49
0
    def post(self, id, item_id, item_type, list_position):
        """Add an item to a worklist.

        :param id: The ID of the worklist.
        :param item_id: The ID of the item.
        :param item_type: The type of the item (i.e. "story" or "task").
        :param list_position: The position in the list to add the item.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id),
                                               user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        worklists_api.add_item(id, item_id, item_type, list_position)

        return wmodels.WorklistItem.from_db_model(
            worklists_api.get_item_at_position(id, list_position))
Example #50
0
    def post(self, id, item_id, item_type, list_position):
        """Add an item to a worklist.

        Example::

          TODO

        :param id: The ID of the worklist.
        :param item_id: The ID of the item.
        :param item_type: The type of the item (i.e. "story" or "task").
        :param list_position: The position in the list to add the item.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id), user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        item = None
        if item_type == 'story':
            item = stories_api.story_get(item_id,
                                         current_user=request.current_user_id)
        elif item_type == 'task':
            item = tasks_api.task_get(item_id,
                                      current_user=request.current_user_id)
        if item is None:
            raise exc.NotFound(
                _("Item %s refers to a non-existent task or "
                  "story.") % item_id)

        card = worklists_api.add_item(id,
                                      item_id,
                                      item_type,
                                      list_position,
                                      current_user=request.current_user_id)

        added = {
            "worklist_id": id,
            "item_id": item_id,
            "item_title": item.title,
            "item_type": item_type,
            "position": card.list_position
        }

        events_api.worklist_contents_changed_event(id, user_id, added=added)

        return wmodels.WorklistItem.from_db_model(card)
Example #51
0
    def post(self, id, item_id, item_type, list_position):
        """Add an item to a worklist.

        Example::

          TODO

        :param id: The ID of the worklist.
        :param item_id: The ID of the item.
        :param item_type: The type of the item (i.e. "story" or "task").
        :param list_position: The position in the list to add the item.

        """
        user_id = request.current_user_id
        if not worklists_api.editable_contents(worklists_api.get(id),
                                               user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        item = None
        if item_type == 'story':
            item = stories_api.story_get(
                item_id, current_user=request.current_user_id)
        elif item_type == 'task':
            item = tasks_api.task_get(
                item_id, current_user=request.current_user_id)
        if item is None:
            raise exc.NotFound(_("Item %s refers to a non-existent task or "
                                 "story.") % item_id)

        card = worklists_api.add_item(
            id, item_id, item_type, list_position,
            current_user=request.current_user_id)

        added = {
            "worklist_id": id,
            "item_id": item_id,
            "item_title": item.title,
            "item_type": item_type,
            "position": card.list_position
        }

        events_api.worklist_contents_changed_event(id, user_id, added=added)

        return wmodels.WorklistItem.from_db_model(card)
Example #52
0
    def delete(self, id, item_id):
        """Remove an item from a worklist.

        Example::

          TODO

        :param id: The ID of the worklist.
        :param item_id: The ID of the worklist item to be removed.

        """
        user_id = request.current_user_id
        worklist = worklists_api.get(id)
        if not worklists_api.editable_contents(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        card = worklists_api.get_item_by_id(item_id)
        if card is None:
            raise exc.NotFound(_("Item %s seems to have already been deleted,"
                                 " try refreshing your page.") % item_id)

        worklists_api.archive_item(item_id)

        item = None
        if card.item_type == 'story':
            item = stories_api.story_get(
                card.item_id, current_user=user_id)
        elif card.item_type == 'task':
            item = tasks_api.task_get(
                card.item_id, current_user=user_id)
        if item is None:
            item.title = ''

        removed = {
            "worklist_id": id,
            "item_id": card.item_id,
            "item_type": card.item_type,
            "item_title": item.title
        }
        events_api.worklist_contents_changed_event(id,
                                                   user_id,
                                                   removed=removed)
Example #53
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
Example #54
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]
Example #55
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
Example #56
0
    def delete(self, id, item_id):
        """Remove an item from a worklist.

        Example::

          TODO

        :param id: The ID of the worklist.
        :param item_id: The ID of the worklist item to be removed.

        """
        user_id = request.current_user_id
        worklist = worklists_api.get(id)
        if not worklists_api.editable_contents(worklist, user_id):
            raise exc.NotFound(_("Worklist %s not found") % id)
        card = worklists_api.get_item_by_id(item_id)
        if card is None:
            raise exc.NotFound(
                _("Item %s seems to have already been deleted,"
                  " try refreshing your page.") % item_id)
        worklists_api.update_item(item_id, {'archived': True})
        worklists_api.normalize_positions(worklist)

        item = None
        if card.item_type == 'story':
            item = stories_api.story_get(card.item_id, current_user=user_id)
        elif card.item_type == 'task':
            item = tasks_api.task_get(card.item_id, current_user=user_id)
        if item is None:
            item.title = ''

        removed = {
            "worklist_id": id,
            "item_id": card.item_id,
            "item_type": card.item_type,
            "item_title": item.title
        }
        events_api.worklist_contents_changed_event(id,
                                                   user_id,
                                                   removed=removed)
Example #57
0
    def post(self, worklist_id, permission):
        """Add a new permission to the worklist.

        Example::

          TODO

        :param worklist_id: The ID of the worklist.
        :param permission: The dict to use to create the permission.

        """
        user_id = request.current_user_id
        if worklists_api.editable(worklists_api.get(worklist_id), user_id):
            created = worklists_api.create_permission(worklist_id, permission)

            users = [{user.id: user.full_name} for user in created.users]
            events_api.worklist_permission_created_event(
                worklist_id, user_id, created.id, created.codename, users)

            return created.codename
        else:
            raise exc.NotFound(_("Worklist %s not found") % worklist_id)
Example #58
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
Example #59
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
Example #60
0
    def delete(self, worklist_id):
        """Archive this worklist.
           Though this uses the DELETE command, the worklist is not deleted.
           Archived worklists remain viewable at the designated URL, but
           are not returned in search results nor appear on your dashboard.

        Example::

          curl https://my.example.org/api/v1/worklists/30 -X DELETE \\
          -H 'Authorization: Bearer MY_ACCESS_TOKEN'

        :param worklist_id: The ID of the worklist to be archived.

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

        updated = worklists_api.update(worklist_id, {"archived": True})

        post_timeline_events(original, updated)