Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin2: Added content for "Users" sub-tab in the "Rights" tab #445

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 90 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 obj = object:gsub('user.','')
table.insert(aAclTab.Cache.Users[group], obj)
end

aAclTab.RefreshUsersList()
end
}

Expand All @@ -84,14 +106,55 @@ 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)

local result = messageBox("Are you sure you want to remove the user '"..object.."' from the '"..group.."' ACL group?", MB_QUESTION, MB_YESNO)

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

aAclTab.Cache.Users[group] = nil
aAclTab.RefreshUsersList()
end
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 +238,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,obj in ipairs(aclGroupListObjects(aclGetGroup(group))) do
if (obj:sub(1,5) == 'user.') then
table.insert(data, obj)
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:gsub('user.','').."' from the '"..group.."' ACL group", MB_INFO)
else
messageBox(client, "Failed to removed user '"..object:gsub('user.','').."' from the '"..group.."' ACL group", MB_INFO)
end
elseif (action == ACL_ADD) then
if (aclGroupAddObject(aclGetGroup(group), 'user.'..object)) then
messageBox(client, "Successfully added user '"..object:gsub('user.','').."' to the '"..group.."' ACL group", MB_INFO)
else
messageBox(client, "Failed to added user '"..object:gsub('user.','').."' to the '"..group.."' ACL group", MB_INFO)
end
end
end,
[ACL_RESOURCES] = function()
end,
Expand Down