From fcfcc0d308f7ecff7257c33fd3e15bc23914fac8 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 31 May 2019 21:40:38 +0100 Subject: [PATCH] Added config to allow any user to make new tasks --- config/tasks.lua | 2 ++ modules/gui/task-list.lua | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/tasks.lua b/config/tasks.lua index 4c6bd54a..cc80d192 100644 --- a/config/tasks.lua +++ b/config/tasks.lua @@ -1,5 +1,7 @@ -- config file for the tasks gui return { + any_user_can_add_new_task = true, -- when false only people with edit permission can make new reports + user_can_edit_own_tasks = true, -- when false only people with edit permission can edit reports only_admins_can_edit = false, -- true will hide the edit and delete buttons from non (game) admins edit_tasks_role_permision = 'gui/task-list/edit' -- value used with custom permision system } \ No newline at end of file diff --git a/modules/gui/task-list.lua b/modules/gui/task-list.lua index d6b291d7..2292a7bb 100644 --- a/modules/gui/task-list.lua +++ b/modules/gui/task-list.lua @@ -53,7 +53,18 @@ local function remove_task(task_id) end --- If a player is allowed to use the edit buttons -local function player_allowed_edit(player) +local function player_allowed_edit(player,task_id) + if task_id then + local details = task_details[task_id] + if config.user_can_edit_own_tasks and details.last_edit_player == player.name then + return true + end + else + if config.any_user_can_add_new_task then + return true + end + end + if config.only_admins_can_edit and not player.admin then return false end @@ -200,7 +211,7 @@ function generate_task(player,element,task_id) Gui.set_padding(task_area) -- if the player can edit then it adds the edit and delete button - if player_allowed_edit(player) then + if player_allowed_edit(player,task_id) then local flow = Gui.create_right_align(element,'edit-'..task_id) flow.caption = task_id @@ -316,8 +327,10 @@ local function generate_container(player,element) } --- Right aligned button to toggle the section - local right_align = Gui.create_right_align(header) - add_new_task(right_align) + if player_allowed_edit(player) then + local right_align = Gui.create_right_align(header) + add_new_task(right_align) + end -- main flow for the data local flow =