コード例 #1
0
def update_filter(filter_id, update):
    old_filter = api_base.entity_get(models.WorklistFilter, filter_id)
    if 'filter_criteria' in update:
        # Change the criteria for this filter. If an ID is provided, change
        # the criterion to match the provided criterion. If no ID is provided,
        # create a new criterion and add it to the filter.
        for criterion in update['filter_criteria']:
            criterion_dict = criterion.as_dict(omit_unset=True)
            if 'id' in criterion_dict:
                id = criterion_dict.pop('id')
                api_base.entity_update(models.FilterCriterion,
                                       id, criterion_dict)
            else:
                created = api_base.entity_create(models.FilterCriterion,
                                                 criterion_dict)
                criterion.id = created
                old_filter.criteria.append(created)

        # Remove criteria which aren't in the provided set
        new_ids = [criterion.id for criterion in update['filter_criteria']]
        for criterion in old_filter.criteria:
            if criterion.id not in new_ids:
                old_filter.criteria.remove(criterion)
        del update['filter_criteria']

    return api_base.entity_update(models.WorklistFilter, filter_id, update)
コード例 #2
0
ファイル: users.py プロジェクト: devcurmudgeon/storyboard
def user_update_preferences(user_id, preferences):
    for key in preferences:
        value = preferences[key]
        prefs = api_base.entity_get_all(models.UserPreference,
                                        user_id=user_id,
                                        key=key)

        if prefs:
            pref = prefs[0]
        else:
            pref = None

        # If the preference exists and it's null.
        if pref and value is None:
            api_base.entity_hard_delete(models.UserPreference, pref.id)
            continue

        # If the preference exists and has a new value.
        if pref and value and pref.cast_value != value:
            pref.cast_value = value
            api_base.entity_update(models.UserPreference, pref.id, dict(pref))
            continue

        # If the preference does not exist and a new value exists.
        if not pref and value:
            api_base.entity_create(models.UserPreference, {
                'user_id': user_id,
                'key': key,
                'cast_value': value
            })

    return user_get_preferences(user_id)
コード例 #3
0
def update_lane(board, lane, new_lane):
    # Make sure we aren't messing up the board ID
    new_lane['board_id'] = board.id

    if new_lane.get('list_id') is None:
        raise ClientSideError(_("A lane must have a worklist_id."))

    api_base.entity_update(models.BoardWorklist, lane.id, new_lane)
コード例 #4
0
ファイル: boards.py プロジェクト: palvarez89/storyboard
def update_lane(board, lane, new_lane):
    # Make sure we aren't messing up the board ID
    new_lane['board_id'] = board.id

    if new_lane.get('list_id') is None:
        raise ClientSideError(_("A lane must have a worklist_id."))

    api_base.entity_update(models.BoardWorklist, lane.id, new_lane)
コード例 #5
0
ファイル: stories.py プロジェクト: openstack-infra/storyboard
def story_update(story_id, values, current_user=None):
    api_base.entity_update(models.Story, story_id, values)
    project_ids = get_project_ids(story_id, current_user=current_user)

    for project_id in project_ids:
        projects_api.project_update_updated_at(project_id)

    return story_get(story_id, current_user=current_user)
コード例 #6
0
def story_update(story_id, values, current_user=None):
    api_base.entity_update(models.Story, story_id, values)
    project_ids = get_project_ids(story_id, current_user=current_user)

    for project_id in project_ids:
        projects_api.project_update_updated_at(project_id)

    return story_get(story_id, current_user=current_user)
