From 9e78de6ef24e31b385913516fa101e57ea94fac5 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 17:11:59 +0200 Subject: [PATCH] Update CREATE, PATCH, DELETE inventory_column endpoints --- app/controllers/api/v1/inventory_columns_controller.rb | 8 +++++++- app/serializers/api/v1/inventory_column_serializer.rb | 6 ------ config/locales/en.yml | 6 ------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/inventory_columns_controller.rb b/app/controllers/api/v1/inventory_columns_controller.rb index 1c50924ec..d11d8cd08 100644 --- a/app/controllers/api/v1/inventory_columns_controller.rb +++ b/app/controllers/api/v1/inventory_columns_controller.rb @@ -24,6 +24,7 @@ module Api @inventory.repository_columns.create!(inventory_column_params) render jsonapi: inventory_column, serializer: InventoryColumnSerializer, + hide_list_items: true, status: :created end @@ -37,7 +38,8 @@ module Api @inventory_column.attributes = update_inventory_column_params if @inventory_column.changed? && @inventory_column.save! render jsonapi: @inventory_column, - serializer: InventoryColumnSerializer + serializer: InventoryColumnSerializer, + hide_list_items: true else render body: nil end @@ -92,6 +94,10 @@ module Api raise ActionController::BadRequest, 'Object ID mismatch in URL and request body' end + if params.require(:data).require(:attributes).include?(:data_type) + raise ActionController::BadRequest, + 'Update of data_type attribute is not allowed' + end inventory_column_params[:attributes] end end diff --git a/app/serializers/api/v1/inventory_column_serializer.rb b/app/serializers/api/v1/inventory_column_serializer.rb index 347457446..64fe83d1d 100644 --- a/app/serializers/api/v1/inventory_column_serializer.rb +++ b/app/serializers/api/v1/inventory_column_serializer.rb @@ -10,12 +10,6 @@ module Api class_name: 'RepositoryListItem', if: -> { object.data_type == 'RepositoryListValue' && !instance_options[:hide_list_items] } - - def data_type - type_id = RepositoryColumn - .data_types[object.data_type] - I18n.t("api.v1.inventory_data_types.t#{type_id}") - end end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c7440c1de..8dee84d14 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1943,12 +1943,6 @@ en: status_ok: "Ok" expired_token: "Token is expired" invalid_token: "Token is invalid" - v1: - inventory_data_types: - t0: "text" - t1: "date" - t2: "list" - t3: "file" Add: "Add" Asset: "File"