diff options
author | Ted Trask <ttrask01@yahoo.com> | 2009-12-28 16:46:05 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2009-12-28 16:46:05 +0000 |
commit | 2799724a1683023f9eaa618127af9d07c0c46f23 (patch) | |
tree | d42ddb099d5178fc09fd18c361964a30dce43d2f /lib | |
parent | a506f1cf5243a5458af1ec4c13946fc88a7dbb84 (diff) | |
download | acf-core-2799724a1683023f9eaa618127af9d07c0c46f23.tar.bz2 acf-core-2799724a1683023f9eaa618127af9d07c0c46f23.tar.xz |
Added ability to manage roles based on which roles file they're in = more granularity of roles.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/roles.lua | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/lib/roles.lua b/lib/roles.lua index 2bceb01..0366a30 100644 --- a/lib/roles.lua +++ b/lib/roles.lua @@ -89,14 +89,29 @@ list_default_roles = function(self) for x,file in ipairs(rolesfiles) do f = fs.read_file_as_array(file) or {} + local rolefile = string.match(file, "(/[^/]+/[^/]+)%.roles$") for y,line in pairs(f) do - if not reverseroles[string.match(line,"^[%w_]+")] then - default_roles[#default_roles+1] = string.match(line,"^[%w_]+") - reverseroles[default_roles[#default_roles]] = #default_roles + local role = string.match(line,"^[%w_]+") + if role then + if not reverseroles[rolefile.."/"..role] then + default_roles[#default_roles+1] = rolefile.."/"..role + reverseroles[default_roles[#default_roles]] = #default_roles + end + if not reverseroles[role] then + default_roles[#default_roles+1] = role + reverseroles[default_roles[#default_roles]] = #default_roles + end end end end + table.sort(default_roles, function(a,b) + if string.byte(a, 1) == 47 and string.byte(b,1) ~= 47 then return false + elseif string.byte(a, 1) ~= 47 and string.byte(b,1) == 47 then return true + else return a<b + end + end) + return default_roles, reverseroles end @@ -111,16 +126,18 @@ list_roles = function(self) defined_roles[#defined_roles + 1] = entry.id end end + table.sort(defined_roles) return defined_roles, default_roles end list_all_roles = function(self) local defined_roles, default_roles = list_roles(self) - for x,role in ipairs(defined_roles) do - default_roles[#default_roles + 1] = role + -- put the defined roles first + for x,role in ipairs(default_roles) do + defined_roles[#defined_roles + 1] = role end - return default_roles + return defined_roles end -- Go through the roles files and determine the permissions for the specified list of roles @@ -140,23 +157,27 @@ local determine_perms = function(self,roles) for x,file in ipairs(rolesfiles) do local prefix = string.match(file, "(/[^/]+/)[^/]+$") or "/" f = fs.read_file_as_array(file) or {} + local rolefile = string.match(file, "(/[^/]+/[^/]+)%.roles$") for y,line in pairs(f) do - if reverseroles[string.match(line,"^[%w_]+")] then - temp = format.string_to_table(string.match(line,"[,%w_:/]+$"),",") - for z,perm in pairs(temp) do - -- we'll allow for : or / to not break old format - local control,action = string.match(perm,"([%w_]+)[:/]([%w_]+)") - if control then - if nil == permissions[prefix] then - permissions[prefix] = {} - end - if nil == permissions[prefix][control] then - permissions[prefix][control] = {} - end - if action then - permissions[prefix][control][action] = {file} - permissions_array[#permissions_array + 1] = prefix .. control .. "/" .. action - default_permissions_array[#default_permissions_array + 1] = prefix .. control .. "/" .. action + local role = string.match(line,"^[%w_]+") + if role then + if reverseroles[role] or reverseroles[rolefile.."/"..role] then + temp = format.string_to_table(string.match(line,"[,%w_:/]+$"),",") + for z,perm in pairs(temp) do + -- we'll allow for : or / to not break old format + local control,action = string.match(perm,"([%w_]+)[:/]([%w_]+)") + if control then + if nil == permissions[prefix] then + permissions[prefix] = {} + end + if nil == permissions[prefix][control] then + permissions[prefix][control] = {} + end + if action then + permissions[prefix][control][action] = {file} + permissions_array[#permissions_array + 1] = prefix .. control .. "/" .. action + default_permissions_array[#default_permissions_array + 1] = prefix .. control .. "/" .. action + end end end end @@ -213,8 +234,8 @@ set_role_perm = function(self, role, permissions, permissions_array) if role==nil or role=="" then return false, "Invalid Role" end - if string.find(role, '[^%w_]') then - return false, "Role can only contain letters, numbers, and '_'" + if string.find(role, '[^%w_/]') then + return false, "Role can only contain letters, numbers, '/', and '_'" end if permissions and not permissions_array then permissions_array = {} |