summary
------------------------------------------------------
-Module for one-step dynamic cnfvar configuration using minimal templates.
+Module for one-step dynamic cnfvar generation from default value templates.
.. codeauthor:: Intra2net
+contents
+-------------------------------------------------------
+These templates contain the bare defaults the UI adds upon
+creation of each major and frequently used cnfvar.
+
+
interface
------------------------------------------------------
###############################################################################
+# MAJOR CNF DEFAULTS
+###############################################################################
+
+
+#: UI defaults for a user instance
+user_defaults = {
+ "USER_DISABLED": "0",
+ "USER_FULLNAME": "",
+ "USER_GROUPWARE_FOLDER_CALENDAR": "INBOX/Calendar",
+ "USER_GROUPWARE_FOLDER_CONTACTS": "INBOX/Contacts",
+ "USER_GROUPWARE_FOLDER_DRAFTS": "INBOX/Drafts",
+ "USER_GROUPWARE_FOLDER_NOTES": "INBOX/Notes",
+ "USER_GROUPWARE_FOLDER_OUTBOX": "INBOX/Sent Items",
+ "USER_GROUPWARE_FOLDER_TASKS": "INBOX/Tasks",
+ "USER_GROUPWARE_FOLDER_TRASH": "INBOX/Deleted Items",
+ # always a member of the 'Alle' group
+ "USER_GROUP_MEMBER_REF": "2",
+ "USER_LOCALE": "",
+ "USER_PASSWORD": "test1234",
+ "USER_TRASH_DELETEDAYS": "30",
+ "USER_WEBMAIL_MESSAGES_PER_PAGE": "25",
+ "USER_WEBMAIL_SIGNATURE": "",
+}
+
+
+###############################################################################
# MINOR CONFIGURATION
###############################################################################
-def simple(varname, data, instance=0):
+def template(name, value, instance=-1, defaults=None, **kwargs):
"""
- Generate a minimal simple cnf variable in terms of required and validated attributes.
+ Generate a template cnf variable from provided defaults.
- :param str varname: cnf variable name
- :param str data: cnf variable value
+ :param str name: cnf variable name
+ :param str value: cnf variable data value
:param int instance: cnf variable instance number
+ :param defaults: default child variables to populate the cnf variable with
+ :type defaults: {str, str or {}} or None
:returns: generated cnf variable
:rtype: :py:class:`Cnf`
+
+ All additional keyword arguments will be used to overwrite the defaults.
"""
- log.info(f"Generating a simple {varname} cnfvar")
- return Cnf(varname, value=data, instance=instance)
+ log.info(f"Generating a template {name} cnfvar")
+ cnf = Cnf(name, value=value, instance=instance)
+ defaults = {} if defaults is None else defaults
+ cnf.add_children(*[(key, value) for key, value in defaults.items()])
+ for key in kwargs.keys():
+ cnf.children.single_with_name(f"{name}_{key}").value = kwargs[key]
+ return cnf
-def user(username, password, instance=-1):
+def user(name, password, instance=-1, **kwargs):
"""
- Generate a minimal user cnf variable in terms of required and validated attributes.
+ Generate a user cnf variable.
- :param str username: username for the user
+ :param str name: username for the user
:param str password: password for the user
:param int instance: instance number for the user
:returns: generated cnf variable
:rtype: :py:class:`Cnf`
"""
- log.info(f"Generating a minimal user {username} cnfvar")
- user_cnf = Cnf("user", value=username, instance=instance)
- user_cnf.add_children(
- ("user_fullname", username.capitalize()),
- ("user_group_member_ref", 2),
- ("user_password", password))
+ log.info(f"Generating a user {name} cnfvar")
+ user_cnf = template("user", name, instance=instance, defaults=user_defaults, **kwargs)
+ user_cnf.children.single_with_name("user_fullname").value = name.capitalize()
+ user_cnf.children.single_with_name("user_password").value = password
return user_cnf