def task_manage_participant(task_id, user, project_id, participant_id, is_add=True): c, p, task = before_task_service(pid=project_id, tid=task_id, user=user) if c is not None: return c participant = User.get_user_by_id(participant_id) if participant is None: return code_list.UserNotExist if not p.has_member(participant): return code_list.NotInProject if is_add: if task.has_participant(participant): return code_list.InParticipant task.add_participant(participant) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.task_add_participant.name, content=participant.username, link=task.link) else: if not task.has_participant(participant): return code_list.NotInParticipant task.remove_participant(participant) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.task_remove_participant.name, content=participant.username, link=task.link) return code_list.Success
def project_manage_admin(project_id, user_id, admin, is_add=True): c, p = before_project_service(project_id, admin) if c is not None: return c if p.user_id != admin.id: return code_list.NotProjectOriginator user = User.get_user_by_id(user_id) if user is None: return code_list.UserNotExist if user.id == admin.id: return code_list.OperatorError if not p.has_member(user): return code_list.NotInProject if is_add: p.add_admin(user) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.project_add_admin.name, content=p.name, link=p.link) else: p.remove_admin(user) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.project_remove_admin.name, content=p.name, link=p.link) return code_list.Success
def new_project(name, user): p = Project.new(name, user) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.project_create.name, content=name, link=p.link) return code_list.Success, {"id": p.id}
def schedule_delete(sid, pid, user): e, p, s = before_schedule_service(pid=pid, user=user, sid=sid) if e is not None: return e s.delete() Action.new(user_id=user.id, project_id=p.id, type_name=action_type.schedule_delete.name, content=s.content, link=s.link) return code_list.Success
def task_delete(task_id, user, project_id): c, p, task = before_task_service(pid=project_id, tid=task_id, user=user) if c is not None: return c task.delete() Action.new(user_id=user.id, project_id=p.id, type_name=action_type.task_delete.name, content=task.name, link=task.link) return code_list.Success
def project_delete(project_id, user): c, p = before_project_service(project_id, user) if c is not None: return c if p.user_id != user.id: return code_list.NotProjectOriginator p.delete() Action.new(user_id=user.id, project_id=p.id, type_name=action_type.project_delete.name, content=p.name, link=p.link) return code_list.Success
def project_member_manage(project_id, account, admin, is_add=True, account_type="id"): c, p = before_project_service(pid=project_id, user=admin) if c is not None: return c if account_type == "email": user = User.get_user_by_email(account) elif account_type == "phone": user = User.get_user_by_phone(account) elif account_type == "id": user = User.get_user_by_id(account) else: return code_list.ParamsWrong.with_message("未开放类型") if user is None: return code_list.UserNotExist if user.id == admin.id: return code_list.OperatorError g = Group.query.filter_by(project_id=project_id, is_all=True).first() if is_add: if p.has_member(user): return code_list.InProject p.add_member(user) g.add(user) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.project_join.name, content=p.name, link=p.link) else: if not p.has_member(user): return code_list.NotInProject p.remove_member(user) g.remove(user) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.project_leave.name, content=p.name, link=p.link) return code_list.Success
def schedule_update(sid, pid, user, content, remarks, t_set, label): e, p, s = before_schedule_service(pid=pid, user=user, sid=sid) if e is not None: return e if len(label) > 5: if not all([len(la) <= 5 for la in label.split(' ')]): return code_list.LabelTooLong s.update(content=content, remarks=remarks, t_set=t_set, label=label) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.schedule_update.name, content=s.content, link=s.link) return code_list.Success
def task_update(task_id, user, project_id, name, remarks, t_begin, t_end, priority, label, finish): c, p, task = before_task_service(pid=project_id, tid=task_id, user=user) if c is not None: return c task.update(name=name, remarks=remarks, t_begin=t_begin, t_end=t_end, priority=priority, label=label, finish=finish) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.task_update.name, content=name, link=task.link) return code_list.Success
def task_create(project_id, user, name, remarks, t_begin, t_end, priority, label): c, p = before_project_service(pid=project_id, user=user) if c is not None: return c if len(label) > 5: if not all([len(la) <= 5 for la in label.split(' ')]): return code_list.LabelTooLong task = Task.new(name, p.id, user.id, remarks=remarks, t_begin=t_begin, t_end=t_end, priority=priority, label=label) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.task_create.name, content=name, link=task.link) return code_list.Success
def schedule_create(pid, user, content, remarks, t_set, t_remind, label): e, p = before_project_service(pid, user) if e is not None: return e, None if len(label) > 5: if not all([len(la) <= 5 for la in label.split(' ')]): return code_list.LabelTooLong if t_remind is None: t_remind = t_set s = Schedule.new(content, p.id, user.id, remarks=remarks, t_set=t_set, t_remind=t_remind, label=label) Action.new(user_id=user.id, project_id=p.id, type_name=action_type.schedule_create.name, content=s.content, link=s.link) return code_list.Success