コード例 #7
0
def add_item(worklist_id, item_id, item_type, list_position,
             current_user=None):
    worklist = _worklist_get(worklist_id)
    if worklist is None:
        raise exc.NotFound(_("Worklist %s not found") % worklist_id)

    # Check if this item has an archived card in this worklist to restore
    archived = get_item_by_item_id(
        worklist, item_type, item_id, archived=True)
    if archived:
        update = {
            'archived': False,
            'list_position': list_position
        }
        api_base.entity_update(models.WorklistItem, archived.id, update)
        return worklist

    # If this worklist is a lane, check if the item has an archived card
    # somewhere in the board to restore
    if is_lane(worklist):
        board = boards.get_from_lane(worklist)
        archived = boards.get_card(board, item_type, item_id, archived=True)
        if archived:
            update = {
                'archived': False,
                'list_id': worklist_id,
                'list_position': list_position
            }
            api_base.entity_update(models.WorklistItem, archived.id, update)
            return worklist

    # Create a new card
    if item_type == 'story':
        item = stories_api.story_get(item_id, current_user=current_user)
    elif item_type == 'task':
        item = tasks_api.task_get(item_id, current_user=current_user)
    else:
        raise ClientSideError(_("An item in a worklist must be either a "
                                "story or a task"))

    if item is None:
        raise exc.NotFound(_("%(type)s %(id)s not found") %
                           {'type': item_type, 'id': item_id})

    item_dict = {
        'list_id': worklist_id,
        'item_id': item_id,
        'item_type': item_type,
        'list_position': list_position
    }
    worklist_item = api_base.entity_create(models.WorklistItem, item_dict)

    if worklist.items is None:
        worklist.items = [worklist_item]
    else:
        worklist.items.append(worklist_item)

    return worklist
コード例 #8
0
ファイル: worklists.py プロジェクト: palvarez89/storyboard
def add_item(worklist_id, item_id, item_type, list_position,
             current_user=None):
    worklist = _worklist_get(worklist_id)
    if worklist is None:
        raise exc.NotFound(_("Worklist %s not found") % worklist_id)

    # Check if this item has an archived card in this worklist to restore
    archived = get_item_by_item_id(
        worklist, item_type, item_id, archived=True)
    if archived:
        update = {
            'archived': False,
            'list_position': list_position
        }
        api_base.entity_update(models.WorklistItem, archived.id, update)
        return worklist

    # If this worklist is a lane, check if the item has an archived card
    # somewhere in the board to restore
    if is_lane(worklist):
        board = boards.get_from_lane(worklist)
        archived = boards.get_card(board, item_type, item_id, archived=True)
        if archived:
            update = {
                'archived': False,
                'list_id': worklist_id,
                'list_position': list_position
            }
            api_base.entity_update(models.WorklistItem, archived.id, update)
            return worklist

    # Create a new card
    if item_type == 'story':
        item = stories_api.story_get(item_id, current_user=current_user)
    elif item_type == 'task':
        item = tasks_api.task_get(item_id, current_user=current_user)
    else:
        raise ClientSideError(_("An item in a worklist must be either a "
                                "story or a task"))

    if item is None:
        raise exc.NotFound(_("%(type)s %(id)s not found") %
                           {'type': item_type, 'id': item_id})

    item_dict = {
        'list_id': worklist_id,
        'item_id': item_id,
        'item_type': item_type,
        'list_position': list_position
    }
    worklist_item = api_base.entity_create(models.WorklistItem, item_dict)

    if worklist.items is None:
        worklist.items = [worklist_item]
    else:
        worklist.items.append(worklist_item)

    return worklist
コード例 #9
0
ファイル: tasks.py プロジェクト: RadwaSK/storyboard
def task_update(task_id, values):
    task = api_base.entity_update(models.Task, task_id, values)
    if task:
        stories_api.story_update_updated_at(task.story_id)
        # Update updated_at in projects when task is updated
        projects_api.project_update_updated_at(task.project_id)
    return task
コード例 #10
0
def comment_update(comment_id, values):
    comment = api_base.entity_get(models.Comment, comment_id)
    old_dict = {
        'comment_id': comment_id,
        'content': comment.content
    }
    api_base.entity_create(models.HistoricalComment, old_dict)
    return api_base.entity_update(models.Comment, comment_id, values)
