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)
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)
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)
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)
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
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
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)
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)
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)
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)
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)
def milestone_update(milestone_id, values): return api_base.entity_update(models.Milestone, milestone_id, values)
def project_group_update(project_group_id, values): return api_base.entity_update(models.ProjectGroup, project_group_id, values)
def update_item(item_id, updated): return api_base.entity_update(models.WorklistItem, item_id, updated)
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)
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)
def update(worklist_id, values): return api_base.entity_update(models.Worklist, worklist_id, values)
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)
def user_update(user_id, values): return api_base.entity_update(models.User, user_id, values)
def task_update(task_id, values): return api_base.entity_update(models.Task, task_id, values)
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
def story_update(story_id, values): api_base.entity_update(models.Story, story_id, values) return story_get(story_id)
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())
def team_update(team_id, values): return api_base.entity_update(models.Team, team_id, values)
def update(id, values): return api_base.entity_update(models.Board, id, values)
def comment_update(comment_id, values): return api_base.entity_update(models.Comment, comment_id, values)
def update(id, values): return api_base.entity_update(models.DueDate, id, values)
def story_update(story_id, values): return api_base.entity_update(models.Story, story_id, values)
def project_update(project_id, values): return api_base.entity_update(models.Project, project_id, values)
def tag_update(tag_id, values): return api_base.entity_update(models.StoryTag, tag_id, values)
def branch_update(branch_id, values): return api_base.entity_update(models.Branch, branch_id, values)