From f3913b7258e6fafc236840308caf8e707b1bd6ed Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Sat, 5 Oct 2024 14:05:26 -0700 Subject: [PATCH 1/2] mass changes generated by ruff when updating moin/config/wikiconfig.py changed single quotes to douple quotes, wrapped long import statements, --- src/moin/config/wikiconfig.py | 144 ++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 68 deletions(-) diff --git a/src/moin/config/wikiconfig.py b/src/moin/config/wikiconfig.py index bb1d7c3e7..fa4a52835 100644 --- a/src/moin/config/wikiconfig.py +++ b/src/moin/config/wikiconfig.py @@ -34,8 +34,13 @@ from moin.config.default import DefaultConfig from moin.utils.interwiki import InterWikiMap from moin.storage import create_mapping -from moin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERPROFILES,NAMESPACE_USERS, \ - NAMESPACE_HELP_COMMON, NAMESPACE_HELP_EN, NAMESPACE_ALL +from moin.constants.namespaces import ( + NAMESPACE_DEFAULT, + NAMESPACE_USERPROFILES, + NAMESPACE_USERS, + NAMESPACE_HELP_COMMON, + NAMESPACE_HELP_EN, +) class Config(DefaultConfig): @@ -43,47 +48,47 @@ class Config(DefaultConfig): # These paths are usually correct. # See https://moin-20.readthedocs.io/en/latest/admin/configure.html#directory-structure wikiconfig_dir = os.path.abspath(os.path.dirname(__file__)) - instance_dir = os.path.join(wikiconfig_dir, 'wiki') - data_dir = os.path.join(instance_dir, 'data') - index_storage = 'FileStorage', (os.path.join(instance_dir, "index"), ), {} + instance_dir = os.path.join(wikiconfig_dir, "wiki") + data_dir = os.path.join(instance_dir, "data") + index_storage = "FileStorage", (os.path.join(instance_dir, "index"),), {} # setup moin to serve static files' or change to have your webserver serve static files serve_files = dict( - wiki_local=os.path.join(wikiconfig_dir, 'wiki_local'), # store custom logos, CSS, templates, etc. here + wiki_local=os.path.join(wikiconfig_dir, "wiki_local") # store custom logos, CSS, templates, etc. here ) - docs = os.path.join(wikiconfig_dir, 'docs', '_build', 'html') + docs = os.path.join(wikiconfig_dir, "docs", "_build", "html") if os.path.isdir(docs): - serve_files['docs'] = docs + serve_files["docs"] = docs else: # change target if a specific release or language is available - serve_files['external_docs'] = "https://moin-20.readthedocs.io/en/latest/" + serve_files["external_docs"] = "https://moin-20.readthedocs.io/en/latest/" # copy templates/snippets.html to directory below and edit per requirements to customize logos, etc. - template_dirs = [os.path.join(wikiconfig_dir, 'wiki_local'), ] + template_dirs = [os.path.join(wikiconfig_dir, "wiki_local")] # it is required that you set interwikiname to a unique, stable and non-empty name. # Changing interwikiname on an existing wiki requires rebuilding the index. # moin index-destroy; moin index-create; moin index-rebuild - interwikiname = 'MyMoinMoin' + interwikiname = "MyMoinMoin" # load the interwiki map from intermap.txt try: - interwiki_map = InterWikiMap.from_file(os.path.join(wikiconfig_dir, 'intermap.txt')).iwmap + interwiki_map = InterWikiMap.from_file(os.path.join(wikiconfig_dir, "intermap.txt")).iwmap except FileNotFoundError: interwiki_map = {} # we must add entries for 'Self' and our interwikiname, # if you are not running the built-in desktop server change these to your wiki URL - interwiki_map[interwikiname] = 'http://127.0.0.1:8080/' - interwiki_map['Self'] = 'http://127.0.0.1:8080/' + interwiki_map[interwikiname] = "http://127.0.0.1:8080/" + interwiki_map["Self"] = "http://127.0.0.1:8080/" # sitename is displayed in heading of all wiki pages - sitename = 'My MoinMoin' + sitename = "My MoinMoin" # see https://www.moinmo.in/ThemeMarket for contributed moin2 themes # default theme is topside # theme_default = "modernized" # or basic or topside_cms # prevent multiple users from editing an item at same time - edit_locking_policy = 'lock' + edit_locking_policy = "lock" edit_lock_time = 20 # minutes, resets when the Preview button is clicked # number of quicklinks to show in navigation bar, mouseover shows all @@ -121,7 +126,9 @@ class Config(DefaultConfig): # New user registration option; if set to True use the command line to create the first superuser: # moin account-create --name MyName --email MyName@x.x --password ******** registration_only_by_superuser = True # True disables self-registration, recommended for public wikis - registration_hint = 'To contribute to this wiki as an editor send an email with your preferred UserName to XXX@XXX.XXX.' + registration_hint = ( + "To contribute to this wiki as an editor send an email with your preferred UserName to XXX@XXX.XXX." + ) # if registration_only_by_superuser=False then making this True verifies a working email address # for users who self-register @@ -129,14 +136,14 @@ class Config(DefaultConfig): # Define the super user who will have access to administrative functions like user registration, # password reset, disabling users, etc. - acl_functions = 'YOUR-SUPER-USER-NAME:superuser' + acl_functions = "YOUR-SUPER-USER-NAME:superuser" # OR, if you have a large active wiki with many administrators and editors you may want to # create a ConfigGroup or a WikiGroup. Group names may be used in place of user names # above and in ACL rules defined below. Read about it here: # https://moin-20.readthedocs.io/en/latest/admin/configure.html#group-backend-configuration # File Storage backends are recommended for most wikis - uri = f'stores:fs:{data_dir}/%(backend)s/%(kind)s' # use file system for storage + uri = f"stores:fs:{data_dir}/%(backend)s/%(kind)s" # use file system for storage # uri = 'stores:sqlite:{0}/mywiki_%(backend)s_%(kind)s.db'.format(data_dir) # sqlite, 1 table per db # uri = 'stores:sqlite:{0}/mywiki_%(backend)s.db::%(kind)s'.format(data_dir) # sqlite, 2 tables per db # sqlite via SQLAlchemy @@ -146,12 +153,12 @@ class Config(DefaultConfig): namespaces = { # maps namespace name -> backend name # these 3 standard namespaces are required, these have separate backends - NAMESPACE_DEFAULT: 'default', - NAMESPACE_USERS: 'users', - NAMESPACE_USERPROFILES: 'userprofiles', + NAMESPACE_DEFAULT: "default", + NAMESPACE_USERS: "users", + NAMESPACE_USERPROFILES: "userprofiles", # namespaces for editor help files are optional, if unwanted delete here and in backends and acls - NAMESPACE_HELP_COMMON: 'help-common', # contains media files used by other language helps - NAMESPACE_HELP_EN: 'help-en', # replace this with help-de, help-ru, help-pt_BR etc. + NAMESPACE_HELP_COMMON: "help-common", # contains media files used by other language helps + NAMESPACE_HELP_EN: "help-en", # replace this with help-de, help-ru, help-pt_BR etc. # define custom namespaces using the default backend # 'foo': 'default', # custom namespace with a separate backend (a wiki/data/bar directory will be created) @@ -162,12 +169,12 @@ class Config(DefaultConfig): # the feature to use different storage types for each namespace is not implemented so use None below. # the storage type for all backends is set in 'uri' above, # all values in `namespace` dict must be defined as keys in `backends` dict - 'default': None, - 'users': None, - 'userprofiles': None, + "default": None, + "users": None, + "userprofiles": None, # help namespaces are optional - 'help-common': None, - 'help-en': None, + "help-common": None, + "help-en": None, # required for foo and bar namespaces as defined above # 'foo': None, # 'bar': None, @@ -182,40 +189,40 @@ class Config(DefaultConfig): # # most wiki data will be stored in NAMESPACE_DEFAULT NAMESPACE_DEFAULT: dict( - before='YOUR-SUPER-EDITOR:read,write,create,destroy,admin', - default='YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read', - after='', - hierarchic=False, ), + before="YOUR-SUPER-EDITOR:read,write,create,destroy,admin", + default="YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read", + after="", + hierarchic=False, + ), # user home pages should be stored here NAMESPACE_USERS: dict( - before='YOUR-SUPER-EDITOR:read,write,create,destroy,admin', - default='YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read', - after='', + before="YOUR-SUPER-EDITOR:read,write,create,destroy,admin", + default="YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read", + after="", # True enables possibility of an admin creating ACL rules for a user's subpages - hierarchic=True, ), + hierarchic=True, + ), # contains user data that must be kept secret, dis-allow access for all - NAMESPACE_USERPROFILES: dict( - before='All:', - default='', - after='', - hierarchic=False, ), + NAMESPACE_USERPROFILES: dict(before="All:", default="", after="", hierarchic=False), # editor help namespacess are optional - 'help-common': dict( - before='YOUR-SUPER-EDITOR:read,write,create,destroy,admin', - default='YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read', - after='', - hierarchic=False, ), - 'help-en': dict( - before='YOUR-SUPER-EDITOR:read,write,create,destroy,admin', - default='YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read', - after='', - hierarchic=False, ), + "help-common": dict( + before="YOUR-SUPER-EDITOR:read,write,create,destroy,admin", + default="YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read", + after="", + hierarchic=False, + ), + "help-en": dict( + before="YOUR-SUPER-EDITOR:read,write,create,destroy,admin", + default="YOUR-TRUSTED-EDITORS-GROUP:read,write,create All:read", + after="", + hierarchic=False, + ), } - namespace_mapping, backend_mapping, acl_mapping = create_mapping(uri, namespaces, backends, acls, ) + namespace_mapping, backend_mapping, acl_mapping = create_mapping(uri, namespaces, backends, acls) # define mapping of namespaces to unique item_roots (home pages within namespaces). - root_mapping = {'users': 'UserHome', } + root_mapping = {"users": "UserHome"} # default root, use this value by default for all namespaces - default_root = 'Home' + default_root = "Home" # Enable only selected content types for new items. Default: [] (all types enabled). # contenttype_enabled = ['MoinMoin', 'PDF', 'PNG', 'JPEG'] @@ -225,35 +232,36 @@ class Config(DefaultConfig): # add or remove packages - see https://github.com/xstatic-py/xstatic for info about xstatic # it is uncommon to change these because of local customizations from xstatic.main import XStatic + # names below must be package names mod_names = [ - 'jquery', - 'jquery_file_upload', - 'bootstrap', - 'font_awesome', - 'ckeditor', - 'autosize', - 'svgedit_moin', - 'jquery_tablesorter', - 'pygments', + "jquery", + "jquery_file_upload", + "bootstrap", + "font_awesome", + "ckeditor", + "autosize", + "svgedit_moin", + "jquery_tablesorter", + "pygments", ] - pkg = __import__('xstatic.pkg', fromlist=mod_names) + pkg = __import__("xstatic.pkg", fromlist=mod_names) for mod_name in mod_names: mod = getattr(pkg, mod_name) - xs = XStatic(mod, root_url='/static', provider='local', protocol='http') + xs = XStatic(mod, root_url="/static", provider="local", protocol="http") serve_files[xs.name] = xs.base_dir # flask settings require all caps MOINCFG = Config # adding MOINCFG= to OS environment overrides CWD # Flask settings - see the flask documentation about their meaning -SECRET_KEY = 'WARNING: set this to a unique string to create secure cookies' +SECRET_KEY = "WARNING: set this to a unique string to create secure cookies" DEBUG = False # use True for development only, not for public sites! TESTING = False # built-in server (./m run) ignores TESTING and DEBUG settings # per https://flask.palletsprojects.com/en/1.1.x/security/#set-cookie-options SESSION_COOKIE_SECURE = False # flask default is False SESSION_COOKIE_HTTPONLY = True # flask default is True -SESSION_COOKIE_SAMESITE = 'Lax' # flask default is None +SESSION_COOKIE_SAMESITE = "Lax" # flask default is None # SESSION_COOKIE_NAME = 'session' # PERMANENT_SESSION_LIFETIME = timedelta(days=31) # USE_X_SENDFILE = False From 238a197acaa45fba799caa02173a52341fd2bf80 Mon Sep 17 00:00:00 2001 From: RogerHaase Date: Sun, 6 Oct 2024 08:03:26 -0700 Subject: [PATCH 2/2] add "from datetime import timedelta" line to wikiconfig; fixes #1754 needed if wiki admin changes PERMANENT_SESSION_LIFETIME value in wikiconfig.py. >>>> manual copy of src/moin/config/wikiconfig.py over wikiconfig.py required afer applying this patch --- src/moin/config/wikiconfig.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/moin/config/wikiconfig.py b/src/moin/config/wikiconfig.py index fa4a52835..ac161d1a2 100644 --- a/src/moin/config/wikiconfig.py +++ b/src/moin/config/wikiconfig.py @@ -263,6 +263,7 @@ class Config(DefaultConfig): SESSION_COOKIE_HTTPONLY = True # flask default is True SESSION_COOKIE_SAMESITE = "Lax" # flask default is None # SESSION_COOKIE_NAME = 'session' +# from datetime import timedelta # next line requires this # PERMANENT_SESSION_LIFETIME = timedelta(days=31) # USE_X_SENDFILE = False # LOGGER_NAME = 'MoinMoin'