def remove_project(project_id): session_id = auth.check_token(request.headers.get('session')) if not session_id: return "Unauthorized request: Bad session token", 401 user_sess = User.find_id(session_id) if not user_sess: return "Session token not found", 404 project = Project.find_id(project_id) if not project: return "Project not found", 404 if not (user_sess in project.team or user_sess.type == "organizer"): return "Unauthorized request: You don't have permission for this action", 401 project.delete() return 'Project deleted'
def remove_teammate(project_id): project = Project.find_id(project_id) if not project: return "Project not found", 404 teammate_email = request.json.get('teammate') # A team is required if not teammate_email: return "Teammate email is required", 400 teammate = User.objects(email=teammate_email).first() if not teammate: teammate = user.find_id(teammate_email) if not teammate or not teammate in project.team: return "Teammate not found", 404 project.team.remove(teammate) project.save() return project.to_json()
def update_project(project_id): session_id = auth.check_token(request.headers.get('session')) if not session_id: return "Unauthorized request: Bad session token", 401 user_sess = User.find_id(session_id) if not user_sess: return "Session token not found", 404 project = Project.find_id(project_id) if not project: return "Project not found", 404 for key, value in request.get_json().items(): if not key.startswith('_'): # Some security setattr(project, key, value) project.save() return project.to_json()
def add_teammate(project_id): project = Project.find_id(project_id) if not project: return "Project not found", 404 teammate_email = request.json.get('teammate') # A team is required if not teammate_email: return "Teammate email is required", 400 teammate = User.objects(email=teammate_email).first() if not teammate: return "Teammate not found", 404 if not project.event in teammate.events: return "Teammate not registered for event", 400 if len(project.team) >= 5: return "Your team is full. Max team size is 5 people.", 400 project.team.append(teammate) project.save() return project.select_related(max_depth=1).to_json()
def find_project(project_id): project = Project.find_id(project_id) if not project: return "Project not found", 404 return project.to_json()