コード例 #11
0
ファイル: users.py プロジェクト: openstack-infra/storyboard
def user_update_preferences(user_id, preferences):
    for key in preferences:
        value = preferences[key]
        prefs = api_base.entity_get_all(models.UserPreference,
                                        user_id=user_id,
                                        key=key)

        matching_prefs = []
        if prefs:
            for p in prefs:
                if p.key == key:
                    # FIXME: We create a list here because there appears to
                    # currently be a bug which means that each preference may
                    # appear more than once per-user. We should fix that once
                    # we discover the cause.
                    matching_prefs.append(p)
        else:
            pref = None

        for pref in matching_prefs:
            # If the preference exists and it's null.
            if pref and value is None:
                api_base.entity_hard_delete(models.UserPreference, pref.id)
                continue

            # If the preference exists and has a new value.
            if pref and value is not None and pref.cast_value != value:
                pref.cast_value = value
                api_base.entity_update(
                    models.UserPreference, pref.id, dict(pref))
                continue

        # If the preference does not exist and a new value exists.
        if not matching_prefs and value is not None:
            api_base.entity_create(models.UserPreference, {
                'user_id': user_id,
                'key': key,
                'cast_value': value
            })

    return user_get_preferences(user_id)
コード例 #12
0
def user_update_preferences(user_id, preferences):
    for key in preferences:
        value = preferences[key]
        prefs = api_base.entity_get_all(models.UserPreference,
                                        user_id=user_id,
                                        key=key)

        matching_prefs = []
        if prefs:
            for p in prefs:
                if p.key == key:
                    # FIXME: We create a list here because there appears to
                    # currently be a bug which means that each preference may
                    # appear more than once per-user. We should fix that once
                    # we discover the cause.
                    matching_prefs.append(p)
        else:
            pref = None

        for pref in matching_prefs:
            # If the preference exists and it's null.
            if pref and value is None:
                api_base.entity_hard_delete(models.UserPreference, pref.id)
                continue

            # If the preference exists and has a new value.
            if pref and value is not None and pref.cast_value != value:
                pref.cast_value = value
                api_base.entity_update(
                    models.UserPreference, pref.id, dict(pref))
                continue

        # If the preference does not exist and a new value exists.
        if not matching_prefs and value is not None:
            api_base.entity_create(models.UserPreference, {
                'user_id': user_id,
                'key': key,
                'cast_value': value
            })

    return user_get_preferences(user_id)
コード例 #13
0
ファイル: worklists.py プロジェクト: palvarez89/storyboard
def update_filter(filter_id, update):
    old_filter = api_base.entity_get(models.WorklistFilter, filter_id)
    if 'filter_criteria' in update:
        new_ids = [criterion.id for criterion in update['filter_criteria']]
        for criterion in update['filter_criteria']:
            criterion_dict = criterion.as_dict(omit_unset=True)
            if 'id' in criterion_dict:
                existing = api_base.entity_get(models.FilterCriterion,
                                               criterion['id'])
                if existing.as_dict() != criterion_dict:
                    api_base.entity_update(models.FilterCriterion,
                                           criterion_dict['id'],
                                           criterion_dict)
            else:
                created = api_base.entity_create(models.FilterCriterion,
                                                 criterion_dict)
                old_filter.criteria.append(created)
        for criterion in old_filter.criteria:
            if criterion.id not in new_ids:
                old_filter.criteria.remove(criterion)
        del update['filter_criteria']

    return api_base.entity_update(models.WorklistFilter, filter_id, update)
コード例 #14
0
ファイル: worklists.py プロジェクト: palvarez89/storyboard
def update_filter(filter_id, update):
    old_filter = api_base.entity_get(models.WorklistFilter, filter_id)
    if 'filter_criteria' in update:
        new_ids = [criterion.id for criterion in update['filter_criteria']]
        for criterion in update['filter_criteria']:
            criterion_dict = criterion.as_dict(omit_unset=True)
            if 'id' in criterion_dict:
                existing = api_base.entity_get(models.FilterCriterion,
                                               criterion['id'])
                if existing.as_dict() != criterion_dict:
                    api_base.entity_update(models.FilterCriterion,
                                           criterion_dict['id'],
                                           criterion_dict)
            else:
                created = api_base.entity_create(models.FilterCriterion,
                                                 criterion_dict)
                old_filter.criteria.append(created)
        for criterion in old_filter.criteria:
            if criterion.id not in new_ids:
                old_filter.criteria.remove(criterion)
        del update['filter_criteria']

    return api_base.entity_update(models.WorklistFilter, filter_id, update)
