def delete_version(mod_id, version_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 any([u.accepted and u.user == current_user for u in mod.shared_authors]): editable = True if not editable: abort(401) version = [v for v in mod.versions if v.id == int(version_id)] if len(mod.versions) == 1: abort(400) if len(version) == 0: abort(404) if version[0].id == mod.default_version_id: abort(400) db.delete(version[0]) mod.versions = [v for v in mod.versions if v.id != int(version_id)] db.commit() return redirect(url_for("mods.mod", id=mod.id, mod_name=mod.name))
def unfeature(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) game = Game.query.filter(Game.id == mod.game_id).first() session['game'] = game.id session['gamename'] = game.name session['gameshort'] = game.short session['gameid'] = game.id if not mod or not game: ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by( desc(Game.id)).first() session['game'] = ga.id session['gamename'] = ga.name session['gameshort'] = ga.short session['gameid'] = ga.id abort(404) else: session['game'] = game.id session['gamename'] = game.name session['gameshort'] = game.short session['gameid'] = game.id feature = Featured.query.filter(Featured.mod_id == mod_id).first() if not feature: abort(404) db.delete(feature) return {"success": True}
def delete_blog(id): post = BlogPost.query.filter(BlogPost.id == id).first() if not post: abort(404) db.delete(post) db.commit() return redirect("/")
def unfeature(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) game = Game.query.filter(Game.id == mod.game_id).first() session['game'] = game.id; session['gamename'] = game.name; session['gameshort'] = game.short; session['gameid'] = game.id; if not mod or not game: ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by(desc(Game.id)).first() session['game'] = ga.id; session['gamename'] = ga.name; session['gameshort'] = ga.short; session['gameid'] = ga.id; abort(404) else: session['game'] = game.id; session['gamename'] = game.name; session['gameshort'] = game.short; session['gameid'] = game.id; feature = Featured.query.filter(Featured.mod_id == mod_id).first() if not feature: abort(404) db.delete(feature) return { "success": True }
def unfeature(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) feature = Featured.query.filter(Featured.mod_id == mod_id).first() if not feature: abort(404) db.delete(feature) return { "success": True }
def disconnect_oauth(): provider = request.form.get('provider') assert provider in list_defined_oauths() # This is a quick and dirty form of sanitation. auths = UserAuth.query.filter(UserAuth.provider == provider, UserAuth.user_id == current_user.id).all() for auth in auths: db.delete(auth) db.flush() # So that /profile will display currectly return redirect('/profile/%s/edit' % current_user.username)
def disconnect_oauth(): provider = request.form.get('provider') assert provider in list_defined_oauths( ) # This is a quick and dirty form of sanitation. auths = UserAuth.query.filter(UserAuth.provider == provider, UserAuth.user_id == current_user.id).all() for auth in auths: db.delete(auth) db.flush() # So that /profile will display currectly return redirect('/profile/%s/edit' % current_user.username)
def delete(mod_id): user = get_user() mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) editable = False if user: if user.admin: editable = True if user.id == mod.user_id: editable = True if not editable: abort(401) db.delete(mod) for feature in Featured.query.filter(Featured.mod_id == mod.id).all(): db.delete(feature) for media in Media.query.filter(Media.mod_id == mod.id).all(): db.delete(media) for version in ModVersion.query.filter(ModVersion.mod_id == mod.id).all(): db.delete(version) db.commit() base_path = os.path.join(secure_filename(mod.user.username) + '_' + str(mod.user.id), secure_filename(mod.name)) full_path = os.path.join(_cfg('storage'), base_path) rmtree(full_path) return redirect("/profile/" + user.username)
def delete(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) db.delete(mod) for feature in Featured.query.filter(Featured.mod_id == mod.id).all(): db.delete(feature) for media in Media.query.filter(Media.mod_id == mod.id).all(): db.delete(media) for version in ModVersion.query.filter(ModVersion.mod_id == mod.id).all(): db.delete(version) base_path = os.path.join( secure_filename(mod.user.username) + '_' + str(mod.user.id), secure_filename(mod.name)) full_path = os.path.join(_cfg('storage'), base_path) db.commit() rmtree(full_path) return redirect("/profile/" + current_user.username)
def delete(list_id): mod_list = ModList.query.filter(ModList.id == list_id).first() if not mod_list: abort(404) editable = False if current_user: if current_user.admin: editable = True if current_user.id == mod_list.user_id: editable = True if not editable: abort(401) db.delete(mod_list) db.commit() return redirect("/profile/" + current_user.username)
def edit_media(mod_id, mod_name): user = get_user() mod = Mod.query.filter(Mod.id == mod_id).first() editable = False if user: if user.admin: editable = True if user.id == mod.user_id: editable = True if not editable: abort(401) screenshots = request.form.get('screenshots') videos = request.form.get('videos') background = request.form.get('backgroundMedia') bgOffsetX = request.form.get('bg-offset-x') bgOffsetY = request.form.get('bg-offset-y') screenshot_list = screenshots.split(',') video_list = videos.split(',') if len(screenshot_list) > 5 \ or len(video_list) > 2 \ or len(background) > 32: abort(400) [db.delete(m) for m in mod.media] for screenshot in screenshot_list: if screenshot: r = requests.get('https://mediacru.sh/' + screenshot + '.json') if r.status_code != 200: abort(400) j = r.json() data = '' if j['blob_type'] == 'image': for f in j['files']: if f['type'] == 'image/jpeg' or f['type'] == 'image/png': data = f['file'] else: abort(400) m = Media(j['hash'], j['blob_type'], data) mod.medias.append(m) for video in video_list: if video: r = requests.get('https://mediacru.sh/' + video + '.json') if r.status_code != 200: abort(400) j = r.json() data = '' if j['blob_type'] == 'video': data = j['hash'] else: abort(400) m = Media(j['hash'], j['blob_type'], data) mod.medias.append(m) db.add(m) mod.background = background try: mod.bgOffsetX = int(bgOffsetX) mod.bgOffsetY = int(bgOffsetY) except: pass # Do not modify background in this case return redirect('/mod/' + str(mod.id) + '/' + secure_filename(mod.name)[:64])
def delete_version(mod_id, version_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) game = Game.query.filter(Game.id == mod.game_id).first() session['game'] = game.id session['gamename'] = game.name session['gameshort'] = game.short session['gameid'] = game.id if not mod or not game: ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by( desc(Game.id)).first() session['game'] = ga.id session['gamename'] = ga.name session['gameshort'] = ga.short session['gameid'] = ga.id abort(404) else: session['game'] = game.id session['gamename'] = game.name session['gameshort'] = game.short session['gameid'] = game.id editable = False if current_user: if current_user.admin: editable = True if current_user.id == mod.user_id: editable = True if any([ u.accepted and u.user == current_user for u in mod.shared_authors ]): editable = True if not editable: abort(401) version = [v for v in mod.versions if v.id == int(version_id)] if len(mod.versions) == 1: abort(400) if len(version) == 0: abort(404) if version[0].id == mod.default_version_id: abort(400) db.delete(version[0]) mod.versions = [v for v in mod.versions if v.id != int(version_id)] db.commit() return redirect(url_for("mods.mod", id=mod.id, mod_name=mod.name, ga=game))
def delete_version(mod_id, version_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) game = Game.query.filter(Game.id == mod.game_id).first() session['game'] = game.id; session['gamename'] = game.name; session['gameshort'] = game.short; session['gameid'] = game.id; if not mod or not game: ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by(desc(Game.id)).first() session['game'] = ga.id; session['gamename'] = ga.name; session['gameshort'] = ga.short; session['gameid'] = ga.id; abort(404) else: session['game'] = game.id; session['gamename'] = game.name; session['gameshort'] = game.short; session['gameid'] = game.id; editable = False if current_user: if current_user.admin: editable = True if current_user.id == mod.user_id: editable = True if any([u.accepted and u.user == current_user for u in mod.shared_authors]): editable = True if not editable: abort(401) version = [v for v in mod.versions if v.id == int(version_id)] if len(mod.versions) == 1: abort(400) if len(version) == 0: abort(404) if version[0].id == mod.default_version_id: abort(400) db.delete(version[0]) mod.versions = [v for v in mod.versions if v.id != int(version_id)] db.commit() return redirect(url_for("mods.mod", id=mod.id, mod_name=mod.name,ga=game))
def edit_media(mod_id, mod_name): user = get_user() mod = Mod.query.filter(Mod.id == mod_id).first() editable = False if user: if user.admin: editable = True if user.id == mod.user_id: editable = True if not editable: abort(401) screenshots = request.form.get('screenshots') videos = request.form.get('videos') background = request.form.get('backgroundMedia') screenshot_list = screenshots.split(',') video_list = videos.split(',') if len(screenshot_list) > 5 \ or len(video_list) > 2 \ or len(background) > 32: abort(400) [db.delete(m) for m in mod.media] for screenshot in screenshot_list: if screenshot: r = requests.get('https://mediacru.sh/' + screenshot + '.json') if r.status_code != 200: abort(400) j = r.json() data = '' if j['blob_type'] == 'image': for f in j['files']: if f['type'] == 'image/jpeg' or f['type'] == 'image/png': data = f['file'] else: abort(400) m = Media(j['hash'], j['blob_type'], data) mod.medias.append(m) for video in video_list: if video: r = requests.get('https://mediacru.sh/' + video + '.json') if r.status_code != 200: abort(400) j = r.json() data = '' if j['blob_type'] == 'video': data = j['hash'] else: abort(400) m = Media(j['hash'], j['blob_type'], data) mod.medias.append(m) db.add(m) mod.background = background db.commit() return redirect('/mod/' + str(mod.id) + '/' + secure_filename(mod.name)[:64])
def delete(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) game = Game.query.filter(Game.id == mod.game_id).first() session['game'] = game.id session['gamename'] = game.name session['gameshort'] = game.short session['gameid'] = game.id if not mod or not game: ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by( desc(Game.id)).first() session['game'] = ga.id session['gamename'] = ga.name session['gameshort'] = ga.short session['gameid'] = ga.id abort(404) else: session['game'] = game.id session['gamename'] = game.name session['gameshort'] = game.short session['gameid'] = game.id 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) db.delete(mod) for feature in Featured.query.filter(Featured.mod_id == mod.id).all(): db.delete(feature) for media in Media.query.filter(Media.mod_id == mod.id).all(): db.delete(media) for version in ModVersion.query.filter(ModVersion.mod_id == mod.id).all(): db.delete(version) base_path = os.path.join( secure_filename(mod.user.username) + '_' + str(mod.user.id), secure_filename(mod.name)) full_path = os.path.join(_cfg('storage'), base_path) db.commit() notify_ckan.delay(mod_id, 'delete') rmtree(full_path) return redirect("/profile/" + current_user.username)
def delete(mod_id): mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) game = Game.query.filter(Game.id == mod.game_id).first() session['game'] = game.id; session['gamename'] = game.name; session['gameshort'] = game.short; session['gameid'] = game.id; if not mod or not game: ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by(desc(Game.id)).first() session['game'] = ga.id; session['gamename'] = ga.name; session['gameshort'] = ga.short; session['gameid'] = ga.id; abort(404) else: session['game'] = game.id; session['gamename'] = game.name; session['gameshort'] = game.short; session['gameid'] = game.id; 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) db.delete(mod) for feature in Featured.query.filter(Featured.mod_id == mod.id).all(): db.delete(feature) for media in Media.query.filter(Media.mod_id == mod.id).all(): db.delete(media) for version in ModVersion.query.filter(ModVersion.mod_id == mod.id).all(): db.delete(version) base_path = os.path.join(secure_filename(mod.user.username) + '_' + str(mod.user.id), secure_filename(mod.name)) full_path = os.path.join(_cfg('storage'), base_path) db.commit() notify_ckan.delay(mod_id, 'delete') rmtree(full_path) return redirect("/profile/" + current_user.username)
def delete(mod_id): user = get_user() mod = Mod.query.filter(Mod.id == mod_id).first() if not mod: abort(404) if not admin or not user.id == mod.user.id: abort(401) db.delete(mod) for feature in Featured.query.filter(Featured.mod_id == mod.id).all(): db.delete(feature) for media in Media.query.filter(Media.mod_id == mod.id).all(): db.delete(media) for version in ModVersion.query.filter(ModVersion.mod_id == mod.id).all(): db.delete(version) base_path = os.path.join( secure_filename(user.username) + '_' + str(user.id), secure_filename(mod.name)) full_path = os.path.join(_cfg('storage'), base_path) rmtree(full_path) db.commit() return redirect("/profile")
import sys from KerbalStuff.config import _cfg, _cfgi from KerbalStuff.database import db, init_db from KerbalStuff.objects import User from KerbalStuff.email import send_confirmation init_db() if sys.argv[1] == 'delete_user': user = User.query.filter(User.username == sys.argv[2]).first() if not user: sys.exit("User not found.") else: db.delete(user) db.commit() print("Success.") sys.exit()