def verify_user(code): user = User.query.filter_by(activation_code=code).first() if user is not None and not user.activated: user.activated = True sql_utils.commit_db() return True return False
def apply_user_settings(user, settings): settings = json.loads(settings) setts = json.loads(User.query.filter_by(username=user).first().settings) for key in settings: setts[key] = settings[key] User.query.filter_by(username=user).first().settings = json.dumps(setts) sql_utils.commit_db()
def switch_admin(user): """ Toggles admin mode for the given user. If the user is not an admin, they will be promoted, otherwise they are degraded to a normal user again. :param user: The user to toggle admin state of. """ val = User.query.filter_by(username=user).first() val.admin = not val.admin sql_utils.commit_db()
def delete_user(username): user = User.query.filter_by(username=username).first() sql_utils.delete_from_db(user) remove_reports_by_username(username, False) remove_reports_by_creator(username, False) kelp_module_repo.remove_user_content(username, False) kelp_plugin_repo.remove_user_content(username, False) sql_utils.commit_db() return True
def remove_reports_by_plugin_uuid(uuid, auto_commit=True): KelpPluginReport.query.filter_by(plugin_uuid=uuid).delete() if auto_commit: sql_utils.commit_db()
def set_plugin_tags(uuid, tags: str): KelpPlugin.query.filter_by(uuid=uuid).first().tags = tags sql_utils.commit_db()
def get_plugin_file(uuid, filename): KelpPlugin.query.filter_by(uuid=uuid).first().downloads += 1 sql_utils.commit_db() return os.path.join(configuration.path_kelp_plugins, uuid, filename)
def remove_reports_by_creator(creator, auto_commit=True): UserReport.query.filter_by(creator=creator) if auto_commit: sql_utils.commit_db()
def plugin_updated(uuid): KelpPlugin.query.filter_by(uuid=uuid).first().updated = time.time() sql_utils.commit_db()
def change_plugin_tags(uuid, tags: dict): KelpPlugin.query.filter_by(uuid=uuid).first().tags = tags sql_utils.commit_db() plugin_updated(uuid)
def change_module_picture(uuid, picture): module = KelpModule.query.filter_by(uuid=uuid).first() module.picture = picture.stream.read() sql_utils.commit_db()
def remove_user_content(username, auto_commit=True): for module in KelpModule.query.filter_by(creator=username).all(): remove_module(module.uuid) if auto_commit: sql_utils.commit_db()
def change_plugin_banner(uuid, picture): plugin = KelpPlugin.query.filter_by(uuid=uuid).first() plugin.banner = picture.stream.read() sql_utils.commit_db() plugin_updated(uuid)
def change_avatar(user, avatar): User.query.filter_by(username=user).first().avatar = avatar.stream.read() sql_utils.commit_db()
def switch_pinned(uuid): module = KelpModule.query.filter_by(uuid=uuid).first() module.pinned = not module.pinned sql_utils.commit_db()
def change_email(user, email): User.query.filter_by(username=user).first().email = email sql_utils.commit_db()
def change_description(user, description): User.query.filter_by(username=user).first().description = description sql_utils.commit_db()
def change_module_description(uuid, description): KelpModule.query.filter_by(uuid=uuid).first().description = description sql_utils.commit_db()
def remove_report_by_id(report_id, auto_commit=True): KelpPluginReport.query.filter_by(id=report_id).delete() if auto_commit: sql_utils.commit_db()
def get_module_file(uuid, filename): KelpModule.query.filter_by(uuid=uuid).first().downloads += 1 sql_utils.commit_db() return os.path.join(configuration.path_kelp_modules, uuid, filename)
def remove_user_content(username, auto_commit=True): for plugin in KelpPlugin.query.filter_by(creator=username).all(): remove_plugin(plugin.uuid) KelpPluginReport.query.filter_by(creator=username).delete() if auto_commit: sql_utils.commit_db()
def remove_reports_by_username(username, auto_commit=True): UserReport.query.filter_by(username=username).delete() if auto_commit: sql_utils.commit_db()
def change_plugin_name(uuid, plugin_name): KelpPlugin.query.filter_by(uuid=uuid).first().plugin_name = plugin_name sql_utils.commit_db() plugin_updated(uuid)
def change_module_name(uuid, module_name): KelpModule.query.filter_by(uuid=uuid).first().module_name = module_name sql_utils.commit_db()
def change_plugin_description(uuid, description): KelpPlugin.query.filter_by(uuid=uuid).first().description = description sql_utils.commit_db() plugin_updated(uuid)
def switch_admin(user): val = User.query.filter_by(username=user).first() val.admin = not val.admin sql_utils.commit_db()