コード例 #15
0
def update_permission(story, users, session=None):
    story = api_base.model_query(models.Story, session) \
        .options(subqueryload(models.Story.tags)) \
        .filter_by(id=story.id).first()
    if not story.permissions:
        raise exc.NotFound(_("Permissions for story %d not found.") % story.id)
    permission = story.permissions[0]
    permission_dict = {
        'name': permission.name,
        'codename': permission.codename,
        'users': [users_api.user_get(user.id) for user in users]
    }

    return api_base.entity_update(models.Permission, permission.id,
                                  permission_dict)
コード例 #16
0
def update_permission(due_date_id, permission_dict):
    due_date = _due_date_get(due_date_id)
    id = None
    for permission in due_date.permissions:
        if permission.codename == permission_dict['codename']:
            id = permission.id
    users = permission_dict.pop('users')
    permission_dict['users'] = []
    for user_id in users:
        user = users_api.user_get(user_id)
        permission_dict['users'].append(user)

    if id is None:
        raise ClientSideError(_("Permission %s does not exist")
                              % permission_dict['codename'])
    return api_base.entity_update(models.Permission, id, permission_dict)
コード例 #17
0
ファイル: due_dates.py プロジェクト: ColdrickSotK/storyboard
def update_permission(due_date_id, permission_dict):
    due_date = _due_date_get(due_date_id)
    id = None
    for permission in due_date.permissions:
        if permission.codename == permission_dict['codename']:
            id = permission.id
    users = permission_dict.pop('users')
    permission_dict['users'] = []
    for user_id in users:
        user = users_api.user_get(user_id)
        permission_dict['users'].append(user)

    if id is None:
        raise ClientSideError(_("Permission %s does not exist")
                              % permission_dict['codename'])
    return api_base.entity_update(models.Permission, id, permission_dict)
コード例 #18
0
ファイル: stories.py プロジェクト: palvarez89/storyboard
def update_permission(story, users, session=None):
    story = api_base.model_query(models.Story, session) \
        .options(subqueryload(models.Story.tags)) \
        .filter_by(id=story.id).first()
    if not story.permissions:
        raise exc.NotFound(_("Permissions for story %d not found.")
                           % story.id)
    permission = story.permissions[0]
    permission_dict = {
        'name': permission.name,
        'codename': permission.codename,
        'users': [users_api.user_get(user.id) for user in users]
    }

    return api_base.entity_update(models.Permission,
                                  permission.id,
                                  permission_dict)
コード例 #19
0
def milestone_update(milestone_id, values):
    return api_base.entity_update(models.Milestone, milestone_id, values)
コード例 #20
0
def project_group_update(project_group_id, values):
    return api_base.entity_update(models.ProjectGroup, project_group_id,
                                  values)
コード例 #21
0
ファイル: worklists.py プロジェクト: palvarez89/storyboard
def update_item(item_id, updated):
    return api_base.entity_update(models.WorklistItem, item_id, updated)
コード例 #22
0
ファイル: users.py プロジェクト: openstack-infra/storyboard
def user_update(user_id, values, filter_non_public=False):
    return api_base.entity_update(models.User, user_id, values,
                                  filter_non_public=filter_non_public)
コード例 #23
0
def access_token_update(access_token_id, values):
    values['expires_at'] = values['created_at'] + datetime.timedelta(
        seconds=values['expires_in'])

    return api_base.entity_update(models.AccessToken, access_token_id, values)
コード例 #24
0
ファイル: worklists.py プロジェクト: palvarez89/storyboard
def update(worklist_id, values):
    return api_base.entity_update(models.Worklist, worklist_id, values)
コード例 #25
0
ファイル: stories.py プロジェクト: palvarez89/storyboard
def story_update(story_id, values, current_user=None):
    api_base.entity_update(models.Story, story_id, values)
    return story_get(story_id, current_user=current_user)
コード例 #26
0
def update(worklist_id, values):
    return api_base.entity_update(models.Worklist, worklist_id, values)
