Ejemplo n.º 1
0
 def resolve_item(self, item):
     user_id = request.current_user_id
     if item.item_type == 'story':
         story = stories_api.story_get(item.item_id,
                                       current_user=request.current_user_id)
         if story is None:
             return False
         self.story = Story.from_db_model(story)
         due_dates = [
             date.id for date in story.due_dates
             if due_dates_api.visible(date, user_id)
         ]
         self.story.due_dates = due_dates
     elif item.item_type == 'task':
         task = tasks_api.task_get(item.item_id,
                                   current_user=request.current_user_id)
         if task is None or task.story is None:
             return False
         self.task = Task.from_db_model(task)
         due_dates = [
             date.id for date in task.due_dates
             if due_dates_api.visible(date, user_id)
         ]
         self.task.due_dates = due_dates
     return True
Ejemplo n.º 2
0
 def resolve_item(self, item, story_cache, task_cache, due_dates=True):
     user_id = request.current_user_id
     if item.item_type == 'story':
         story = story_cache.get(item.item_id) or stories_api.story_get(
             item.item_id, current_user=request.current_user_id)
         if story is None:
             return False
         self.story = Story.from_db_model(story)
         if due_dates:
             self.story.due_dates = [
                 date.id for date in story.due_dates
                 if due_dates_api.visible(date, user_id)
             ]
     elif item.item_type == 'task':
         task = task_cache.get(item.item_id) or tasks_api.task_get(
             item.item_id, current_user=request.current_user_id)
         if task is None or task.story is None:
             return False
         self.task = Task.from_db_model(task)
         if due_dates:
             self.task.due_dates = [
                 date.id for date in task.due_dates
                 if due_dates_api.visible(date, user_id)
             ]
     return True
Ejemplo n.º 3
0
    def get_all(self, name=None, date=None, board_id=None, worklist_id=None,
                user=None, owner=None, sort_field='id', sort_dir='asc'):
        """Retrieve details about all the due dates.

        :param name: The name of the due date.
        :param date: The date of the due date.
        :param board_id: The ID of a board to filter by.
        :param worklist_id: The ID of a worklist to filter by.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).

        """
        due_dates = due_dates_api.get_all(name=name,
                                          date=date,
                                          board_id=board_id,
                                          worklist_id=worklist_id,
                                          user=user,
                                          owner=owner,
                                          sort_field=sort_field,
                                          sort_dir=sort_dir)
        visible_dates = []
        for due_date in due_dates:
            if due_dates_api.visible(due_date, request.current_user_id):
                due_date_model = wmodels.DueDate.from_db_model(due_date)
                due_date_model.resolve_items(due_date)
                due_date_model.resolve_permissions(due_date)
                visible_dates.append(due_date_model)

        response.headers['X-Total'] = str(len(visible_dates))

        return visible_dates
Ejemplo n.º 4
0
    def get_all(self, name=None, date=None, board_id=None, worklist_id=None,
                user=None, owner=None, sort_field='id', sort_dir='asc'):
        """Retrieve details about all the due dates.

        :param name: The name of the due date.
        :param date: The date of the due date.
        :param board_id: The ID of a board to filter by.
        :param worklist_id: The ID of a worklist to filter by.
        :param sort_field: The name of the field to sort on.
        :param sort_dir: Sort direction for results (asc, desc).

        """
        due_dates = due_dates_api.get_all(name=name,
                                          date=date,
                                          board_id=board_id,
                                          worklist_id=worklist_id,
                                          user=user,
                                          owner=owner,
                                          sort_field=sort_field,
                                          sort_dir=sort_dir)
        visible_dates = []
        for due_date in due_dates:
            if due_dates_api.visible(due_date, request.current_user_id):
                due_date_model = wmodels.DueDate.from_db_model(due_date)
                due_date_model.resolve_items(due_date)
                due_date_model.resolve_permissions(due_date)
                visible_dates.append(due_date_model)

        response.headers['X-Total'] = str(len(visible_dates))

        return visible_dates
