From 1b9cc35cbea2e2ae7d5ed0b412c0a6e67cb54ed1 Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 27 Mar 2022 18:02:51 +0200 Subject: [PATCH] 2 custome theme bugfixes --- verse/distribusiselector.py | 5 +++++ verse/editor.py | 22 ++++++++++++++++++++-- verse/statuspengguna/resetpassword.py | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/verse/distribusiselector.py b/verse/distribusiselector.py index c7749f7..19b7032 100644 --- a/verse/distribusiselector.py +++ b/verse/distribusiselector.py @@ -94,6 +94,11 @@ def DeleteDistribusi(distribusiname): "themes/userthemes", distribusi.distribusiname ) shutil.rmtree(cssfolder) + if distribusi.publictheme is not None: + publicthemefolder = os.path.join( + "themes/publicthemes", distribusi.distribusiname + ) + shutil.rmtree(publicthemefolder) # SelectField error is list is a tuple?? why?? # selectorform.distribusis.errors.append("Distribusi deleted!") except (InvalidRequestError, DataError, InterfaceError, DatabaseError): diff --git a/verse/editor.py b/verse/editor.py index 902f695..1029498 100644 --- a/verse/editor.py +++ b/verse/editor.py @@ -1,5 +1,6 @@ import os import bleach +from bleach_allowlist import all_styles import shutil from flask import render_template @@ -52,8 +53,11 @@ def ValidateEditCssForm(editorform, current_distribusi): MakePublicTheme(editorform, current_distribusi) if editorform.cssfile.data: SaveUploadCssFile(editorform, publicfolder) + CopyPublicToUserFolder(editorform, publicfolder, newcssfolder) + return else: WriteCssToFile(editorform, publicfolder) + if editorform.cssfile.data: SaveUploadCssFile(editorform, newcssfolder) return @@ -68,7 +72,8 @@ def SaveUploadCssFile(editorform, newcssfolder): cssfilename = f"{secure_filename(editorform.cssname.data)}.css" cssfile.save(os.path.join(newcssfolder, cssfilename)) openfile = open(os.path.join(newcssfolder, cssfilename), "r") - cleancss = bleach.clean(openfile.read()) + cleancss = bleach.clean(openfile.read(), all_styles) + cleancss = cleancss.replace('>', '>') openfile.close() cleanfile = open(os.path.join(newcssfolder, cssfilename), "w") cleanfile.write(cleancss) @@ -80,12 +85,25 @@ def WriteCssToFile(editorform, newcssfolder): os.mkdir(newcssfolder) cssfilename = f"{secure_filename(editorform.cssname.data)}.css" - cleancss = bleach.clean(editorform.css.data) + cleancss = bleach.clean(editorform.css.data, all_styles) + cleancss = cleancss.replace('>', '>') with open(os.path.join(newcssfolder, cssfilename), "w") as cssfile: cssfile.write(cleancss) cssfile.close +def CopyPublicToUserFolder(editorform, publicfolder, newcssfolder): + if not os.path.exists(newcssfolder): + os.mkdir(newcssfolder) + copycssfile = os.path.join( + publicfolder, + f"{secure_filename(editorform.cssname.data)}.css" + ) + print(f"copying file: {copycssfile}") + print(f"to folder: {newcssfolder}") + shutil.copy(copycssfile, newcssfolder) + + def MakePublicTheme(editorform, current_distribusi): try: distribusi = Distribusis.query.filter_by( diff --git a/verse/statuspengguna/resetpassword.py b/verse/statuspengguna/resetpassword.py index b802dab..dc2a977 100644 --- a/verse/statuspengguna/resetpassword.py +++ b/verse/statuspengguna/resetpassword.py @@ -20,7 +20,7 @@ from flask_bcrypt import generate_password_hash from app import db -def ResetPassword(path): +def ResetPassword(path): linkvalid = False user = User.query.filter_by(resethash=path).first() if user is None: