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 editable(worklist, user=None): if not worklist: return False if not user: return False if is_lane(worklist): board = boards.get_from_lane(worklist) permissions = boards.get_permissions(board, user) return any(name in permissions for name in ['edit_board', 'move_cards']) return 'edit_worklist' in get_permissions(worklist, user)
def visible(worklist, user=None, hide_lanes=False): if hide_lanes: if is_lane(worklist): return False if not worklist: return False if is_lane(worklist): board = boards.get_from_lane(worklist) permissions = boards.get_permissions(board, user) if board.private: return any(name in permissions for name in ['edit_board', 'move_cards']) return not board.private if user and worklist.private: permissions = get_permissions(worklist, user) return any(name in permissions for name in ['edit_worklist', 'move_items']) return not worklist.private
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) # If the target position is "outside" the list, override it if list_position > worklist.items.count(): list_position = worklist.items.count() # 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_item(archived.id, {'archived': False}) # Move the newly unarchived card into position, and move other cards # to compensate for the move move_item(archived.id, list_position) return archived # 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_item(archived.id, {'archived': False}) # Move the newly unarchived card into position, and move other # cards to compensate for the move move_item(archived.id, list_position, new_list_id=worklist_id) return archived # 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 }) card_dict = { 'list_id': worklist_id, 'item_id': item_id, 'item_type': item_type, 'list_position': 99999 # Initialise the card "outside" the list } card = api_base.entity_create(models.WorklistItem, card_dict) # Move the card into position, and move other cards to compensate card = move_item(card.id, list_position) if worklist.items is None: worklist.items = [card] else: worklist.items.append(card) return card