def add_reminder(user_name, description=None, start_remind_before=None, start_remind_from=None, stop_remind_in=None, remind_in=None, datetimes=None, interval=None, weekdays=None): """Create reminder, save it and attach it to user. :param user_name: :param description: :param start_remind_before: :param start_remind_from: :param stop_remind_in: :param remind_in: :param datetimes: :param interval: :param weekdays: :return: """ reminder = Reminder.create(description, start_remind_before, start_remind_from, stop_remind_in, remind_in, datetimes, interval, weekdays) reminder.user = get_user(user_name) reminder.save() return reminder.id
def wrapper(username, reminder_id, *args, **kwargs): user = get_user(username) reminder = get_reminder(reminder_id) if reminder.user.name == user.name: func(username, reminder_id, *args, **kwargs) else: msg = ("Permission denied, you can't " "edit '{}' reminder.").format(reminder.id) raise PermissionError(msg)
def remove_owners_from_plan(username, plan_id, owners): """Remove owners from plan. :param user_name: users name, who makes query. :param plan_id: plan id :param owners: list of owners ids """ plan = get_plan(plan_id) for owner in owners: user = get_user(owner) try: relation = UserPlans.objects.get(user=user, plan=plan) relation.delete() except: continue
def add_owners_to_plan(user_name, plan_id, owners): """Adds owners to plan. :param user_name: users name, who makes query. :param plan_id: plan id :param owners: list of owners ids """ plan = get_plan(plan_id) for owner in owners: user = get_user(owner.user_name) relation = UserPlans(user=user, plan=plan, assign_date=datetime.now(), access_level=owner.access_level) relation.save()
def remove_participants_from_event(username, event_id, participants): """Removes participants from event. :param user_name: users name, who makes query :param event_id: event id :param participants: list of participants """ event = get_event(event_id) for participant in participants: user = get_user(participant) try: relation = UserEvents.objects.get(user=user, event=event) relation.delete() except: continue
def remove_owners_from_task(username, task_id, owners): """Removes owners from task. :param user_name: users name, who makes query :param task_id: task id :param owners: list of owners """ task = get_task(task_id) for owner in owners: user = get_user(owner) try: relation = UserTasks.objects.get(user=user, task=task) relation.delete() except: continue
def wrapper(username, plan_id, *args, **kwargs): if not username == ADMINS_NAME: user = get_user(username) plan = get_plan(plan_id) try: relation = UserPlans.objects.get(user=user, plan=plan) except ObjectDoesNotExist: msg = ("Invalid operation, you are not the owner " "of the '{}' plan.").format(plan.id) raise PermissionError(msg) if relation.access_level == AccessLevels.EDIT.value: func(username, plan_id, *args, **kwargs) else: msg = ("Permission denied, you can't " "edit '{}' plan.").format(plan.id) raise PermissionError(msg) else: func(username, plan_id, *args, **kwargs)
def add_participants_to_event(user_name, event_id, participants): """Adds participants to event. :param user_name: users name, who makes query :param event_id: event id :param participants: list of participants :return: """ event = get_event(event_id) for participant in participants: user = get_user(participant.user_name) try: relation = UserEvents.objects.get(user=user, event=event) except: relation = UserEvents(user=user, event=event, assign_date=datetime.now(), access_level=participant.access_level) relation.save()
def add_owners_to_task(user_name, task_id, owners): """Adds owners to task. :param user_name: users name, who makes query :param task_id: task id :param owners: list of owners :return: """ task = get_task(task_id) for owner in owners: user = get_user(owner.user_name) try: relation = UserTasks.objects.get(user=user, task=task) except: relation = UserTasks(user=user, task=task, assign_date=datetime.now(), access_level=owner.access_level) relation.save()
def remove_user(name): """ Remove user """ get_user(name).delete()