diff --git a/app/controllers/form_field_values_controller.rb b/app/controllers/form_field_values_controller.rb index 51a2ea46d..8daab0737 100644 --- a/app/controllers/form_field_values_controller.rb +++ b/app/controllers/form_field_values_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class FormFieldValuesController < ApplicationController + before_action :check_forms_enabled before_action :load_form_response before_action :load_form_field before_action :check_create_permissions @@ -40,6 +41,10 @@ class FormFieldValuesController < ApplicationController render_403 unless can_submit_form_response?(@form_response) end + def check_forms_enabled + render_404 unless Form.forms_enabled? + end + def log_form_field_value_create_activity step = @form_response.step protocol = step.protocol diff --git a/app/controllers/form_fields_controller.rb b/app/controllers/form_fields_controller.rb index 09e34c386..12e62d793 100644 --- a/app/controllers/form_fields_controller.rb +++ b/app/controllers/form_fields_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class FormFieldsController < ApplicationController + before_action :check_forms_enabled before_action :load_form before_action :load_form_field, only: %i(update destroy) before_action :check_manage_permissions, only: %i(create update destroy reorder) @@ -85,6 +86,10 @@ class FormFieldsController < ApplicationController params.require(:form_field).permit(:name, :description, { data: [:type, :unit, :time, :range, validations: {}, options: []] }, :required, :allow_not_applicable, :uid) end + def check_forms_enabled + render_404 unless Form.forms_enabled? + end + def log_activity(type_of, message_items = {}) Activities::CreateActivityService .call(activity_type: type_of, diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index 02fec7046..583f07243 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -3,6 +3,7 @@ class FormsController < ApplicationController include UserRolesHelper + before_action :check_forms_enabled before_action :load_form, only: %i(show update publish unpublish export_form_responses) before_action :set_breadcrumbs_items, only: %i(index show) before_action :check_manage_permissions, only: :update @@ -221,6 +222,10 @@ class FormsController < ApplicationController params.require(:form).permit(:name, :description) end + def check_forms_enabled + render_404 unless Form.forms_enabled? + end + def log_activity(form, type_of, message_items = {}) Activities::CreateActivityService .call(activity_type: type_of, diff --git a/app/controllers/step_elements/form_responses_controller.rb b/app/controllers/step_elements/form_responses_controller.rb index 272be12fb..1721e4ca4 100644 --- a/app/controllers/step_elements/form_responses_controller.rb +++ b/app/controllers/step_elements/form_responses_controller.rb @@ -2,6 +2,7 @@ module StepElements class FormResponsesController < BaseController + before_action :check_forms_enabled, except: %i(destroy) before_action :load_form, only: :create before_action :load_step, only: :create before_action :load_form_response, except: :create @@ -90,6 +91,10 @@ module StepElements render_404 unless @form_response end + def check_forms_enabled + render_404 unless Form.forms_enabled? + end + def log_step_form_activity(element_type_of, message_items = {}) message_items[:my_module] = @protocol.my_module.id if @protocol.in_module? diff --git a/app/helpers/left_menu_bar_helper.rb b/app/helpers/left_menu_bar_helper.rb index abe0060ef..22ce21335 100644 --- a/app/helpers/left_menu_bar_helper.rb +++ b/app/helpers/left_menu_bar_helper.rb @@ -34,19 +34,7 @@ module LeftMenuBarHelper name: t('left_menu_bar.templates'), icon: 'sn-icon-protocols-templates', active: protocols_are_selected? || label_templates_are_selected? || forms_are_selected?, - submenu: [{ - url: forms_path, - name: t('left_menu_bar.forms'), - active: forms_are_selected? - }, { - url: protocols_path, - name: t('left_menu_bar.protocol'), - active: protocols_are_selected? - }, { - url: label_templates_path, - name: t('left_menu_bar.label'), - active: label_templates_are_selected? - }] + submenu: template_submenu }, { url: reports_path, name: t('left_menu_bar.reports'), @@ -103,4 +91,27 @@ module LeftMenuBarHelper def activities_are_selected? controller_name == 'global_activities' end + + def template_submenu + submenu = [ + { + url: protocols_path, + name: t('left_menu_bar.protocol'), + active: protocols_are_selected? + }, { + url: label_templates_path, + name: t('left_menu_bar.label'), + active: label_templates_are_selected? + } + ] + + if Form.forms_enabled? + submenu.unshift({ + url: forms_path, + name: t('left_menu_bar.forms'), + active: forms_are_selected? + }) + end + submenu + end end diff --git a/app/javascript/vue/protocol/step.vue b/app/javascript/vue/protocol/step.vue index aeb20f73b..a4180f4c1 100644 --- a/app/javascript/vue/protocol/step.vue +++ b/app/javascript/vue/protocol/step.vue @@ -410,14 +410,18 @@ emit: 'create:checklist', icon: 'sn-icon sn-icon-checkllist', data_e2e: `e2e-BT-protocol-step${this.step.id}-insertChecklist` - },{ - text: this.i18n.t('protocols.steps.insert.form'), - emit: 'create:form', - icon: 'sn-icon sn-icon-forms', - data_e2e: `e2e-BT-protocol-step${this.step.id}-insertForm` }]); } + if (this.urls.create_form_response_url) { + menu = menu.concat([{ + text: this.i18n.t('protocols.steps.insert.form'), + emit: 'create:form', + icon: 'sn-icon sn-icon-forms', + data_e2e: `e2e-BT-protocol-step${this.step.id}-insertForm` + }]); + } + return menu; }, actionsMenu() { diff --git a/app/models/form.rb b/app/models/form.rb index eb2f7bd5c..f5812460a 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -65,6 +65,10 @@ class Form < ApplicationRecord end end + def self.forms_enabled? + false + end + private def update_automatic_user_assignments diff --git a/app/serializers/step_form_response_serializer.rb b/app/serializers/step_form_response_serializer.rb index 7bb618190..70b030f3d 100644 --- a/app/serializers/step_form_response_serializer.rb +++ b/app/serializers/step_form_response_serializer.rb @@ -30,19 +30,21 @@ class StepFormResponseSerializer < ActiveModel::Serializer def urls user = scope[:user] || @instance_options[:user] + list = {} - list = { - add_value: form_response_form_field_values_path(object) - } + if Form.forms_enabled? + list[:add_value] = form_response_form_field_values_path(object) + list[:submit] = submit_step_form_response_path(object.step, object) if can_submit_form_response?(user, object) + list[:reset] = reset_step_form_response_path(object.step, object) if can_reset_form_response?(user, object) - list[:submit] = submit_step_form_response_path(object.step, object) if can_submit_form_response?(user, object) - list[:reset] = reset_step_form_response_path(object.step, object) if can_reset_form_response?(user, object) - if can_manage_step?(user, object.step) - list[:move_url] = move_step_form_response_path(object.step, object) - list[:move_targets_url] = move_targets_step_text_path(object.step, object) - list[:delete_url] = step_form_response_path(object.step, object) + if can_manage_step?(user, object.step) + list[:move_url] = move_step_form_response_path(object.step, object) + list[:move_targets_url] = move_targets_step_text_path(object.step, object) + end end + list[:delete_url] = step_form_response_path(object.step, object) if can_manage_step?(user, object.step) + list end end diff --git a/app/serializers/step_serializer.rb b/app/serializers/step_serializer.rb index 06b3bb0f2..c08bd2278 100644 --- a/app/serializers/step_serializer.rb +++ b/app/serializers/step_serializer.rb @@ -97,13 +97,14 @@ class StepSerializer < ActiveModel::Serializer create_table_url: step_tables_path(object), create_text_url: step_texts_path(object), create_checklist_url: step_checklists_path(object), - create_form_response_url: step_form_responses_path(object), update_asset_view_mode_url: update_asset_view_mode_step_path(object), update_view_state_url: update_view_state_step_path(object), direct_upload_url: rails_direct_uploads_url, upload_attachment_url: upload_attachment_step_path(object), reorder_elements_url: reorder_step_step_orderable_elements_path(step_id: object.id) }) + + urls_list[:create_form_response_url] = step_form_responses_path(object) if Form.forms_enabled? end urls_list