Skip to content

Commit

Permalink
Added content for "Users" sub-tab in the "Rights" tab
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Aug 10, 2023
1 parent b7cae33 commit 27602d0
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
88 changes: 86 additions & 2 deletions [admin]/admin2/client/main/admin_acl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
aAclTab = {
Cache = {
Groups = {},
ACL = {}
ACL = {},
Users = {}
}
}

Expand All @@ -31,6 +32,15 @@ function aAclTab.Create(tab)
-- users tab
aAclTab.UsersTab = guiCreateTab("Users", aAclTab.Panel)

aAclTab.Users = guiCreateGridList(0.01, 0.07, 0.98, 0.91, true, aAclTab.UsersTab)
guiGridListAddColumn(aAclTab.Users, "Name", 1)
aAclTab.UsersSearch = guiCreateEdit(0.01, 0.0125, 0.3, 0.05, "", true, aAclTab.UsersTab)
guiCreateInnerImage("client\\images\\search.png", aAclTab.UsersSearch)
guiHandleInput(aAclTab.UsersSearch)

aAclTab.UsersButton_AddUser = guiCreateButton(0.55, 0.0125, 0.2, 0.05, "Add User", true, aAclTab.UsersTab)
aAclTab.UsersButton_RemoveUser = guiCreateButton(0.775, 0.0125, 0.2, 0.05, "Remove User", true, aAclTab.UsersTab)

-- resources tab
aAclTab.ResourcesTab = guiCreateTab("Resources", aAclTab.Panel)

Expand All @@ -55,6 +65,7 @@ function aAclTab.Create(tab)
addEventHandler(EVENT_ACL, localPlayer, aAclTab.onSync)
addEventHandler("onClientGUIClick", aAclTab.Tab, aAclTab.onClick)
addEventHandler("onClientGUIChanged", aAclTab.AccessSearch, aAclTab.onChanged)
addEventHandler("onClientGUIChanged", aAclTab.UsersSearch, aAclTab.onChanged)
end

aAclTab.SyncFunctions = {
Expand All @@ -73,6 +84,17 @@ aAclTab.SyncFunctions = {
aAclTab.Cache.ACL[acl] = rights
end
aAclTab.RefreshAccess()
end,
[ACL_USERS] = function(group, data)
guiGridListClear(aAclTab.Users)
aAclTab.Cache.Users[group] = {}

for id,object in ipairs(data) do
local object = object:gsub('user.','')
table.insert(aAclTab.Cache.Users[group], object)
end

aAclTab.RefreshUsersList()
end
}

Expand All @@ -84,14 +106,51 @@ function aAclTab.onClick(key, state)
if (key ~= "left") then
return
end
if (source == aAclTab.Groups or source == aAclTab.ViewTypes) then

if (source == aAclTab.Groups) then
aAclTab.RefreshAccess()
aAclTab.RefreshUsersList()
elseif (source == aAclTab.ViewTypes) then
aAclTab.RefreshAccess()
elseif (source == aAclTab.UsersButton_RemoveUser) then
local selected = guiGridListGetSelectedItem(aAclTab.Users)

if (selected ~= -1) then
local object = guiGridListGetItemText(aAclTab.Users, selected, 1)
local selectedGroup = guiGridListGetSelectedItem(aAclTab.Groups)
local group = guiGridListGetItemText(aAclTab.Groups, selectedGroup, 1)

triggerServerEvent(EVENT_ACL, localPlayer, ACL_USERS, ACL_REMOVE, group, 'user.'..object)

aAclTab.Cache.Users[group] = nil
aAclTab.RefreshUsersList()
else
messageBox("No user selected!", MB_ERROR, MB_OK)
end
elseif (source == aAclTab.UsersButton_AddUser) then
local selected = guiGridListGetSelectedItem(aAclTab.Groups)

if (selected ~= -1) then
local nick = inputBox("Add user", "Enter user account name")

if (nick) then
local group = guiGridListGetItemText(aAclTab.Groups, selected, 1)
triggerServerEvent(EVENT_ACL, localPlayer, ACL_USERS, ACL_ADD, group, nick)

aAclTab.Cache.Users[group] = nil
aAclTab.RefreshUsersList()
end
else
messageBox("No group selected!", MB_ERROR, MB_OK)
end
end
end

function aAclTab.onChanged()
if (source == aAclTab.AccessSearch) then
aAclTab.RefreshAccess()
elseif (source == aAclTab.UsersSearch) then
aAclTab.RefreshUsersList()
end
end

Expand Down Expand Up @@ -175,3 +234,28 @@ function aAclTab.ClearAccess()
guiGridListRemoveColumn(aAclTab.Access, 1)
end
end

function aAclTab.RefreshUsersList()
local selected = guiGridListGetSelectedItem(aAclTab.Groups)

if (selected ~= -1) then
guiGridListClear(aAclTab.Users)

local group = guiGridListGetItemText(aAclTab.Groups, selected, 1)
local cache = aAclTab.Cache.Users[group]
if (cache and #cache > 0) then
local searchText = guiGetText(aAclTab.UsersSearch):lower()
local search = searchText:gsub(' ','') ~= ''

for i,user in ipairs(cache) do
local row = guiGridListAddRow(aAclTab.Users)

if ((search and (user:gsub('user.',''):lower():find(searchText))) or not search) then
guiGridListSetItemText(aAclTab.Users, row, 1, user, false, false)
end
end
else
triggerServerEvent(EVENT_ACL, localPlayer, ACL_USERS,ACL_GET, group)
end
end
end
24 changes: 23 additions & 1 deletion [admin]/admin2/server/admin_ACL.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,29 @@ local aACLFunctions = {
end
triggerClientEvent(client, EVENT_ACL, client, ACL_GROUPS, data)
end,
[ACL_USERS] = function()
[ACL_USERS] = function(action,group,object)
if (action == ACL_GET) then
local data = {}
for k,object in ipairs(aclGroupListObjects(aclGetGroup(group))) do
if (object:sub(1,5) == 'user.') then
table.insert(data, object)
end
end

triggerClientEvent(client, EVENT_ACL, client, ACL_USERS, group, data)
elseif (action == ACL_REMOVE) then
if (aclGroupRemoveObject(aclGetGroup(group), object)) then
messageBox(client, "Successfully removed user '"..object.."'", MB_INFO)
else
messageBox(client, "Failed to removed user '"..object.."'", MB_INFO)
end
elseif (action == ACL_ADD) then
if (aclGroupAddObject(aclGetGroup(group), 'user.'..object)) then
messageBox(client, "Successfully added user '"..object.."'", MB_INFO)
else
messageBox(client, "Failed to added user '"..object.."'", MB_INFO)
end
end
end,
[ACL_RESOURCES] = function()
end,
Expand Down

0 comments on commit 27602d0

Please sign in to comment.