Exemplo n.º 1
0
    def put(self, id, board):
        """Modify this board.

        :param id: The ID of the board.
        :param board: The new board within the request body.

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

        board_dict = board.as_dict(omit_unset=True)
        update_lanes(board_dict, id)

        # This is not how we add due dates.
        if 'due_dates' in board_dict:
            del board_dict['due_dates']

        updated_board = boards_api.update(id, board_dict)

        if boards_api.visible(updated_board, user_id):
            board_model = wmodels.Board.from_db_model(updated_board)
            board_model.resolve_lanes(updated_board)
            board_model.resolve_permissions(updated_board)
            return board_model
        else:
            raise exc.NotFound(_("Board %s not found") % id)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def put(self, id, board):
        """Modify this board.

        :param id: The ID of the board.
        :param board: The new board within the request body.

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

        board_dict = board.as_dict(omit_unset=True)
        update_lanes(board_dict, id)

        # This is not how we add due dates.
        if 'due_dates' in board_dict:
            del board_dict['due_dates']

        updated_board = boards_api.update(id, board_dict)

        if boards_api.visible(updated_board, user_id):
            board_model = wmodels.Board.from_db_model(updated_board)
            board_model.resolve_lanes(updated_board)
            board_model.resolve_permissions(updated_board)
            return board_model
        else:
            raise exc.NotFound(_("Board %s not found") % id)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def post(self, board_id, permission):
        """Add a new permission to the board.

        :param board_id: The ID of the board.
        :param permission: The dict to use to create the permission.

        """
        if boards_api.editable(boards_api.get(board_id),
                               request.current_user_id):
            return boards_api.create_permission(board_id)
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 6
0
    def post(self, board_id, permission):
        """Add a new permission to the board.

        :param board_id: The ID of the board.
        :param permission: The dict to use to create the permission.

        """
        if boards_api.editable(boards_api.get(board_id),
                               request.current_user_id):
            return boards_api.create_permission(board_id)
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 7
0
    def put(self, board_id, permission):
        """Update a permission of the board.

        :param board_id: The ID of the board.
        :param permission: The new contents of the permission.

        """
        if boards_api.editable(boards_api.get(board_id),
                               request.current_user_id):
            return boards_api.update_permission(board_id, permission).codename
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 8
0
    def put(self, board_id, permission):
        """Update a permission of the board.

        :param board_id: The ID of the board.
        :param permission: The new contents of the permission.

        """
        if boards_api.editable(boards_api.get(board_id),
                               request.current_user_id):
            return boards_api.update_permission(board_id, permission).codename
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 9
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)

        boards_api.update(id, {"archived": True})

        for lane in board.lanes:
            worklists_api.update(lane.worklist.id, {"archived": True})
Exemplo n.º 10
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)

        boards_api.update(id, {"archived": True})

        for lane in board.lanes:
            worklists_api.update(lane.worklist.id, {"archived": True})
Exemplo n.º 11
0
    def put(self, id, board):
        """Modify this board.

        :param id: The ID of the board.
        :param board: The new board within the request body.

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

        story_cache = {
            story.id: story
            for story in stories_api.story_get_all(board_id=id,
                                                   current_user=user_id)
        }
        task_cache = {
            task.id: task
            for task in tasks_api.task_get_all(board_id=id,
                                               current_user=user_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(original)

        board_dict = board.as_dict(omit_unset=True)
        update_lanes(board_dict, id)

        # This is not how we add due dates.
        if 'due_dates' in board_dict:
            del board_dict['due_dates']

        updated_board = boards_api.update(id, board_dict)

        post_timeline_events(original, updated_board)

        if boards_api.visible(updated_board, user_id):
            board_model = wmodels.Board.from_db_model(updated_board)
            board_model.resolve_lanes(updated_board, story_cache, task_cache)
            board_model.resolve_permissions(updated_board)
            return board_model
        else:
            raise exc.NotFound(_("Board %s not found") % id)
Exemplo n.º 12
0
    def post(self, board_id, permission):
        """Add a new permission to the board.

        :param board_id: The ID of the board.
        :param permission: The dict to use to create the permission.

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

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

            return created
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 13
0
    def post(self, board_id, permission):
        """Add a new permission to the board.

        :param board_id: The ID of the board.
        :param permission: The dict to use to create the permission.

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

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

            return created
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 14
0
    def put(self, id, board):
        """Modify this board.

        :param id: The ID of the board.
        :param board: The new board within the request body.

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

        story_cache = {story.id: story for story in stories_api.story_get_all(
                       board_id=id, current_user=user_id)}
        task_cache = {task.id: task for task in tasks_api.task_get_all(
                      board_id=id, current_user=user_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(original)

        board_dict = board.as_dict(omit_unset=True)
        update_lanes(board_dict, id)

        # This is not how we add due dates.
        if 'due_dates' in board_dict:
            del board_dict['due_dates']

        updated_board = boards_api.update(id, board_dict)

        post_timeline_events(original, updated_board)

        if boards_api.visible(updated_board, user_id):
            board_model = wmodels.Board.from_db_model(updated_board)
            board_model.resolve_lanes(updated_board, story_cache, task_cache)
            board_model.resolve_permissions(updated_board)
            return board_model
        else:
            raise exc.NotFound(_("Board %s not found") % id)
Exemplo n.º 15
0
    def put(self, board_id, permission):
        """Update a permission of the board.

        :param board_id: The ID of the board.
        :param permission: The new contents of the permission.

        """
        user_id = request.current_user_id
        board = boards_api.get(board_id)

        old = None
        for perm in board.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 boards_api.editable(board, user_id):
            updated = boards_api.update_permission(board_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.board_permissions_changed_event(board.id,
                                                           user_id,
                                                           updated.id,
                                                           updated.codename,
                                                           added,
                                                           removed)
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 16
0
    def put(self, board_id, permission):
        """Update a permission of the board.

        :param board_id: The ID of the board.
        :param permission: The new contents of the permission.

        """
        user_id = request.current_user_id
        board = boards_api.get(board_id)

        old = None
        for perm in board.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 boards_api.editable(board, user_id):
            updated = boards_api.update_permission(board_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.board_permissions_changed_event(
                    board.id, user_id, updated.id, updated.codename, added,
                    removed)
        else:
            raise exc.NotFound(_("Board %s not found") % board_id)
Exemplo n.º 17
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)
Exemplo n.º 18
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)