diff --git a/app/contracts/project_custom_field_project_mappings/base_contract.rb b/app/contracts/project_custom_field_project_mappings/base_contract.rb index 0d506e33dc3..580a3855532 100644 --- a/app/contracts/project_custom_field_project_mappings/base_contract.rb +++ b/app/contracts/project_custom_field_project_mappings/base_contract.rb @@ -34,8 +34,8 @@ module ProjectCustomFieldProjectMappings attribute :custom_field_id validate :select_project_custom_fields_permission - validate :not_required - validate :visbile_to_user + validate :not_for_all_projects + validate :visible_to_user def select_project_custom_fields_permission return if user.allowed_in_project?(:select_project_custom_fields, model.project) @@ -43,15 +43,15 @@ module ProjectCustomFieldProjectMappings errors.add :base, :error_unauthorized end - def not_required - # only mappings of custom fields which are not required can be manipulated by the user - # enabling a custom field which is required happens in an after_save hook within the custom field model itself - return if model.project_custom_field.nil? || !model.project_custom_field.required? + def not_for_all_projects + # only mappings of custom fields which are not activated for all projects can be manipulated by the user + # enabling a custom field which is force-active happens in an after_save hook within the custom field model itself + return if model.project_custom_field.nil? || !model.project_custom_field.is_for_all? errors.add :custom_field_id, :cannot_delete_mapping end - def visbile_to_user + def visible_to_user # "invisible" custom fields can only be seen and edited by admins # using visible scope to check if the custom field is actually visible to the user return if model.project_custom_field.nil? || diff --git a/app/services/project_custom_field_project_mappings/bulk_update_service.rb b/app/services/project_custom_field_project_mappings/bulk_update_service.rb index 009d9a401f1..908505cf5a4 100644 --- a/app/services/project_custom_field_project_mappings/bulk_update_service.rb +++ b/app/services/project_custom_field_project_mappings/bulk_update_service.rb @@ -84,11 +84,11 @@ module ProjectCustomFieldProjectMappings end def fetch_custom_field_ids - # only custom fields which are not set to required can be disabled + # only custom fields which are set "for all projects" can be disabled ProjectCustomField .visible(@user) .where(custom_field_section_id: @project_custom_field_section.id) - .where(is_required: false) + .where(is_for_all: false) .pluck(:id) end diff --git a/app/services/projects/concerns/new_project_service.rb b/app/services/projects/concerns/new_project_service.rb index 077f59abe12..bad9e78e9b6 100644 --- a/app/services/projects/concerns/new_project_service.rb +++ b/app/services/projects/concerns/new_project_service.rb @@ -93,7 +93,7 @@ module Projects::Concerns # although the user explicitly provided a blank value. In order to not patch `acts_as_customizable` # further, we simply identify these custom values and deactivate the custom field. - custom_field_ids = new_project.custom_values.select { |cv| cv.value.blank? && !cv.required? }.pluck(:custom_field_id) + custom_field_ids = new_project.custom_values.select { |cv| cv.value.blank? && !cv.is_for_all? }.pluck(:custom_field_id) custom_field_project_mappings = new_project.project_custom_field_project_mappings custom_field_project_mappings @@ -104,11 +104,11 @@ module Projects::Concerns end def build_missing_project_custom_field_project_mappings(project) - # Activate all custom fields (via mapping table) that are required or - # have a value provided by the user, but no mapping exists. + # Activate all custom fields (via mapping table) that have no mapping, but are either + # intended for all projects, or have a value provided by the user. custom_field_ids = project.custom_values - .select { |cv| cv.value? || cv.required? } + .select { |cv| cv.value? || cv.is_for_all? } .pluck(:custom_field_id).uniq activated_custom_field_ids = project.project_custom_field_project_mappings.pluck(:custom_field_id).uniq