def mutate(root, info, node_id, **kwargs): question_set = QuestionSetNode.get_model_from_global_id(node_id) if not question_set: raise GraphQLError("Question set not exist") if question_set.owner_profile != get_logged_in_user().user_profile: raise GraphQLError("Permission Denied") if "name" in kwargs: name = kwargs["name"] if len(name) < 5: raise GraphQLError("Invalid name") question_set.name = name if "details" in kwargs: details = kwargs["details"] if len(details) < 20: raise GraphQLError("Invalid description") question_set.details = details try: db.session.commit() except exc.SQLAlchemyError: raise GraphQLError("Failed to update question set info") return UpdateQuestionSetInfo(question_set=question_set)
def mutate(root, info, name, details): if len(name) < 5 or len(details) < 20: raise GraphQLError("Name or description invalid") user = get_logged_in_user() question_set = create_question_set(name, details, user.user_profile) if not question_set: raise GraphQLError("Failed to create empty set") return CreateQuestionSetEmpty(question_set=question_set)
def mutate(root, info, password): user = get_logged_in_user() if not validate_password(password): raise GraphQLError("Invalid password") user.set_password(password) try: db.session.commit() except exc.SQLAlchemyError: raise GraphQLError("Failed to change password") return ChangePassword(user_profile=user.user_profile)
def mutate(root, info, node_id): question_set = QuestionSetNode.get_model_from_global_id(node_id) if not question_set: raise GraphQLError("Question set not exist") if question_set.owner_profile != get_logged_in_user().user_profile: raise GraphQLError("Permission Denied") if question_set.close_date: raise GraphQLError("Question set already closed") question_set.close_date = datetime.now() try: db.session.commit() except exc.SQLAlchemyError: raise GraphQLError("Failed to close question set") return CloseQuestionSet(question_set=question_set)
def resolve_me(parent, info: ResolveInfo) -> UserProfileNode: user = get_logged_in_user() if not user: raise GraphQLError("User not authorized") return user.user_profile
def mutate(root, info): user_account = get_logged_in_user() token = generate_user_token(user_account) return RefreshSignIn(token=token)
def is_accessible(self) -> bool: current_user = get_logged_in_user() if current_user is None: return False return current_user.user_profile.role == UserRole.ADMIN.value