# HG changeset patch # User Matthew Wild # Date 1665158495 -3600 # Node ID 7b9de8109a909a4eb5494cfdcdfdaf4b8f013cfa # Parent 9d6d64fb7641f184969a03a962236e7b6f870a8c util.roles: Add a :policies() method to iterate through available policies We don't expose the policies directly, to force people to go through :may(). However, there are times when we really just need to know what policies a role has inside it (e.g. for reporting or debugging purposes). diff -r 9d6d64fb7641 -r 7b9de8109a90 util/roles.lua --- a/util/roles.lua Fri Oct 07 16:58:52 2022 +0100 +++ b/util/roles.lua Fri Oct 07 17:01:35 2022 +0100 @@ -86,6 +86,16 @@ return true; end +function role_methods:policies() + local policy_iterator, s, v = it.join(pairs(self[permissions_key])); + if self.inherits then + for _, inherited_role in ipairs(self.inherits) do + policy_iterator:append(inherited_role:policies()); + end + end + return policy_iterator, s, v; +end + function role_mt.__tostring(self) return ("role<[%s] %s>"):format(self.id or "nil", self.name or "[no name]"); end