Use group (minimal GUI) defaults similarly to the user template
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Sat, 9 Apr 2022 05:06:08 +0000 (08:06 +0300)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 19 May 2022 09:13:27 +0000 (11:13 +0200)
This provides a complete user-group combination for testing of
the template concept before migrating more templates code.

Note that the UI-defaults for group child cnfvars are not the same
as the ones provided in the build_group module which seem to be
too few and the minimal needed for the configuration to be accepted.

When creating an empty GROUP in the UI, these fields are populated:

    1 GROUP,104: "ganz neu"
    2    (1) GROUP_ACCESS_GO_ONLINE_ALLOWED,0: "1"
    3    (1) GROUP_COMMENT,0: ""
    4    (1) GROUP_EMAILFILTER_BAN_FILTERLIST_REF,0: "-1"
    5    (1) GROUP_EMAIL_RELAY_RIGHTS,0: "RELAY_FROM_INTRANET"
    6    (1) GROUP_PROXY_PROFILE_REF,0: "1"

So there is a tad more than just "GROUP_COMMENT" and following the
UI these additional fields should be added and similarly populated.

src/cnfvar/templates.py

index 7e2d9da..1a68960 100644 (file)
@@ -72,6 +72,15 @@ user_defaults = {
     "USER_WEBMAIL_MESSAGES_PER_PAGE": "25",
     "USER_WEBMAIL_SIGNATURE": "",
 }
+#: UI defaults for a group instance
+group_defaults = {
+    "GROUP_COMMENT": "",
+    "GROUP_ACCESS_GO_ONLINE_ALLOWED": "1",
+    "GROUP_EMAILFILTER_BAN_FILTERLIST_REF": "-1",
+    "GROUP_EMAIL_RELAY_RIGHTS": "RELAY_FROM_INTRANET",
+    "GROUP_PROXY_PROFILE_REF": "1",
+}
+
 
 
 ###############################################################################
@@ -119,66 +128,17 @@ def user(name, password, instance=-1, **kwargs):
     return user_cnf
 
 
-def group_admins(proxy_profile="1", activesync_enable=False, xauth_enable=False, suffix="host"):
-    """
-    Generate and save an Administrators group configuration file.
-
-    :param str proxy_profile: proxy profile instance reference
-    :param bool activesync_enable: whether to enable ActiveSync for the group
-    :param bool xauth_enable: whether to enable XAUTH for the group
-    :param str suffix: optional suffix to use for config identification
-    :returns: generated config filename
-    :rtype: str
-    """
-    log.info("Create arnied admin group configuration")
-    group = batch_update_cnf(build_group.BuildGroup(data="Administratoren",
-                                                    instance=1),
-                             [(Update, ("GROUP_ACCESS_REMOTE_ADMINISTRATION_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_EMAILFILTER_BAN_FILTERLIST_REF", 0, "-1")),
-                              (Update, ("GROUP_PROXY_PROFILE_REF", 0, proxy_profile)),
-                              (Update, ("GROUP_ACCESS_GO_ONLINE_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_EMAIL_RELAY_RIGHTS", 0, "RELAY_FROM_INTRANET")),
-                              (Update, ("GROUP_ACTIVESYNC_ENABLE", 0, "1" if activesync_enable else "0")),
-                              (Update, ("GROUP_XAUTH_ENABLE", 0, "1" if xauth_enable else "0")),
-                              (Delete, ("GROUP_COMMENT",))])
-    group_cnf = "group-%d-%s.cnf" % (time.time(), suffix)
-    [group_cnf] = aw.prep_config_paths([group_cnf], aw.DUMP_CONFIG_DIR)
-    logging.info("Saving group configuration to %s", group_cnf)
-    group.save(group_cnf)
-    return group_cnf
-
-
-def group_all(proxy_profile="1", suffix="host"):
+def group(name, instance=-1, **kwargs):
     """
-    Generate and save an "All" group configuration file.
+    Generate a group cnf variable.
 
-    :param str proxy_profile: proxy profile instance reference
-    :param str suffix: optional suffix to use for config identification
-    :returns: generated config filename
-    :rtype: str
+    :param str name: name for the group
+    :param int instance: instance number for the group
+    :returns: generated cnf variable
+    :rtype: :py:class:`Cnf`
     """
-    log.info("Create arnied all group configuration")
-    group = batch_update_cnf(build_group.BuildGroup(data="Alle",
-                                                    instance=2),
-                             [(Update, ("GROUP_ACCESS_GO_ONLINE_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_INFORMATION_VERSION_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_MAINPAGE_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_USERMANAGER_OWN_PROFILE_FORWARDING_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_USERMANAGER_OWN_PROFILE_GROUPWARE_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_USERMANAGER_OWN_PROFILE_SETTINGS_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_USERMANAGER_OWN_PROFILE_SORTING_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_USERMANAGER_OWN_PROFILE_SPAMFILTER_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_USERMANAGER_OWN_PROFILE_VACATION_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_ACCESS_GROUPWARE_ALLOWED", 0, "1")),
-                              (Update, ("GROUP_EMAILFILTER_BAN_FILTERLIST_REF", 0, "-1")),
-                              (Update, ("GROUP_EMAIL_RELAY_RIGHTS", 0, "RELAY_FROM_EVERYWHERE")),
-                              (Update, ("GROUP_PROXY_PROFILE_REF", 0, proxy_profile)),
-                              (Delete, ("GROUP_COMMENT",))])
-
-    group_cnf = "group-%d-%s.cnf" % (time.time(), suffix)
-    [group_cnf] = aw.prep_config_paths([group_cnf], aw.DUMP_CONFIG_DIR)
-    logging.info("Saving group configuration to %s", group_cnf)
-    group.save(group_cnf)
+    log.info(f"Generating a group {name} cnfvar")
+    group_cnf = template("group", name, instance=instance, defaults=group_defaults, **kwargs)
     return group_cnf