Merge remote-tracking branch 'upstream/core-api' into core-api

This commit is contained in:
Luka Murn 2018-10-17 14:35:57 +02:00
commit 08c218e530
8 changed files with 38 additions and 29 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 = {}

View file

@ -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