diff mod_firewall/conditions.lib.lua @ 5002:84997bc3f92e

mod_firewall: Update for role-auth (backwards compatible) Probably worth investigating mod_compat_roles in the future.
author Matthew Wild <mwild1@gmail.com>
date Thu, 11 Aug 2022 17:04:53 +0100
parents 4e8fa75cc678
children 8226ac08484e
line wrap: on
line diff
--- a/mod_firewall/conditions.lib.lua	Wed Jul 13 11:27:44 2022 +0100
+++ b/mod_firewall/conditions.lib.lua	Thu Aug 11 17:04:53 2022 +0100
@@ -175,22 +175,39 @@
 	return "not "..table.concat(code, " or "), { "group_contains", "bare_to", "bare_from" };
 end
 
+-- COMPAT w/0.12: Deprecated
 function condition_handlers.FROM_ADMIN_OF(host)
 	return ("is_admin(bare_from, %s)"):format(host ~= "*" and metaq(host) or nil), { "is_admin", "bare_from" };
 end
 
+-- COMPAT w/0.12: Deprecated
 function condition_handlers.TO_ADMIN_OF(host)
 	return ("is_admin(bare_to, %s)"):format(host ~= "*" and metaq(host) or nil), { "is_admin", "bare_to" };
 end
 
+-- COMPAT w/0.12: Deprecated
 function condition_handlers.FROM_ADMIN()
 	return ("is_admin(bare_from, current_host)"), { "is_admin", "bare_from", "current_host" };
 end
 
+-- COMPAT w/0.12: Deprecated
 function condition_handlers.TO_ADMIN()
 	return ("is_admin(bare_to, current_host)"), { "is_admin", "bare_to", "current_host" };
 end
 
+-- MAY: permission_to_check
+function condition_handlers.MAY(permission_to_check)
+	return ("module:may(%q, event)"):format(permission_to_check);
+end
+
+function condition_handlers.TO_ROLE(role_name)
+	return ("get_jid_role(bare_to, current_host) == %q"):format(role_name), { "get_jid_role", "current_host", "bare_to" };
+end
+
+function condition_handlers.FROM_ROLE(role_name)
+	return ("get_jid_role(bare_from, current_host) == %q"):format(role_name), { "get_jid_role", "current_host", "bare_from" };
+end
+
 local day_numbers = { sun = 0, mon = 2, tue = 3, wed = 4, thu = 5, fri = 6, sat = 7 };
 
 local function current_time_check(op, hour, minute)