Ejemplo n.º 5
0
 def resolve_due_date(self, worklist_item):
     if not worklist_item.display_due_date:
         self.resolved_due_date = None
         return
     due_date = due_dates_api.get(worklist_item.display_due_date)
     resolved = None
     if due_dates_api.visible(due_date, request.current_user_id):
         resolved = DueDate.from_db_model(due_date)
     self.resolved_due_date = resolved
Ejemplo n.º 6
0
    def put(self, id, due_date):
        """Modify a due date.

        :param id: The ID of the due date to edit.
        :param due_date: The new due date within the request body.

        """
        if not due_dates_api.assignable(due_dates_api.get(id), request.current_user_id):
            raise exc.NotFound(_("Due date %s not found") % id)

        original_due_date = due_dates_api.get(id)

        due_date_dict = due_date.as_dict(omit_unset=True)
        editing = any(prop in due_date_dict for prop in ("name", "date", "private"))
        if editing and not due_dates_api.editable(original_due_date, request.current_user_id):
            raise exc.NotFound(_("Due date %s not found") % id)

        if due_date.creator_id and due_date.creator_id != original_due_date.creator_id:
            abort(400, _("You can't select the creator of a due date."))

        if "tasks" in due_date_dict:
            tasks = due_date_dict.pop("tasks")
            db_tasks = []
            for task in tasks:
                db_tasks.append(tasks_api.task_get(task.id, current_user=request.current_user_id))
            due_date_dict["tasks"] = db_tasks

        if "stories" in due_date_dict:
            stories = due_date_dict.pop("stories")
            db_stories = []
            for story in stories:
                db_stories.append(stories_api.story_get_simple(story.id, current_user=request.current_user_id))
            due_date_dict["stories"] = db_stories

        board = None
        worklist = None
        if "board_id" in due_date_dict:
            board = boards_api.get(due_date_dict["board_id"])

        if "worklist_id" in due_date_dict:
            worklist = worklists_api.get(due_date_dict["worklist_id"])

        updated_due_date = due_dates_api.update(id, due_date_dict)

        if board:
            updated_due_date.boards.append(board)

        if worklist:
            updated_due_date.worklists.append(worklist)

        if due_dates_api.visible(updated_due_date, request.current_user_id):
            due_date_model = wmodels.DueDate.from_db_model(updated_due_date)
            due_date_model.resolve_items(updated_due_date)
            due_date_model.resolve_permissions(updated_due_date, request.current_user_id)
            return due_date_model
        else:
            raise exc.NotFound(_("Due date %s not found") % id)
Ejemplo n.º 7
0
 def resolve_due_date(self, worklist_item):
     if not worklist_item.display_due_date:
         self.resolved_due_date = None
         return
     due_date = due_dates_api.get(worklist_item.display_due_date)
     resolved = None
     if due_dates_api.visible(due_date, request.current_user_id):
         resolved = DueDate.from_db_model(due_date)
     self.resolved_due_date = resolved
Ejemplo n.º 8
0
 def resolve_due_dates(self, board):
     self.due_dates = []
     for due_date in board.due_dates:
         if due_dates_api.visible(due_date, request.current_user_id):
             due_date_model = DueDate.from_db_model(due_date)
             due_date_model.resolve_items(due_date)
             due_date_model.resolve_permissions(
                 due_date, request.current_user_id)
             due_date_model.resolve_count_in_board(due_date, board)
             self.due_dates.append(due_date_model)
Ejemplo n.º 9
0
 def resolve_due_dates(self, board):
     self.due_dates = []
     for due_date in board.due_dates:
         if due_dates_api.visible(due_date, request.current_user_id):
             due_date_model = DueDate.from_db_model(due_date)
             due_date_model.resolve_items(due_date)
             due_date_model.resolve_permissions(due_date,
                                                request.current_user_id)
             due_date_model.resolve_count_in_board(due_date, board)
             self.due_dates.append(due_date_model)
