Ejemplo n.º 1
0
    def check_permission(self, user_id, task_id):
        """

        Checks if user with user_id have permission to task with task_id.

        :param user_id: unique user_id
        :param task_id: unique task_id
        :return: bool type. True if user have access, else raise exception
        """
        try:
            return task_storage.check_permission(user_id=user_id,
                                                 task_id=task_id)

        except ObjectNotFound:
            logger.error(errs.TaskNotExistError().name)
            raise errs.TaskNotExistError()
Ejemplo n.º 2
0
def create_periodic_task_comment(user_id, task_id, text, date):
    if task_storage.check_periodic_task_exist(task_id=task_id, user_id=user_id):
        task = PeriodicTask[task_id]

        if date and cph.in_period(task.period, date):
            task_storage.add_task(user_id=user_id, title=task.title, text=task.text, status=task.status, tags=task.tags,
                                  date=datetime.strptime(date, '%d/%m/%y'), parent_id=task.parent_id,
                                  periodic_task_id=task_id)
        else:
            raise errs.TaskNotExistError()
Ejemplo n.º 3
0
    def check_task_exist(self, task_id, user_id):
        """

        Checks if simple_task exist in current user with user_id.

        :param task_id:
        :param user_id:
        :return: True or raise exception
        """
        return_value = task_storage.check_task_exist(task_id=task_id,
                                                     user_id=user_id)

        if return_value == errs.TaskNotExistError().code:
            raise errs.TaskNotExistError()

        if return_value == errs.TaskWithParentIdNotExistError().code:
            logger.error(errs.TaskWithParentIdNotExistError().name)
            raise errs.TaskWithParentIdNotExistError()

        else:
            return True
Ejemplo n.º 4
0
def check_task_exist(task_id: int, user_id: int):
    """
    Checks if simple task with[task_id] belong to user with [user_id]
    :param task_id:
    :param user_id:
    :return: True if exist, else raise exception
    """
    task = Task.get(id=task_id)
    if task:
        if user_id in task.users:
            return True
        else:
            return errs.TaskNotExistError().code
    else:
        return errs.TaskWithParentIdNotExistError().code
Ejemplo n.º 5
0
def check_periodic_task_exist(task_id: int, user_id: int):
    """
    Checks if periodic task with [task_id] belong to user with[user_id]
    :param task_id:
    :param user_id:
    :return:
    """
    task = PeriodicTask.get(id=task_id)

    if task:
        if user_id in task.users:
            return True
        else:
            return errs.TaskWithParentIdNotExistError().code
    else:
        return errs.TaskNotExistError().code
Ejemplo n.º 6
0
    def edit_task(self, task_id: int, edited_task: typing.Dict):
        """

        Function which allows you edit the task parameters such title, text, date, period etc.

        :param task_id: task id
        :param edited_task: contains parameters of edited task.
        """
        if not self.check_permission(task_id=task_id, user_id=self.user_id):
            logger.error(errs.TaskNotExistError().name)
            raise errs.TaskNotExistError()

        task = task_storage.get_task_by_id(task_id=task_id)

        if 'date' in edited_task:
            try:
                date = datetime.strptime(edited_task['date'], '%d/%m/%y %H:%M')
                edited_task['date'] = date
            except ValueError:
                raise errs.IncorrectDateValueError()

        values = [str(item.value) for item in TaskStatus]

        if 'status' in edited_task and edited_task['status'] not in values:
            raise errs.StatusValueError()

        if not task['classtype'] == "PeriodicTask":
            return_value = task_storage.edit_task(task_id=task_id,
                                                  edited_task=edited_task)
            if return_value == errs.TaskNotExistError().code:
                raise errs.TaskNotExistError()

        if 'period' in edited_task and not self.period_helper.is_valid_cron(
                edited_task['period']):
            raise errs.CronValueError()

        if 'start_date' in edited_task:
            try:
                date = datetime.strptime(edited_task['start_date'],
                                         '%d/%m/%y %H:%M')
                edited_task['date'] = date
            except ValueError:
                raise errs.IncorrectDateValueError()

        return_value = task_storage.edit_periodic_task(task_id=task_id,
                                                       edited_task=edited_task)

        if return_value == errs.TaskNotExistError().code:
            raise errs.TaskNotExistError()
Ejemplo n.º 7
0
def edit_periodic_task(task_id: int, edited_task: typing.Dict):
    task = PeriodicTask[task_id]
    if task:
        task.set(**edited_task)
    else:
        return errs.TaskNotExistError().code