view mod_groups_migration/mod_groups_migration.lua @ 4651:8231774f5bfd

mod_cloud_notify_encrypted: Ensure body substring remains valid UTF-8 The `body:sub()` call risks splitting the string in the middle of a multi-byte UTF-8 sequence. This should have been caught by util.stanza validation, but that would have caused some havoc, at the very least causing the notification to not be sent. There have been no reports of this happening. Likely because this module isn't widely deployed among users with languages that use many longer UTF-8 sequences. The util.encodings.utf8.valid() function is O(n) where only the last sequence really needs to be checked, but it's in C and expected to be fast.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Aug 2021 13:22:59 +0200
parents dd3bfe8f182e
children
line wrap: on
line source

local host = module.host;
local usermanager = require"core.usermanager";

local mod_groups = module:depends("groups_internal");
local default_group_id = module:get_option("group_default_id", "default");
local default_group_name = module:get_option("group_default_name", "default");

local function trigger_migration()
	if mod_groups.exists(default_group_id) then
		module:log("debug", "skipping migration, group exists already")
		return
	end
	module:log("info", "migrating to mod_groups!")

	local group_id = default_group_id;
	local ok, err = mod_groups.create({name=default_group_name}, true, group_id);
	if not ok then
		module:log("error", "failed to create group: %s", err)
		return
	end

	for user in usermanager.users(host) do
		mod_groups.add_member(group_id, user, true);
		module:log("debug", "added %s to %s", user, group_id)
	end
	module:log("debug", "synchronising group %s", group_id)
	mod_groups.sync(group_id)
	module:log("info", "added all users to group %s", group_id)
end

module:hook_global("server-started", trigger_migration, -100)