Example #1
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 #2
0
    def put(self, due_date_id, permission):
        """Update a permission of the due date.

        :param due_date_id: The ID of the due date.
        :param permission: The new contents of the permission.

        """
        if due_dates_api.editable(due_dates_api.get(due_date_id), request.current_user_id):
            return due_dates_api.update_permission(due_date_id, permission).codename
        else:
            raise exc.NotFound(_("Due date %s not found") % due_date_id)
Example #3
0
    def post(self, due_date_id, permission):
        """Add a new permission to the due date.

        :param due_date_id: The ID of the due date.
        :param permission: The dict used to create the permission.

        """
        if due_dates_api.editable(due_dates_api.get(due_date_id), request.current_user_id):
            return due_dates_api.create_permission(due_date_id, permission)
        else:
            raise exc.NotFound(_("Due date %s not found") % due_date_id)
Example #4
0
    def post(self, due_date_id, permission):
        """Add a new permission to the due date.

        :param due_date_id: The ID of the due date.
        :param permission: The dict used to create the permission.

        """
        if due_dates_api.editable(due_dates_api.get(due_date_id),
                                  request.current_user_id):
            return due_dates_api.create_permission(due_date_id, permission)
        else:
            raise exc.NotFound(_("Due date %s not found") % due_date_id)
Example #5
0
    def put(self, due_date_id, permission):
        """Update a permission of the due date.

        :param due_date_id: The ID of the due date.
        :param permission: The new contents of the permission.

        """
        if due_dates_api.editable(due_dates_api.get(due_date_id),
                                  request.current_user_id):
            return due_dates_api.update_permission(
                due_date_id, permission).codename
        else:
            raise exc.NotFound(_("Due date %s not found") % due_date_id)
Example #6
0
    def delete(self, id, board_id):
        """Stop associating a due date with a board.

        Note: We don't allow actual deletion of due dates.

        :param id: The ID of the due date.
        :param board_id: The ID of the board.

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

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

        if board in due_date.boards:
            due_date.boards.remove(board)
            for lane in board.lanes:
                for card in lane.worklist.items:
                    if card.display_due_date == due_date.id:
                        update = {'display_due_date': None}
                        worklists_api.update_item(card.id, update)
Example #7
0
    def delete(self, id, board_id):
        """Stop associating a due date with a board.

        Note: We don't allow actual deletion of due dates.

        :param id: The ID of the due date.
        :param board_id: The ID of the board.

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

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

        if board in due_date.boards:
            due_date.boards.remove(board)
            for lane in board.lanes:
                for card in lane.worklist.items:
                    if card.display_due_date == due_date.id:
                        update = {'display_due_date': None}
                        worklists_api.update_item(card.id, update)
Example #8
0
 def resolve_permissions(self, due_date, user=None):
     """Resolve the permissions groups of the due date."""
     self.owners = due_dates_api.get_owners(due_date)
     self.users = due_dates_api.get_users(due_date)
     self.editable = due_dates_api.editable(due_date, user)
     self.assignable = due_dates_api.assignable(due_date, user)
Example #9
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 #10
0
 def resolve_permissions(self, due_date, user=None):
     """Resolve the permissions groups of the due date."""
     self.owners = due_dates_api.get_owners(due_date)
     self.users = due_dates_api.get_users(due_date)
     self.editable = due_dates_api.editable(due_date, user)
     self.assignable = due_dates_api.assignable(due_date, user)