def grant_mod(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) editable = False if current_user: if current_user.admin: editable = True if current_user.id == mod.user_id: editable = True if not editable: abort(401) new_user = request.form.get('user') new_user = User.query.filter(User.username.ilike(new_user)).first() if new_user == None: return { 'error': True, 'message': 'The specified user does not exist.' }, 400 if mod.user == new_user: return { 'error': True, 'message': 'This user has already been added.' }, 400 if any(m.user == new_user for m in mod.shared_authors): return { 'error': True, 'message': 'This user has already been added.' }, 400 if not new_user.public: return { 'error': True, 'message': 'This user has not made their profile public.' }, 400 author = SharedAuthor() author.mod = mod author.user = new_user mod.shared_authors.append(author) db.add(author) db.commit() send_grant_notice(mod, new_user) return { 'error': False }, 200
def grant_mod(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: return {"error": True, "reason": "Mod not found."}, 404 editable = False if current_user: if current_user.admin: editable = True if current_user.id == mod.user_id: editable = True if not editable: return {"error": True, "reason": "Not enought rights."}, 401 new_user = request.form.get("user") new_user = User.query.filter(User.username.ilike(new_user)).first() if new_user == None: return {"error": True, "reason": "The specified user does not exist."}, 400 if mod.user == new_user: return {"error": True, "reason": "This user has already been added."}, 400 if any(m.user == new_user for m in mod.shared_authors): return {"error": True, "reason": "This user has already been added."}, 400 if not new_user.public: return {"error": True, "reason": "This user has not made their profile public."}, 400 author = SharedAuthor() author.mod = mod author.user = new_user mod.shared_authors.append(author) db.add(author) db.commit() send_grant_notice(mod, new_user) return {"error": False}, 200