diff --git a/Gemfile b/Gemfile index bda6b00dc..751c9ceb7 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem 'autosize-rails' # jQuery autosize plugin gem 'underscore-rails' gem 'turbolinks', '~> 5.1.1' -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'sdoc', '~> 1.0', group: :doc gem 'bcrypt', '~> 3.1.10' gem 'logging', '~> 2.0.0' gem 'aspector' # Aspect-oriented programming for Rails diff --git a/Gemfile.lock b/Gemfile.lock index ffbc8c0e0..661bcdd0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -399,7 +399,7 @@ GEM rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) - rdoc (4.3.0) + rdoc (6.0.4) recaptcha (4.6.3) json responders (2.4.0) @@ -461,9 +461,8 @@ GEM scss_lint (0.56.0) rake (>= 0.9, < 13) sass (~> 3.5.3) - sdoc (0.4.2) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) + sdoc (1.0.0) + rdoc (>= 5.0) shoulda-matchers (3.1.2) activesupport (>= 4.0.0) silencer (1.0.1) @@ -611,7 +610,7 @@ DEPENDENCIES sass-rails (~> 5.0.6) scenic (~> 1.4) scss_lint - sdoc (~> 0.4.0) + sdoc (~> 1.0) shoulda-matchers silencer simple_token_authentication (~> 1.15.1) @@ -631,7 +630,7 @@ DEPENDENCIES yomu RUBY VERSION - ruby 2.4.3p205 + ruby 2.4.4p296 BUNDLED WITH - 1.16.3 + 1.16.6 diff --git a/app/controllers/api/v1/inventory_columns_controller.rb b/app/controllers/api/v1/inventory_columns_controller.rb index d11d8cd08..51d554c30 100644 --- a/app/controllers/api/v1/inventory_columns_controller.rb +++ b/app/controllers/api/v1/inventory_columns_controller.rb @@ -84,9 +84,15 @@ module Api 'Wrong object type within parameters' end params.require(:data).require(:attributes) - params - .permit(data: { attributes: %i(name data_type) })[:data] - .merge(created_by: @current_user) + new_params = params + .permit(data: { attributes: %i(name data_type) })[:data] + .merge(created_by: @current_user) + if new_params[:attributes][:data_type].present? + new_params[:attributes][:data_type] = + Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS + .key(new_params.dig(:attributes, :data_type)) + end + new_params end def update_inventory_column_params @@ -94,7 +100,7 @@ module Api raise ActionController::BadRequest, 'Object ID mismatch in URL and request body' end - if params.require(:data).require(:attributes).include?(:data_type) + if inventory_column_params[:attributes].include?(:data_type) raise ActionController::BadRequest, 'Update of data_type attribute is not allowed' end diff --git a/app/controllers/api/v1/inventory_items_controller.rb b/app/controllers/api/v1/inventory_items_controller.rb index 4f6815fcf..f9d7f7bfe 100644 --- a/app/controllers/api/v1/inventory_items_controller.rb +++ b/app/controllers/api/v1/inventory_items_controller.rb @@ -119,7 +119,7 @@ module Api 'Wrong object type within parameters' end params.require(:data).require(:attributes) - params.permit(data: { attributes: %i(name uid) })[:data] + params.permit(data: { attributes: :name })[:data] end def update_inventory_item_params diff --git a/app/serializers/api/v1/inventory_cell_serializer.rb b/app/serializers/api/v1/inventory_cell_serializer.rb index dc89e1454..ab6dac081 100644 --- a/app/serializers/api/v1/inventory_cell_serializer.rb +++ b/app/serializers/api/v1/inventory_cell_serializer.rb @@ -8,23 +8,17 @@ module Api attribute :repository_column_id, key: :column_id def value - value = - case object.value_type - when 'RepositoryTextValue' - object.repository_text_value - when 'RepositoryDateValue' - object.repository_date_value - when 'RepositoryListValue' - object.repository_list_value - when 'RepositoryAssetValue' - object.repository_asset_value - end ActiveModelSerializers::SerializableResource.new( - value, + object.value, + class_name: object.value_type, namespace: Api::V1, adapter: :attribute ).as_json end + + def value_type + Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.value_type] + end end end end diff --git a/app/serializers/api/v1/inventory_column_serializer.rb b/app/serializers/api/v1/inventory_column_serializer.rb index 268cb151d..aee1733fc 100644 --- a/app/serializers/api/v1/inventory_column_serializer.rb +++ b/app/serializers/api/v1/inventory_column_serializer.rb @@ -9,8 +9,14 @@ module Api key: :inventory_list_items, serializer: InventoryListItemSerializer, class_name: 'RepositoryListItem', - if: -> { object.data_type == 'RepositoryListValue' && - !instance_options[:hide_list_items] } + if: (lambda do + object.data_type == 'RepositoryListValue' && + !instance_options[:hide_list_items] + end) + + def data_type + Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.data_type] + end end end end diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index 15eea86f5..3d0fb3d0d 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -66,6 +66,11 @@ class Extends # Array used for injecting names of additional authentication methods for API API_PLUGABLE_AUTH_METHODS = [:azure_jwt_auth] + API_REPOSITORY_DATA_TYPE_MAPPINGS = { 'RepositoryTextValue' => 'text', + 'RepositoryDateValue' => 'date', + 'RepositoryListValue' => 'list', + 'RepositoryAssetValue' => 'file' } + OMNIAUTH_PROVIDERS = [:linkedin] INITIAL_USER_OPTIONS = {} diff --git a/spec/requests/api/v1/inventory_columns_controller_spec.rb b/spec/requests/api/v1/inventory_columns_controller_spec.rb index 87dad2d1f..ffbb27718 100644 --- a/spec/requests/api/v1/inventory_columns_controller_spec.rb +++ b/spec/requests/api/v1/inventory_columns_controller_spec.rb @@ -181,8 +181,7 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do { type: 'inventory_columns', attributes: { name: Faker::Name.unique.name, - data_type: - RepositoryColumn.data_types.values.first + data_type: 'text' } } } end