From 4e920ecd159fac602589378072069005c9fc2c14 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 13 Jun 2022 14:02:40 +0100 Subject: [PATCH] Allow support user to create log on behalf of other users --- app/controllers/case_logs_controller.rb | 4 +--- app/models/case_log.rb | 2 +- app/views/case_logs/_log_list.html.erb | 4 ++-- config/forms/2021_2022.json | 32 +++++++++++++++++++++++++ config/forms/2022_2023.json | 32 +++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index e3e84ee39..75c61bf98 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -105,9 +105,7 @@ private end def case_log_params - if current_user && current_user.role == "support" - { "created_by_id": current_user.id }.merge(api_case_log_params) - elsif current_user + if current_user && current_user.role != "support" org_params.merge(api_case_log_params) else api_case_log_params diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 9cc36d235..94d82c32d 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -33,7 +33,7 @@ class CaseLog < ApplicationRecord belongs_to :owning_organisation, class_name: "Organisation", optional: true belongs_to :managing_organisation, class_name: "Organisation", optional: true - belongs_to :created_by, class_name: "User" + belongs_to :created_by, class_name: "User", optional: true scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_status, ->(status, _user = nil) { where status: } diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index dfccaabf9..458bfe6df 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -64,8 +64,8 @@ <%= status_tag(log.status) %> <% end %> <% if current_user.support? %> - <% row.cell(text: log.owning_organisation.name) %> - <% row.cell(text: log.managing_organisation.name) %> + <% row.cell(text: log.owning_organisation&.name) %> + <% row.cell(text: log.managing_organisation&.name) %> <% end %> <% end %> <% end %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 9eb1bc1cc..5d97858a9 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -36,6 +36,38 @@ ] ] }, + "user": { + "header": "", + "description": "", + "questions": { + "created_by_id": { + "header": "Which user are you creating this log for?", + "hint_text": "", + "type": "select", + "answer_options_lookup": { + "class": "User", + "scope": "all", + "id": "id", + "label": "name" + } + } + }, + "derived": true, + "depends_on": [ + [ + { + "object": "user", + "method": "role", + "value": "support" + }, + { + "object": "case_log", + "method": "owning_organisation_id.nil?", + "value": false + } + ] + ] + }, "needs_type": { "header": "", "description": "", diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index 327773a7b..6a906c8b7 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -36,6 +36,38 @@ ] ] }, + "user": { + "header": "", + "description": "", + "questions": { + "created_by_id": { + "header": "Which user are you creating this log for?", + "hint_text": "", + "type": "select", + "answer_options_lookup": { + "class": "User", + "scope": "all", + "id": "id", + "label": "name" + } + } + }, + "derived": true, + "depends_on": [ + [ + { + "object": "user", + "method": "role", + "value": "support" + }, + { + "object": "case_log", + "method": "owning_organisation_id.nil?", + "value": false + } + ] + ] + }, "needs_type": { "header": "", "description": "",