コード例 #27
0
ファイル: users.py プロジェクト: devcurmudgeon/storyboard
def user_update(user_id, values):
    return api_base.entity_update(models.User, user_id, values)
コード例 #28
0
def project_group_update(project_group_id, values):
    return api_base.entity_update(models.ProjectGroup, project_group_id,
                                  values)
コード例 #29
0
ファイル: tasks.py プロジェクト: palvarez89/storyboard
def task_update(task_id, values):
    return api_base.entity_update(models.Task, task_id, values)
コード例 #30
0
def task_update(task_id, values):
    task = api_base.entity_update(models.Task, task_id, values)

    if task:
        stories_api.story_update_updated_at(task.story_id)
    return task
コード例 #31
0
ファイル: stories.py プロジェクト: ColdrickSotK/storyboard
def story_update(story_id, values):
    api_base.entity_update(models.Story, story_id, values)
    return story_get(story_id)
コード例 #32
0
def comment_delete(comment_id):
    comment = comment_get(comment_id)

    if comment:
        comment.is_active = False
        api_base.entity_update(models.Task, comment_id, comment.as_dict())
コード例 #33
0
def update_item(item_id, updated):
    return api_base.entity_update(models.WorklistItem, item_id, updated)
コード例 #34
0
ファイル: milestones.py プロジェクト: ColdrickSotK/storyboard
def milestone_update(milestone_id, values):
    return api_base.entity_update(models.Milestone, milestone_id, values)
コード例 #35
0
ファイル: teams.py プロジェクト: openstack-infra/storyboard
def team_update(team_id, values):
    return api_base.entity_update(models.Team, team_id,
                                  values)
コード例 #36
0
def user_update(user_id, values, filter_non_public=False):
    return api_base.entity_update(models.User,
                                  user_id,
                                  values,
                                  filter_non_public=filter_non_public)
コード例 #37
0
def update(id, values):
    return api_base.entity_update(models.Board, id, values)
コード例 #38
0
def comment_update(comment_id, values):
    return api_base.entity_update(models.Comment, comment_id, values)
コード例 #39
0
def team_update(team_id, values):
    return api_base.entity_update(models.Team, team_id, values)
コード例 #40
0
def update(id, values):
    return api_base.entity_update(models.DueDate, id, values)
コード例 #41
0
ファイル: stories.py プロジェクト: pombredanne/storyboard
def story_update(story_id, values):
    return api_base.entity_update(models.Story, story_id, values)
コード例 #42
0
ファイル: due_dates.py プロジェクト: ColdrickSotK/storyboard
def update(id, values):
    return api_base.entity_update(models.DueDate, id, values)
コード例 #43
0
def user_update(user_id, values):
    return api_base.entity_update(models.User, user_id, values)
コード例 #44
0
ファイル: projects.py プロジェクト: RadwaSK/storyboard
def project_update(project_id, values):
    return api_base.entity_update(models.Project, project_id, values)
コード例 #45
0
ファイル: story_tags.py プロジェクト: ColdrickSotK/storyboard
def tag_update(tag_id, values):
    return api_base.entity_update(models.StoryTag, tag_id, values)
コード例 #46
0
ファイル: projects.py プロジェクト: devcurmudgeon/storyboard
def project_update(project_id, values):
    return api_base.entity_update(models.Project, project_id, values)
コード例 #47
0
ファイル: branches.py プロジェクト: palvarez89/storyboard
def branch_update(branch_id, values):
    return api_base.entity_update(models.Branch, branch_id, values)
コード例 #48
0
def tag_update(tag_id, values):
    return api_base.entity_update(models.StoryTag, tag_id, values)
コード例 #49
0
ファイル: boards.py プロジェクト: palvarez89/storyboard
def update(id, values):
    return api_base.entity_update(models.Board, id, values)
コード例 #50
0
def story_update(story_id, values, current_user=None):
    api_base.entity_update(models.Story, story_id, values)
    return story_get(story_id, current_user=current_user)
コード例 #51
0
def access_token_update(access_token_id, values):
    values['expires_at'] = values['created_at'] + datetime.timedelta(
        seconds=values['expires_in'])

    return api_base.entity_update(models.AccessToken, access_token_id, values)