diff --git a/[admin]/admin2/client/main/admin_acl.lua b/[admin]/admin2/client/main/admin_acl.lua index 8534d14e4..909ea2bfb 100644 --- a/[admin]/admin2/client/main/admin_acl.lua +++ b/[admin]/admin2/client/main/admin_acl.lua @@ -10,7 +10,8 @@ aAclTab = { Cache = { Groups = {}, - ACL = {} + ACL = {}, + Users = {} } } @@ -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) @@ -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 = { @@ -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 } @@ -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 @@ -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 \ No newline at end of file diff --git a/[admin]/admin2/server/admin_ACL.lua b/[admin]/admin2/server/admin_ACL.lua index 9ff5d0f8d..33864c12c 100644 --- a/[admin]/admin2/server/admin_ACL.lua +++ b/[admin]/admin2/server/admin_ACL.lua @@ -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,