The V3 version of this module is now deprecated
Hey Developers!
I decided to re-write my GranularPermissions module which today, I’m shipping to production.
The purpose of this rewrite was to fix a few bugs and write up clearer documentation on the module which can be found here:
For any of you who haven’t used my GranularPermissions module before, it basically is an easier way to run permission checks collectively, rather than copy pasting code in a big long line that is ugly and inefficient.
A small rundown of how you can use this would be:
local GranularPermissions = require(path.to.GranularPermissions)
-- Create a new instance
local Permissions = GranularPermissions.new()
-- Register Callbacks
Permissions:RegisterCallback("CanEdit", function(self, Player)
return Player:GetAttribute("CanEdit") == true
end)
-- Complex callback
Permissions:RegisterCallback("IsGroupRank", function(self, Player, Arguments)
return Player:GetRankInGroup(tonumber(Arguments[2])) >= Arguments[3]
end)
Permissions:RegisterCallback("CanView", function(self, Player)
return Player:GetAttribute("CanView") == true
end)
Permissions:RegisterCallback("CanDelete", function(self, Player)
return Player:GetAttribute("CanDelete") == true
end)
Permissions:RegisterCallback("IsAdmin", function(self, Player)
return Player:GetAttribute("IsAdmin") == true
end)
-- Register Replacements
Permissions:RegisterReplacement("Admin", "IsAdmin")
Permissions:RegisterReplacement("Editor", "CanEdit")
-- Demo: Complex Check
print(Permissions:IsAuthorised(Player, {"IsGroupRank:5763193:15"})
-- Demo: Flat Permissions
print("Flat Permission Check (CanEdit):", Permissions:IsAuthorised(Player, {"CanEdit"})) -- Output: true
-- Demo: Nested Permissions
local NestedPermissions = {
"[RequireAll]", -- All permissions in this table must pass
{"CanEdit", "CanView"}, -- Nested: At least one of these must pass
"CanDelete", -- Single permission
}
print("Nested Permission Check:", Permissions:IsAuthorised(Player, NestedPermissions)) -- Output: false (fails on "CanDelete")
-- Demo: Using Replacements
print("Using Replacements (Admin):", Permissions:IsAuthorised(Player, {"Admin"})) -- Output: false (Player is not an admin)
-- Demo: Complex Example with Replacements and Nesting
local ComplexPermissions = {
"[RequireAll]", -- All conditions must pass
{"Editor", "CanView"}, -- Nested: Player must either be an "Editor" or "CanView"
{"[RequireAll]", "Admin", "CanDelete"}, -- Nested with [RequireAll]: Must be "Admin" and "CanDelete"
}
print("Complex Permission Check:", Permissions:IsAuthorised(Player, ComplexPermissions)) -- Output: false (fails on Admin/CanDelete)
You can register your own callbacks that don’t even have to be player specific, for example locking a feature to only be used if there are #10 players online…
You can install this with wally:
GranularPermissions = "dayflareroblox/granularpermissions@2.1.0"
It’s a really simple module, but is effective where it needs to be, ENJOY!