Example #1
0
def downgrade(active_plugins=None, options=None):
    op.add_column(
        u'worklists',
        sa.Column('permission_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.create_foreign_key(u'worklists_ibfk_2', 'worklists', 'permissions',
                          ['permission_id'], ['id'])
    op.add_column(
        u'boards',
        sa.Column('permission_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.create_foreign_key(u'boards_ibfk_2', 'boards', 'permissions',
                          ['permission_id'], ['id'])

    session = api_base.get_session(in_request=False)
    to_delete = []
    for board in boards.get_all(session=session):
        for permission in board.permissions:
            to_delete.append(permission)

    for worklist in worklists.get_all(session=session):
        for permission in worklist.permissions:
            to_delete.append(permission)

    op.drop_table('worklist_permissions')
    op.drop_table('board_permissions')

    for permission in to_delete:
        api_base.entity_hard_delete(models.Permission,
                                    permission.id,
                                    session=session)
Example #2
0
    def get_all(self, title=None, creator_id=None, project_id=None,
                archived=False, user_id=None, story_id=None, task_id=None,
                item_type=None, offset=None, limit=None, sort_field='id',
                sort_dir='asc'):
        """Retrieve definitions of all of the boards.

        :param title: A string to filter the title by.
        :param creator_id: Filter boards by their creator.
        :param project_id: Filter boards by project ID.
        :param archived: Filter boards by whether they are archived or not.
        :param story_id: Filter boards by whether they contain a story.
        :param task_id: Filter boards by whether they contain a task.
        :param item_type: Used when filtering by story_id. If item_type is
        'story' then only return worklists that contain the story, if
        item_type is 'task' then only return worklists that contain tasks from
        the story, otherwise return worklists that contain the story or tasks
        from the story.
        :param offset: Value to offset results by.
        :param limit: Maximum number of results to return.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).

        """
        current_user = request.current_user_id
        boards = boards_api.get_all(title=title,
                                    creator_id=creator_id,
                                    user_id=user_id,
                                    project_id=project_id,
                                    story_id=story_id,
                                    task_id=task_id,
                                    item_type=item_type,
                                    offset=offset,
                                    limit=limit,
                                    current_user=current_user,
                                    sort_field=sort_field,
                                    sort_dir=sort_dir)
        count = boards_api.get_count(title=title,
                                     creator_id=creator_id,
                                     user_id=user_id,
                                     project_id=project_id,
                                     story_id=story_id,
                                     task_id=task_id,
                                     item_type=item_type,
                                     current_user=current_user,)

        visible_boards = []
        for board in boards:
            board_model = wmodels.Board.from_db_model(board)
            board_model.resolve_lanes(board, resolve_items=False)
            board_model.resolve_permissions(board)
            visible_boards.append(board_model)

        # Apply the query response headers
        response.headers['X-Total'] = str(count)
        if limit is not None:
            response.headers['X-Limit'] = str(limit)
        if offset is not None:
            response.headers['X-Offset'] = str(offset)

        return visible_boards
def downgrade(active_plugins=None, options=None):
    op.add_column(u'worklists', sa.Column('permission_id',
                  mysql.INTEGER(display_width=11), autoincrement=False,
                  nullable=True))
    op.create_foreign_key(u'worklists_ibfk_2', 'worklists', 'permissions',
                          ['permission_id'], ['id'])
    op.add_column(u'boards', sa.Column('permission_id',
                  mysql.INTEGER(display_width=11), autoincrement=False,
                  nullable=True))
    op.create_foreign_key(u'boards_ibfk_2', 'boards', 'permissions',
                          ['permission_id'], ['id'])

    session = api_base.get_session(in_request=False)
    to_delete = []
    for board in boards.get_all(session=session):
        for permission in board.permissions:
            to_delete.append(permission)

    for worklist in worklists.get_all(session=session):
        for permission in worklist.permissions:
            to_delete.append(permission)

    op.drop_table('worklist_permissions')
    op.drop_table('board_permissions')

    for permission in to_delete:
        api_base.entity_hard_delete(
            models.Permission, permission.id, session=session)
def upgrade(active_plugins=None, options=None):
    op.create_table('board_permissions',
        sa.Column('board_id', sa.Integer(), nullable=True),
        sa.Column('permission_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['board_id'], ['boards.id'], ),
        sa.ForeignKeyConstraint(['permission_id'], ['permissions.id'], )
    )
    op.create_table('worklist_permissions',
        sa.Column('worklist_id', sa.Integer(), nullable=True),
        sa.Column('permission_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['permission_id'], ['permissions.id'], ),
        sa.ForeignKeyConstraint(['worklist_id'], ['worklists.id'], )
    )

    session = api_base.get_session(in_request=False)
    for board in boards.get_all(session=session):
        edit_permission = {
            'name': 'edit_board_%d' % board.id,
            'codename': 'edit_board',
            'users': [board.creator_id]
        }
        move_permission = {
            'name': 'move_cards_%d' % board.id,
            'codename': 'move_cards',
            'users': []
        }
        print('Creating permissions for Board with id: %d' % board.id)
        boards.create_permission(board.id, edit_permission, session=session)
        boards.create_permission(board.id, move_permission, session=session)

    for worklist in worklists.get_all(session=session):
        edit_permission = {
            'name': 'edit_worklist_%d' % worklist.id,
            'codename': 'edit_worklist',
            'users': [worklist.creator_id]
        }
        move_permission = {
            'name': 'move_items_%d' % worklist.id,
            'codename': 'move_items',
            'users': []
        }
        print('Creating permissions for Worklist with id: %d' % worklist.id)
        worklists.create_permission(
            worklist.id, edit_permission, session=session)
        worklists.create_permission(
            worklist.id, move_permission, session=session)
        session.flush()

    dialect = op.get_bind().engine.dialect
    if dialect.supports_alter:
        op.drop_constraint(u'boards_ibfk_2', 'boards', type_='foreignkey')
        op.drop_column(u'boards', 'permission_id')
        op.drop_constraint(u'worklists_ibfk_2', 'worklists',
                           type_='foreignkey')
        op.drop_column(u'worklists', 'permission_id')
def upgrade(active_plugins=None, options=None):
    op.create_table('board_permissions',
        sa.Column('board_id', sa.Integer(), nullable=True),
        sa.Column('permission_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['board_id'], ['boards.id'], ),
        sa.ForeignKeyConstraint(['permission_id'], ['permissions.id'], )
    )
    op.create_table('worklist_permissions',
        sa.Column('worklist_id', sa.Integer(), nullable=True),
        sa.Column('permission_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['permission_id'], ['permissions.id'], ),
        sa.ForeignKeyConstraint(['worklist_id'], ['worklists.id'], )
    )

    session = api_base.get_session(in_request=False)
    for board in boards.get_all(session=session):
        edit_permission = {
            'name': 'edit_board_%d' % board.id,
            'codename': 'edit_board',
            'users': [board.creator_id]
        }
        move_permission = {
            'name': 'move_cards_%d' % board.id,
            'codename': 'move_cards',
            'users': []
        }
        print('Creating permissions for Board with id: %d' % board.id)
        boards.create_permission(board.id, edit_permission, session=session)
        boards.create_permission(board.id, move_permission, session=session)

    for worklist in worklists.get_all(session=session):
        edit_permission = {
            'name': 'edit_worklist_%d' % worklist.id,
            'codename': 'edit_worklist',
            'users': [worklist.creator_id]
        }
        move_permission = {
            'name': 'move_items_%d' % worklist.id,
            'codename': 'move_items',
            'users': []
        }
        print('Creating permissions for Worklist with id: %d' % worklist.id)
        worklists.create_permission(
            worklist.id, edit_permission, session=session)
        worklists.create_permission(
            worklist.id, move_permission, session=session)
        session.flush()

    op.drop_constraint(u'boards_ibfk_2', 'boards', type_='foreignkey')
    op.drop_column(u'boards', 'permission_id')
    op.drop_constraint(u'worklists_ibfk_2', 'worklists', type_='foreignkey')
    op.drop_column(u'worklists', 'permission_id')
Example #6
0
    def get_all(self, title=None, creator_id=None, project_id=None,
                archived=False, user_id=None, story_id=None, task_id=None,
                sort_field='id', sort_dir='asc'):
        """Retrieve definitions of all of the boards.

        :param title: A string to filter the title by.
        :param creator_id: Filter boards by their creator.
        :param project_id: Filter boards by project ID.
        :param archived: Filter boards by whether they are archived or not.
        :param story_id: Filter boards by whether they contain a story.
        :param task_id: Filter boards by whether they contain a task.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).

        """
        boards = boards_api.get_all(title=title,
                                    creator_id=creator_id,
                                    user_id=user_id,
                                    project_id=project_id,
                                    story_id=story_id,
                                    task_id=task_id,
                                    sort_field=sort_field,
                                    sort_dir=sort_dir)

        visible_boards = []
        user_id = request.current_user_id
        for board in boards:
            if boards_api.visible(board, user_id) and\
                    board.archived == archived:
                board_model = wmodels.Board.from_db_model(board)
                board_model.resolve_lanes(board, resolve_items=False)
                board_model.resolve_permissions(board)
                visible_boards.append(board_model)

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

        return visible_boards
Example #7
0
    def get_all(self,
                title=None,
                creator_id=None,
                project_id=None,
                archived=False,
                user_id=None,
                story_id=None,
                task_id=None,
                item_type=None,
                offset=None,
                limit=None,
                sort_field='id',
                sort_dir='asc'):
        """Retrieve definitions of all of the boards.

        :param title: A string to filter the title by.
        :param creator_id: Filter boards by their creator.
        :param project_id: Filter boards by project ID.
        :param archived: Filter boards by whether they are archived or not.
        :param story_id: Filter boards by whether they contain a story.
        :param task_id: Filter boards by whether they contain a task.
        :param item_type: Used when filtering by story_id. If
                          item_type is 'story' then only return
                          worklists that contain the story, if
                          item_type is 'task' then only return
                          worklists that contain tasks from the story,
                          otherwise return worklists that contain the
                          story or tasks from the story.
        :param offset: Value to offset results by.
        :param limit: Maximum number of results to return.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).

        """
        current_user = request.current_user_id
        boards = boards_api.get_all(title=title,
                                    creator_id=creator_id,
                                    user_id=user_id,
                                    project_id=project_id,
                                    story_id=story_id,
                                    task_id=task_id,
                                    item_type=item_type,
                                    offset=offset,
                                    limit=limit,
                                    current_user=current_user,
                                    sort_field=sort_field,
                                    sort_dir=sort_dir)
        count = boards_api.get_count(
            title=title,
            creator_id=creator_id,
            user_id=user_id,
            project_id=project_id,
            story_id=story_id,
            task_id=task_id,
            item_type=item_type,
            current_user=current_user,
        )

        visible_boards = []
        for board in boards:
            board_model = wmodels.Board.from_db_model(board)
            board_model.resolve_lanes(board, resolve_items=False)
            board_model.resolve_permissions(board)
            visible_boards.append(board_model)

        # Apply the query response headers
        response.headers['X-Total'] = str(count)
        if limit is not None:
            response.headers['X-Limit'] = str(limit)
        if offset is not None:
            response.headers['X-Offset'] = str(offset)

        return visible_boards