Ejemplo n.º 10
0
    def get(self, due_date_id):
        """Get due date permissions for the current user.

        :param due_date_id: The ID of the due date.

        """
        due_date = due_dates_api.get(due_date_id)
        if due_dates_api.visible(due_date, request.current_user_id):
            return due_dates_api.get_permissions(due_date, request.current_user_id)
        else:
            raise exc.NotFound(_("Due date %s not found") % due_date_id)
Ejemplo n.º 11
0
    def get(self, due_date_id):
        """Get due date permissions for the current user.

        :param due_date_id: The ID of the due date.

        """
        due_date = due_dates_api.get(due_date_id)
        if due_dates_api.visible(due_date, request.current_user_id):
            return due_dates_api.get_permissions(due_date,
                                                 request.current_user_id)
        else:
            raise exc.NotFound(_("Due date %s not found") % due_date_id)
Ejemplo n.º 12
0
    def get_one(self, id):
        """Retrieve details about one due date.

        :param id: The ID of the due date.

        """
        due_date = due_dates_api.get(id)

        if due_dates_api.visible(due_date, request.current_user_id):
            due_date_model = wmodels.DueDate.from_db_model(due_date)
            due_date_model.resolve_items(due_date)
            due_date_model.resolve_permissions(due_date)
            return due_date_model
        else:
            return exc.NotFound(_("Due date %s not found") % id)
Ejemplo n.º 13
0
    def get_one(self, id):
        """Retrieve details about one due date.

        :param id: The ID of the due date.

        """
        due_date = due_dates_api.get(id)

        if due_dates_api.visible(due_date, request.current_user_id):
            due_date_model = wmodels.DueDate.from_db_model(due_date)
            due_date_model.resolve_items(due_date)
            due_date_model.resolve_permissions(due_date)
            return due_date_model
        else:
            return exc.NotFound(_("Due date %s not found") % id)
Ejemplo n.º 14
0
    def put(self, id, due_date):
        """Modify a due date.

        :param id: The ID of the due date to edit.
        :param due_date: The new due date within the request body.

        """
        if not due_dates_api.assignable(due_dates_api.get(id),
                                        request.current_user_id):
            raise exc.NotFound(_("Due date %s not found") % id)

        original_due_date = due_dates_api.get(id)

        due_date_dict = due_date.as_dict(omit_unset=True)
        editing = any(prop in due_date_dict
                      for prop in ('name', 'date', 'private'))
        if editing and not due_dates_api.editable(original_due_date,
                                                  request.current_user_id):
            raise exc.NotFound(_("Due date %s not found") % id)

        if due_date.creator_id \
                and due_date.creator_id != original_due_date.creator_id:
            abort(400, _("You can't select the creator of a due date."))

        if 'tasks' in due_date_dict:
            tasks = due_date_dict.pop('tasks')
            db_tasks = []
            for task in tasks:
                db_tasks.append(tasks_api.task_get(
                    task.id, current_user=request.current_user_id))
            due_date_dict['tasks'] = db_tasks

        if 'stories' in due_date_dict:
            stories = due_date_dict.pop('stories')
            db_stories = []
            for story in stories:
                db_stories.append(stories_api.story_get_simple(
                    story.id, current_user=request.current_user_id))
            due_date_dict['stories'] = db_stories

        board = None
        worklist = None
        if 'board_id' in due_date_dict:
            board = boards_api.get(due_date_dict['board_id'])

        if 'worklist_id' in due_date_dict:
            worklist = worklists_api.get(due_date_dict['worklist_id'])

        updated_due_date = due_dates_api.update(id, due_date_dict)

        if board:
            updated_due_date.boards.append(board)

        if worklist:
            updated_due_date.worklists.append(worklist)

        if due_dates_api.visible(updated_due_date, request.current_user_id):
            due_date_model = wmodels.DueDate.from_db_model(updated_due_date)
            due_date_model.resolve_items(updated_due_date)
            due_date_model.resolve_permissions(updated_due_date,
                                               request.current_user_id)
            return due_date_model
        else:
            raise exc.NotFound(_("Due date %s not found") % id)