aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-26 13:13:31 +0200
committerKim Alvefur <zash@zash.se>2023-03-26 13:13:31 +0200
commit5427c2472d1b6ddd57b01eaafe90a0bc4f09ffaa (patch)
treea7d13b826a377c14d4a0f0dc63b852be2b0dd1e4
parent196117c3f23809393315df505dcd1d5c8b33b6dd (diff)
downloadprosody-5427c2472d1b6ddd57b01eaafe90a0bc4f09ffaa.tar.gz
prosody-5427c2472d1b6ddd57b01eaafe90a0bc4f09ffaa.zip
util.roles: Implement a serialization preparation metamethod
Should be able to roundtrip trough serialization. Also nice for debug and logging purposes where you might want more details than what the __tostring method provides.
-rw-r--r--util/roles.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/util/roles.lua b/util/roles.lua
index 24444c3d..e7f22c12 100644
--- a/util/roles.lua
+++ b/util/roles.lua
@@ -73,6 +73,19 @@ local function new(base_config, overrides)
return setmetatable(new_role, role_mt);
end
+function role_mt:__freeze()
+ local t = {
+ id = self.id;
+ name = self.name;
+ description = self.description;
+ default = self.default;
+ priority = self.priority;
+ inherits = self.inherits;
+ permissions = self[permissions_key];
+ };
+ return t;
+end
+
function role_methods:clone(overrides)
return new(self, overrides);
end