From 7b5a65416a597d076360e4cc4613193ee4c93039 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 11:47:23 +0200 Subject: [PATCH 01/20] Update status endpoint --- config/initializers/extends.rb | 2 +- spec/controllers/api/api_controller_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb index d186191da..15eea86f5 100644 --- a/config/initializers/extends.rb +++ b/config/initializers/extends.rb @@ -61,7 +61,7 @@ class Extends repository_asset_value: :asset] # List of implemented core API versions - API_VERSIONS = ['20170715'] + API_VERSIONS = ['v1'] # Array used for injecting names of additional authentication methods for API API_PLUGABLE_AUTH_METHODS = [:azure_jwt_auth] diff --git a/spec/controllers/api/api_controller_spec.rb b/spec/controllers/api/api_controller_spec.rb index 90aa792ba..68a7ec432 100644 --- a/spec/controllers/api/api_controller_spec.rb +++ b/spec/controllers/api/api_controller_spec.rb @@ -16,8 +16,8 @@ describe Api::ApiController, type: :controller do expect { hash_body = json }.not_to raise_exception expect(hash_body).to match( 'message' => I18n.t('api.core.status_ok'), - 'versions' => [{ 'version' => '20170715', - 'baseUrl' => '/api/20170715/' }] + 'versions' => [{ 'version' => 'v1', + 'baseUrl' => '/api/v1/' }] ) end end From 6faaff550b8dc3341a755e763bed4cdf4031008e Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 12:18:57 +0200 Subject: [PATCH 02/20] Update GET /teams, GET teams/:team_id endpoints slightly --- app/controllers/api/v1/teams_controller.rb | 4 +++- app/serializers/api/v1/team_serializer.rb | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/teams_controller.rb b/app/controllers/api/v1/teams_controller.rb index 53e6e0c0c..40c4eefb0 100644 --- a/app/controllers/api/v1/teams_controller.rb +++ b/app/controllers/api/v1/teams_controller.rb @@ -13,7 +13,9 @@ module Api end def show - render jsonapi: @team, serializer: TeamSerializer + render jsonapi: @team, + serializer: TeamSerializer, + include: :created_by end private diff --git a/app/serializers/api/v1/team_serializer.rb b/app/serializers/api/v1/team_serializer.rb index ffe94acc0..62d13afae 100644 --- a/app/serializers/api/v1/team_serializer.rb +++ b/app/serializers/api/v1/team_serializer.rb @@ -4,6 +4,7 @@ module Api module V1 class TeamSerializer < ActiveModel::Serializer attributes :id, :name, :description, :space_taken + belongs_to :created_by, serializer: UserSerializer end end end From eaa8a627a843ff4d6766b8481e4dfc22645494db Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 12:39:44 +0200 Subject: [PATCH 03/20] Update GET /inventories, GET /inventories/:inventory_id endpoints --- app/controllers/api/v1/inventories_controller.rb | 4 +++- app/serializers/api/v1/inventory_serializer.rb | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/inventories_controller.rb b/app/controllers/api/v1/inventories_controller.rb index 70fef6fea..9b901980a 100644 --- a/app/controllers/api/v1/inventories_controller.rb +++ b/app/controllers/api/v1/inventories_controller.rb @@ -27,7 +27,9 @@ module Api end def show - render jsonapi: @inventory, serializer: InventorySerializer + render jsonapi: @inventory, + serializer: InventorySerializer, + include: :created_by end def update diff --git a/app/serializers/api/v1/inventory_serializer.rb b/app/serializers/api/v1/inventory_serializer.rb index dfe55f534..88752ecf3 100644 --- a/app/serializers/api/v1/inventory_serializer.rb +++ b/app/serializers/api/v1/inventory_serializer.rb @@ -5,6 +5,7 @@ module Api class InventorySerializer < ActiveModel::Serializer type :inventories attributes :id, :name + belongs_to :created_by, serializer: UserSerializer end end end From 6625b4019e4a4fd1121de58ecb1163b3db731d37 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 13:47:41 +0200 Subject: [PATCH 04/20] Update GET /inventory_columns, GET /inventory_columns/:id endpts --- .../api/v1/inventory_columns_controller.rb | 9 +- .../api/v1/inventory_column_serializer.rb | 4 +- .../v1/inventory_columns_controller_spec.rb | 103 ++++++++++++++++-- 3 files changed, 104 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/inventory_columns_controller.rb b/app/controllers/api/v1/inventory_columns_controller.rb index 2c9ae674c..1c50924ec 100644 --- a/app/controllers/api/v1/inventory_columns_controller.rb +++ b/app/controllers/api/v1/inventory_columns_controller.rb @@ -14,8 +14,9 @@ module Api .includes(:repository_list_items) .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: columns, each_serializer: InventoryColumnSerializer, - include: :inventory_list_items + render jsonapi: columns, + each_serializer: InventoryColumnSerializer, + hide_list_items: true end def create @@ -27,7 +28,9 @@ module Api end def show - render jsonapi: @inventory_column, serializer: InventoryColumnSerializer + render jsonapi: @inventory_column, + serializer: InventoryColumnSerializer, + include: :inventory_list_items end def update diff --git a/app/serializers/api/v1/inventory_column_serializer.rb b/app/serializers/api/v1/inventory_column_serializer.rb index 1d0f65b7a..347457446 100644 --- a/app/serializers/api/v1/inventory_column_serializer.rb +++ b/app/serializers/api/v1/inventory_column_serializer.rb @@ -7,7 +7,9 @@ module Api attributes :name, :data_type has_many :repository_list_items, key: :inventory_list_items, serializer: InventoryListItemSerializer, - class_name: 'RepositoryListItem' + class_name: 'RepositoryListItem', + if: -> { object.data_type == 'RepositoryListValue' && + !instance_options[:hide_list_items] } def data_type type_id = RepositoryColumn diff --git a/spec/requests/api/v1/inventory_columns_controller_spec.rb b/spec/requests/api/v1/inventory_columns_controller_spec.rb index 9af73ad5c..9a8992882 100644 --- a/spec/requests/api/v1/inventory_columns_controller_spec.rb +++ b/spec/requests/api/v1/inventory_columns_controller_spec.rb @@ -41,16 +41,9 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do ActiveModelSerializers::SerializableResource .new(@valid_inventory.repository_columns.limit(10), each_serializer: Api::V1::InventoryColumnSerializer, - include: :inventory_columns) + hide_list_items: true) .as_json[:data] ) - expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_columns.limit(10), - each_serializer: Api::V1::InventoryColumnSerializer, - include: :inventory_list_items) - .as_json[:included] - ) end it 'When invalid request, user in not member of the team' do @@ -87,6 +80,100 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do end end + describe 'GET inventory_column, #show' do + it 'Valid text column response' do + text_column = @valid_inventory.repository_columns.first + hash_body = nil + get api_v1_team_inventory_column_path( + id: text_column.id, + team_id: @teams.first.id, + inventory_id: @valid_inventory.id + ), headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(text_column, + serializer: Api::V1::InventoryColumnSerializer) + .as_json[:data] + ) + expect(hash_body[:data]).not_to include('relationships') + end + + it 'Valid list column response' do + list_column = @valid_inventory.repository_columns.second + hash_body = nil + get api_v1_team_inventory_column_path( + id: list_column.id, + team_id: @teams.first.id, + inventory_id: @valid_inventory.id + ), headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(list_column, + serializer: Api::V1::InventoryColumnSerializer) + .as_json[:data] + ) + expect(hash_body[:data]).to include('relationships') + expect(hash_body[:included]).to match( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_columns.limit(10), + each_serializer: Api::V1::InventoryColumnSerializer, + include: :inventory_list_items) + .as_json[:included] + ) + end + + it 'Valid file column response' do + file_column = @valid_inventory.repository_columns.third + hash_body = nil + get api_v1_team_inventory_column_path( + id: file_column.id, + team_id: @teams.first.id, + inventory_id: @valid_inventory.id + ), headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(file_column, + serializer: Api::V1::InventoryColumnSerializer) + .as_json[:data] + ) + expect(hash_body[:data]).not_to include('relationships') + end + + it 'Invalid request, non existing inventory column' do + get api_v1_team_inventory_column_path( + id: 1001, + team_id: @teams.first.id, + inventory_id: @teams.first.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(404) + end + + it 'When invalid request, incorrect repository' do + id = @teams.first.repositories.first.repository_columns.last.id + get api_v1_team_inventory_column_path( + id: id, + team_id: @teams.first.id, + inventory_id: @teams.second.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(404) + expect(RepositoryColumn.where(id: id)).to exist + end + + it 'When invalid request, repository from another team' do + id = @teams.first.repositories.first.repository_columns.last.id + get api_v1_team_inventory_column_path( + id: id, + team_id: @teams.second.id, + inventory_id: @teams.first.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(403) + expect(RepositoryColumn.where(id: id)).to exist + end + end + describe 'POST inventory_column, #create' do before :all do @valid_headers['Content-Type'] = 'application/json' From 9e78de6ef24e31b385913516fa101e57ea94fac5 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 17:11:59 +0200 Subject: [PATCH 05/20] 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" From d235dd780717073ff3f4fb048e10ab9a8bb3d6ce Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 18:37:40 +0200 Subject: [PATCH 06/20] Update GET /inventory_items, GET /inventory_items/:id endpoints --- .../api/v1/inventory_items_controller.rb | 3 ++- .../api/v1/inventory_cell_serializer.rb | 6 ----- .../api/v1/inventory_item_serializer.rb | 3 ++- .../api/v1/inventory_items_controller_spec.rb | 26 ++++++++++++++----- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/v1/inventory_items_controller.rb b/app/controllers/api/v1/inventory_items_controller.rb index 4ed13d37e..4f6815fcf 100644 --- a/app/controllers/api/v1/inventory_items_controller.rb +++ b/app/controllers/api/v1/inventory_items_controller.rb @@ -16,9 +16,10 @@ module Api repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES ).page(params.dig(:page, :number)) .per(params.dig(:page, :size)) + incl = params[:include] == 'inventory_cells' ? :inventory_cells : nil render jsonapi: items, each_serializer: InventoryItemSerializer, - include: :inventory_cells + include: incl end def create diff --git a/app/serializers/api/v1/inventory_cell_serializer.rb b/app/serializers/api/v1/inventory_cell_serializer.rb index b615f456c..dc89e1454 100644 --- a/app/serializers/api/v1/inventory_cell_serializer.rb +++ b/app/serializers/api/v1/inventory_cell_serializer.rb @@ -7,12 +7,6 @@ module Api attributes :id, :value_type, :value attribute :repository_column_id, key: :column_id - def value_type - type_id = RepositoryColumn - .data_types[object.repository_column.data_type] - I18n.t("api.v1.inventory_data_types.t#{type_id}") - end - def value value = case object.value_type diff --git a/app/serializers/api/v1/inventory_item_serializer.rb b/app/serializers/api/v1/inventory_item_serializer.rb index 3df5dc3f8..e980096fb 100644 --- a/app/serializers/api/v1/inventory_item_serializer.rb +++ b/app/serializers/api/v1/inventory_item_serializer.rb @@ -7,7 +7,8 @@ module Api attributes :name has_many :repository_cells, key: :inventory_cells, serializer: InventoryCellSerializer, - class_name: 'RepositoryCell' + class_name: 'RepositoryCell', + unless: -> { object.repository_cells.empty? } end end end diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index ce1d969c7..5d569fbcc 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -75,6 +75,24 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do include: :inventory_cells) .as_json[:data] ) + expect(hash_body).not_to include('included') + end + + it 'Response with correct inventory items, included cells' do + hash_body = nil + get api_v1_team_inventory_items_path( + team_id: @teams.first.id, + inventory_id: @teams.first.repositories.first.id, + include: 'inventory_cells' + ), headers: @valid_headers + expect { hash_body = json }.not_to raise_exception + expect(hash_body[:data]).to match( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_rows.limit(10), + each_serializer: Api::V1::InventoryItemSerializer, + include: :inventory_cells) + .as_json[:data] + ) expect(hash_body[:included]).to match( ActiveModelSerializers::SerializableResource .new(@valid_inventory.repository_rows.limit(10), @@ -98,13 +116,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do include: :inventory_cells) .as_json[:data] ) - expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(100), - each_serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:included] - ) + expect(hash_body).not_to include('included') end it 'When invalid request, user in not member of the team' do From c9a15db85f6fc28262e2466d05233865f261c9ae Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sat, 6 Oct 2018 19:53:31 +0200 Subject: [PATCH 07/20] Fix GET /task_groups endpoints --- app/controllers/api/v1/my_modules_controller.rb | 12 ++++++------ ...ups_controller.rb => task_groups_controller.rb} | 11 +++++++---- app/serializers/api/v1/activity_serializer.rb | 2 +- app/serializers/api/v1/connection_serializer.rb | 4 ++-- .../api/v1/my_module_group_serializer.rb | 11 ----------- .../api/v1/my_module_repository_row_serializer.rb | 2 +- app/serializers/api/v1/my_module_tag_serializer.rb | 2 +- app/serializers/api/v1/protocol_serializer.rb | 2 +- app/serializers/api/v1/result_serializer.rb | 2 +- app/serializers/api/v1/task_group_serializer.rb | 14 ++++++++++++++ ...{my_module_serializer.rb => task_serializer.rb} | 2 +- .../api/v1/user_my_module_serializer.rb | 2 +- 12 files changed, 36 insertions(+), 30 deletions(-) rename app/controllers/api/v1/{my_module_groups_controller.rb => task_groups_controller.rb} (80%) delete mode 100644 app/serializers/api/v1/my_module_group_serializer.rb create mode 100644 app/serializers/api/v1/task_group_serializer.rb rename app/serializers/api/v1/{my_module_serializer.rb => task_serializer.rb} (83%) diff --git a/app/controllers/api/v1/my_modules_controller.rb b/app/controllers/api/v1/my_modules_controller.rb index 37a2b757d..7a9e3e41a 100644 --- a/app/controllers/api/v1/my_modules_controller.rb +++ b/app/controllers/api/v1/my_modules_controller.rb @@ -14,35 +14,35 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: tasks, each_serializer: MyModuleSerializer + render jsonapi: tasks, each_serializer: TaskSerializer end def show - render jsonapi: @my_module, serializer: MyModuleSerializer + render jsonapi: @my_module, serializer: TaskSerializer end def outputs outputs = @my_module.my_modules .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: outputs, each_serializer: MyModuleSerializer + render jsonapi: outputs, each_serializer: TaskSerializer end def output output = @my_module.my_modules.find(params.require(:id)) - render jsonapi: output, serializer: MyModuleSerializer + render jsonapi: output, serializer: TaskSerializer end def inputs inputs = @my_module.my_module_antecessors .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: inputs, each_serializer: MyModuleSerializer + render jsonapi: inputs, each_serializer: TaskSerializer end def input input = @my_module.my_module_antecessors.find(params.require(:id)) - render jsonapi: input, serializer: MyModuleSerializer + render jsonapi: input, serializer: TaskSerializer end private diff --git a/app/controllers/api/v1/my_module_groups_controller.rb b/app/controllers/api/v1/task_groups_controller.rb similarity index 80% rename from app/controllers/api/v1/my_module_groups_controller.rb rename to app/controllers/api/v1/task_groups_controller.rb index 1250da749..f586c2664 100644 --- a/app/controllers/api/v1/my_module_groups_controller.rb +++ b/app/controllers/api/v1/task_groups_controller.rb @@ -2,7 +2,7 @@ module Api module V1 - class MyModuleGroupsController < BaseController + class TaskGroupsController < BaseController before_action :load_team before_action :load_project before_action :load_experiment @@ -12,13 +12,16 @@ module Api my_module_groups = @experiment.my_module_groups .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - + incl = params[:include] == 'tasks' ? :tasks : nil render jsonapi: my_module_groups, - each_serializer: MyModuleGroupSerializer + each_serializer: TaskGroupSerializer, + include: incl end def show - render jsonapi: @my_module_group, serializer: MyModuleGroupSerializer + render jsonapi: @my_module_group, + serializer: TaskGroupSerializer, + include: :tasks end private diff --git a/app/serializers/api/v1/activity_serializer.rb b/app/serializers/api/v1/activity_serializer.rb index 70332ce2d..28910b7f5 100644 --- a/app/serializers/api/v1/activity_serializer.rb +++ b/app/serializers/api/v1/activity_serializer.rb @@ -6,7 +6,7 @@ module Api type :activities attributes :id, :my_module_id, :user_id, :type_of, :message, :project_id, :experiment_id - belongs_to :my_module, serializer: MyModuleSerializer + belongs_to :my_module, serializer: TaskSerializer end end end diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index 98f83c7c7..d75c41d18 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -5,8 +5,8 @@ module Api class ConnectionSerializer < ActiveModel::Serializer type :connections attributes :id, :input_id, :output_id - has_one :input_task, serializer: MyModuleSerializer - has_one :output_task, serializer: MyModuleSerializer + has_one :input_task, serializer: TaskSerializer + has_one :output_task, serializer: TaskSerializer def input_task MyModule.find(object.input_id) end diff --git a/app/serializers/api/v1/my_module_group_serializer.rb b/app/serializers/api/v1/my_module_group_serializer.rb deleted file mode 100644 index 06b52e31e..000000000 --- a/app/serializers/api/v1/my_module_group_serializer.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class MyModuleGroupSerializer < ActiveModel::Serializer - type :task_groups - attributes :id, :experiment_id - belongs_to :experiment, serializer: ExperimentSerializer - end - end -end diff --git a/app/serializers/api/v1/my_module_repository_row_serializer.rb b/app/serializers/api/v1/my_module_repository_row_serializer.rb index 1133b6263..4b543d012 100644 --- a/app/serializers/api/v1/my_module_repository_row_serializer.rb +++ b/app/serializers/api/v1/my_module_repository_row_serializer.rb @@ -6,7 +6,7 @@ module Api type :task_inventory_rows attribute :repository_row_id, key: :inventory_row_id attribute :my_module_id, key: :task_id - belongs_to :my_module, serializer: MyModuleSerializer + belongs_to :my_module, serializer: TaskSerializer end end end diff --git a/app/serializers/api/v1/my_module_tag_serializer.rb b/app/serializers/api/v1/my_module_tag_serializer.rb index 7f8e4a2e6..a35c39865 100644 --- a/app/serializers/api/v1/my_module_tag_serializer.rb +++ b/app/serializers/api/v1/my_module_tag_serializer.rb @@ -7,7 +7,7 @@ module Api attributes :id, :tag_id attribute :my_module_id, key: :task_id - belongs_to :my_module, serializer: MyModuleSerializer + belongs_to :my_module, serializer: TaskSerializer end end end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 6efafeddc..9f255b377 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -9,7 +9,7 @@ module Api :nr_of_linked_children attribute :my_module_id, key: :task_id - belongs_to :my_module, serializer: MyModuleSerializer + belongs_to :my_module, serializer: TaskSerializer end end end diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index 84aeb1408..5e990f1cb 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -7,7 +7,7 @@ module Api attributes :name, :user_id, :archived attribute :my_module_id, key: :task_id - belongs_to :my_module, serializer: MyModuleSerializer + belongs_to :my_module, serializer: TaskSerializer has_one :result_asset, key: :asset, serializer: ResultAssetSerializer, class_name: 'ResultAsset', diff --git a/app/serializers/api/v1/task_group_serializer.rb b/app/serializers/api/v1/task_group_serializer.rb new file mode 100644 index 000000000..2b7579e8f --- /dev/null +++ b/app/serializers/api/v1/task_group_serializer.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Api + module V1 + class TaskGroupSerializer < ActiveModel::Serializer + type :task_groups + attributes :id + has_many :my_modules, key: :tasks, + serializer: TaskSerializer, + class_name: 'MyModule', + unless: -> { object.my_modules.empty? } + end + end +end diff --git a/app/serializers/api/v1/my_module_serializer.rb b/app/serializers/api/v1/task_serializer.rb similarity index 83% rename from app/serializers/api/v1/my_module_serializer.rb rename to app/serializers/api/v1/task_serializer.rb index bc0f43779..8e2aa9cf0 100644 --- a/app/serializers/api/v1/my_module_serializer.rb +++ b/app/serializers/api/v1/task_serializer.rb @@ -2,7 +2,7 @@ module Api module V1 - class MyModuleSerializer < ActiveModel::Serializer + class TaskSerializer < ActiveModel::Serializer type :tasks attributes :id, :name, :due_date, :description, :state attribute :my_module_group_id, key: :task_group_id diff --git a/app/serializers/api/v1/user_my_module_serializer.rb b/app/serializers/api/v1/user_my_module_serializer.rb index 6474b8316..87edc39ce 100644 --- a/app/serializers/api/v1/user_my_module_serializer.rb +++ b/app/serializers/api/v1/user_my_module_serializer.rb @@ -7,7 +7,7 @@ module Api attributes :id, :user_id attribute :my_module_id, key: :task_id - belongs_to :my_module, serializer: MyModuleSerializer + belongs_to :my_module, serializer: TaskSerializer end end end From 0643ba216ed014624b64173be47e1a63d9a8c743 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 00:53:39 +0200 Subject: [PATCH 08/20] Fix GET /connections, /connections/:id endpoints --- .../api/v1/connections_controller.rb | 9 +++++++-- app/serializers/api/v1/connection_serializer.rb | 17 +++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/connections_controller.rb b/app/controllers/api/v1/connections_controller.rb index 1ce2111f4..ec42edf6b 100644 --- a/app/controllers/api/v1/connections_controller.rb +++ b/app/controllers/api/v1/connections_controller.rb @@ -12,11 +12,16 @@ module Api def index @connections = @connections.page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: @connections, each_serializer: ConnectionSerializer + incl = params[:include] == 'tasks' ? %i(input_task output_task) : nil + render jsonapi: @connections, + each_serializer: ConnectionSerializer, + include: incl end def show - render jsonapi: @connection, serializer: ConnectionSerializer + render jsonapi: @connection, + serializer: ConnectionSerializer, + include: %i(input_task output_task) end private diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index d75c41d18..143f440e9 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -4,16 +4,13 @@ module Api module V1 class ConnectionSerializer < ActiveModel::Serializer type :connections - attributes :id, :input_id, :output_id - has_one :input_task, serializer: TaskSerializer - has_one :output_task, serializer: TaskSerializer - def input_task - MyModule.find(object.input_id) - end - - def output_task - MyModule.find(object.output_id) - end + attributes :id + belongs_to :from, key: :input_task, + serializer: TaskSerializer, + class_name: 'MyModule' + belongs_to :to, key: :output_task, + serializer: TaskSerializer, + class_name: 'MyModule' end end end From 0de3c7eb4e3d8676bacbda8b2619d0d8f81704cf Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 09:45:24 +0200 Subject: [PATCH 09/20] Update GET /tasks, GET /tasks/:id endpoints, refactor routes.rb --- ..._modules_controller.rb => tasks_controller.rb} | 2 +- app/serializers/api/v1/task_serializer.rb | 4 +--- config/routes.rb | 15 +++------------ 3 files changed, 5 insertions(+), 16 deletions(-) rename app/controllers/api/v1/{my_modules_controller.rb => tasks_controller.rb} (98%) diff --git a/app/controllers/api/v1/my_modules_controller.rb b/app/controllers/api/v1/tasks_controller.rb similarity index 98% rename from app/controllers/api/v1/my_modules_controller.rb rename to app/controllers/api/v1/tasks_controller.rb index 7a9e3e41a..710fa8684 100644 --- a/app/controllers/api/v1/my_modules_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -2,7 +2,7 @@ module Api module V1 - class MyModulesController < BaseController + class TasksController < BaseController before_action :load_team before_action :load_project before_action :load_experiment diff --git a/app/serializers/api/v1/task_serializer.rb b/app/serializers/api/v1/task_serializer.rb index 8e2aa9cf0..ba5461fd2 100644 --- a/app/serializers/api/v1/task_serializer.rb +++ b/app/serializers/api/v1/task_serializer.rb @@ -4,9 +4,7 @@ module Api module V1 class TaskSerializer < ActiveModel::Serializer type :tasks - attributes :id, :name, :due_date, :description, :state - attribute :my_module_group_id, key: :task_group_id - belongs_to :experiment, serializer: ExperimentSerializer + attributes :id, :name, :due_date, :description, :state, :archived end end end diff --git a/config/routes.rb b/config/routes.rb index a680fa919..a7dbee906 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -563,18 +563,9 @@ Rails.application.routes.draw do end resources :projects, only: %i(index show) do resources :experiments, only: %i(index show) do - resources :my_module_groups, - only: %i(index show), - path: 'task_groups', - as: :task_groups - resources :connections, - only: %i(index show), - path: 'connections', - as: :connections - resources :my_modules, - only: %i(index show), - path: 'tasks', - as: :tasks do + resources :task_groups, only: %i(index show) + resources :connections, only: %i(index show) + resources :tasks, only: %i(index show) do resources :my_module_repository_rows, only: %i(index show), path: 'task_inventory_rows', as: :task_inventory_rows From f56e5b1e5aaa8b9b3a2f7ee6c20abab3824c3df3 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 10:07:37 +0200 Subject: [PATCH 10/20] Update GET /task/:task_id/items, GET /task/:task_id/items/:id endpts --- .../my_module_repository_rows_controller.rb | 59 ---------------- .../api/v1/task_inventory_items_controller.rb | 68 +++++++++++++++++++ app/controllers/api/v1/tasks_controller.rb | 14 ++-- .../api/v1/inventory_item_serializer.rb | 4 ++ .../v1/my_module_repository_row_serializer.rb | 12 ---- config/routes.rb | 6 +- 6 files changed, 82 insertions(+), 81 deletions(-) delete mode 100644 app/controllers/api/v1/my_module_repository_rows_controller.rb create mode 100644 app/controllers/api/v1/task_inventory_items_controller.rb delete mode 100644 app/serializers/api/v1/my_module_repository_row_serializer.rb diff --git a/app/controllers/api/v1/my_module_repository_rows_controller.rb b/app/controllers/api/v1/my_module_repository_rows_controller.rb deleted file mode 100644 index cdb2317ea..000000000 --- a/app/controllers/api/v1/my_module_repository_rows_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class MyModuleRepositoryRowsController < BaseController - before_action :load_team - before_action :load_project - before_action :load_experiment - before_action :load_task - before_action :load_task_repository_row, only: :show - - def index - repo_rows = @my_module.my_module_repository_rows - .page(params.dig(:page, :number)) - .per(params.dig(:page, :size)) - - render jsonapi: repo_rows, - each_serializer: MyModuleRepositoryRowSerializer - end - - def show - render jsonapi: @repo_row, serializer: MyModuleRepositoryRowSerializer - end - - private - - def load_team - @team = Team.find(params.require(:team_id)) - render jsonapi: {}, status: :forbidden unless can_read_team?(@team) - end - - def load_project - @project = @team.projects.find(params.require(:project_id)) - render jsonapi: {}, status: :forbidden unless can_read_project?( - @project - ) - end - - def load_experiment - @experiment = @project.experiments.find(params.require(:experiment_id)) - render jsonapi: {}, status: :forbidden unless can_read_experiment?( - @experiment - ) - end - - def load_task - @my_module = @experiment.my_modules.find(params.require(:task_id)) - render jsonapi: {}, status: :not_found if @my_module.nil? - end - - def load_task_repository_row - @repo_row = @my_module.my_module_repository_rows.find( - params.require(:id) - ) - render jsonapi: {}, status: :not_found if @repo_row.nil? - end - end - end -end diff --git a/app/controllers/api/v1/task_inventory_items_controller.rb b/app/controllers/api/v1/task_inventory_items_controller.rb new file mode 100644 index 000000000..ab28c6996 --- /dev/null +++ b/app/controllers/api/v1/task_inventory_items_controller.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +module Api + module V1 + class TaskInventoryItemsController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_inventory_item, only: :show + + def index + items = + @task.repository_rows + .includes(repository_cells: :repository_column) + .includes( + repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES + ).page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + incl = params[:include] == 'inventory_cells' ? :inventory_cells : nil + render jsonapi: items, + each_serializer: InventoryItemSerializer, + show_repository: true, + include: incl + end + + def show + render jsonapi: @item, + serializer: InventoryItemSerializer, + show_repository: true, + include: %i(inventory_cells inventory) + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @task = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @task.nil? + end + + def load_inventory_item + @item = @task.repository_rows.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @item.nil? + end + end + end +end diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 710fa8684..f4e271fa0 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -18,30 +18,30 @@ module Api end def show - render jsonapi: @my_module, serializer: TaskSerializer + render jsonapi: @task, serializer: TaskSerializer end def outputs - outputs = @my_module.my_modules + outputs = @task.my_modules .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) render jsonapi: outputs, each_serializer: TaskSerializer end def output - output = @my_module.my_modules.find(params.require(:id)) + output = @task.my_modules.find(params.require(:id)) render jsonapi: output, serializer: TaskSerializer end def inputs - inputs = @my_module.my_module_antecessors + inputs = @task.my_module_antecessors .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) render jsonapi: inputs, each_serializer: TaskSerializer end def input - input = @my_module.my_module_antecessors.find(params.require(:id)) + input = @task.my_module_antecessors.find(params.require(:id)) render jsonapi: input, serializer: TaskSerializer end @@ -67,7 +67,7 @@ module Api end def load_task - @my_module = @experiment.my_modules.find(params.require(:id)) + @task = @experiment.my_modules.find(params.require(:id)) end # Made the method below because its more elegant than changing parameters @@ -75,7 +75,7 @@ module Api # for a task, the "id" that used to be task id is now an id for the output # or input. def load_task_relative - @my_module = @experiment.my_modules.find(params.require(:task_id)) + @task = @experiment.my_modules.find(params.require(:task_id)) end end end diff --git a/app/serializers/api/v1/inventory_item_serializer.rb b/app/serializers/api/v1/inventory_item_serializer.rb index e980096fb..37d3db1f2 100644 --- a/app/serializers/api/v1/inventory_item_serializer.rb +++ b/app/serializers/api/v1/inventory_item_serializer.rb @@ -9,6 +9,10 @@ module Api serializer: InventoryCellSerializer, class_name: 'RepositoryCell', unless: -> { object.repository_cells.empty? } + belongs_to :repository, key: :inventory, + serializer: InventorySerializer, + class_name: 'Repository', + if: -> { instance_options[:show_repository] } end end end diff --git a/app/serializers/api/v1/my_module_repository_row_serializer.rb b/app/serializers/api/v1/my_module_repository_row_serializer.rb deleted file mode 100644 index 4b543d012..000000000 --- a/app/serializers/api/v1/my_module_repository_row_serializer.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class MyModuleRepositoryRowSerializer < ActiveModel::Serializer - type :task_inventory_rows - attribute :repository_row_id, key: :inventory_row_id - attribute :my_module_id, key: :task_id - belongs_to :my_module, serializer: TaskSerializer - end - end -end diff --git a/config/routes.rb b/config/routes.rb index a7dbee906..e04963770 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -566,9 +566,9 @@ Rails.application.routes.draw do resources :task_groups, only: %i(index show) resources :connections, only: %i(index show) resources :tasks, only: %i(index show) do - resources :my_module_repository_rows, only: %i(index show), - path: 'task_inventory_rows', - as: :task_inventory_rows + resources :task_inventory_items, only: %i(index show), + path: 'items', + as: :items resources :user_my_modules, only: %i(index show), path: 'user_tasks', as: :user_tasks From 94e80edc9bae59eb173b80c2c92eb5a863430e3f Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 10:16:00 +0200 Subject: [PATCH 11/20] Minor variable rename in task_groups_controller.rb --- app/controllers/api/v1/task_groups_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/task_groups_controller.rb b/app/controllers/api/v1/task_groups_controller.rb index f586c2664..c94a73865 100644 --- a/app/controllers/api/v1/task_groups_controller.rb +++ b/app/controllers/api/v1/task_groups_controller.rb @@ -9,17 +9,17 @@ module Api before_action :load_task_group, only: :show def index - my_module_groups = @experiment.my_module_groups + task_groups = @experiment.my_module_groups .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) incl = params[:include] == 'tasks' ? :tasks : nil - render jsonapi: my_module_groups, + render jsonapi: task_groups, each_serializer: TaskGroupSerializer, include: incl end def show - render jsonapi: @my_module_group, + render jsonapi: @task_group, serializer: TaskGroupSerializer, include: :tasks end @@ -46,7 +46,7 @@ module Api end def load_task_group - @my_module_group = @experiment.my_module_groups.find( + @task_group = @experiment.my_module_groups.find( params.require(:id) ) end From 98544f00e8c79bf01fe49617320293b9a810a2bd Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 10:20:01 +0200 Subject: [PATCH 12/20] Fix GET /tasks/:task_id/users, GET /tasks/:task_id/users/1 endpts --- ..._controller.rb => task_users_controller.rb} | 18 +++++++++--------- .../api/v1/user_my_module_serializer.rb | 13 ------------- config/routes.rb | 6 +++--- 3 files changed, 12 insertions(+), 25 deletions(-) rename app/controllers/api/v1/{user_my_modules_controller.rb => task_users_controller.rb} (70%) delete mode 100644 app/serializers/api/v1/user_my_module_serializer.rb diff --git a/app/controllers/api/v1/user_my_modules_controller.rb b/app/controllers/api/v1/task_users_controller.rb similarity index 70% rename from app/controllers/api/v1/user_my_modules_controller.rb rename to app/controllers/api/v1/task_users_controller.rb index 00c3acdc7..b5d72d826 100644 --- a/app/controllers/api/v1/user_my_modules_controller.rb +++ b/app/controllers/api/v1/task_users_controller.rb @@ -2,24 +2,24 @@ module Api module V1 - class UserMyModulesController < BaseController + class TaskUsersController < BaseController before_action :load_team before_action :load_project before_action :load_experiment before_action :load_task - before_action :load_user_task, only: :show + before_action :load_user, only: :show def index - user_tasks = @my_module.user_my_modules + users = @task.users .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: user_tasks, - each_serializer: UserMyModuleSerializer + render jsonapi: users, + each_serializer: UserSerializer end def show - render jsonapi: @user_task, serializer: UserMyModuleSerializer + render jsonapi: @user, serializer: UserSerializer end private @@ -44,11 +44,11 @@ module Api end def load_task - @my_module = @experiment.my_modules.find(params.require(:task_id)) + @task = @experiment.my_modules.find(params.require(:task_id)) end - def load_user_task - @user_task = @my_module.user_my_modules.find( + def load_user + @user = @task.users.find( params.require(:id) ) end diff --git a/app/serializers/api/v1/user_my_module_serializer.rb b/app/serializers/api/v1/user_my_module_serializer.rb deleted file mode 100644 index 87edc39ce..000000000 --- a/app/serializers/api/v1/user_my_module_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class UserMyModuleSerializer < ActiveModel::Serializer - type :user_tasks - attributes :id, :user_id - attribute :my_module_id, key: :task_id - - belongs_to :my_module, serializer: TaskSerializer - end - end -end diff --git a/config/routes.rb b/config/routes.rb index e04963770..abe255714 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -569,9 +569,9 @@ Rails.application.routes.draw do resources :task_inventory_items, only: %i(index show), path: 'items', as: :items - resources :user_my_modules, only: %i(index show), - path: 'user_tasks', - as: :user_tasks + resources :task_users, only: %i(index show), + path: 'users', + as: :users resources :my_module_tags, only: %i(index show), path: 'task_tags', as: :task_tags From 24299ef4c0d131442a508ff93fcce798a74935c5 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 11:10:41 +0200 Subject: [PATCH 13/20] Fix GET /tasks/:task_id/tags, GET /tasks/:task_id/tags/:id endpts --- ..._controller.rb => task_tags_controller.rb} | 26 +++++++++---------- .../api/v1/my_module_tag_serializer.rb | 13 ---------- app/serializers/api/v1/tag_serializer.rb | 10 +++++++ config/routes.rb | 6 ++--- 4 files changed, 26 insertions(+), 29 deletions(-) rename app/controllers/api/v1/{my_module_tags_controller.rb => task_tags_controller.rb} (57%) delete mode 100644 app/serializers/api/v1/my_module_tag_serializer.rb create mode 100644 app/serializers/api/v1/tag_serializer.rb diff --git a/app/controllers/api/v1/my_module_tags_controller.rb b/app/controllers/api/v1/task_tags_controller.rb similarity index 57% rename from app/controllers/api/v1/my_module_tags_controller.rb rename to app/controllers/api/v1/task_tags_controller.rb index c0b7911a5..abe4a30a5 100644 --- a/app/controllers/api/v1/my_module_tags_controller.rb +++ b/app/controllers/api/v1/task_tags_controller.rb @@ -2,24 +2,24 @@ module Api module V1 - class MyModuleTagsController < BaseController + class TaskTagsController < BaseController before_action :load_team before_action :load_project before_action :load_experiment before_action :load_task - before_action :load_task_tag, only: :show + before_action :load_tag, only: :show def index - task_tags = @my_module.my_module_tags - .page(params.dig(:page, :number)) - .per(params.dig(:page, :size)) + tags = @task.tags + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) - render jsonapi: task_tags, - each_serializer: MyModuleTagSerializer + render jsonapi: tags, + each_serializer: TagSerializer end def show - render jsonapi: @task_tag, serializer: MyModuleTagSerializer + render jsonapi: @tag, serializer: TagSerializer end private @@ -44,15 +44,15 @@ module Api end def load_task - @my_module = @experiment.my_modules.find(params.require(:task_id)) - render jsonapi: {}, status: :not_found if @my_module.nil? + @task = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @task.nil? end - def load_task_tag - @task_tag = @my_module.my_module_tags.find( + def load_tag + @tag = @task.tags.find( params.require(:id) ) - render jsonapi: {}, status: :not_found if @task_tag.nil? + render jsonapi: {}, status: :not_found if @tag.nil? end end end diff --git a/app/serializers/api/v1/my_module_tag_serializer.rb b/app/serializers/api/v1/my_module_tag_serializer.rb deleted file mode 100644 index a35c39865..000000000 --- a/app/serializers/api/v1/my_module_tag_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class MyModuleTagSerializer < ActiveModel::Serializer - type :task_tags - attributes :id, :tag_id - attribute :my_module_id, key: :task_id - - belongs_to :my_module, serializer: TaskSerializer - end - end -end diff --git a/app/serializers/api/v1/tag_serializer.rb b/app/serializers/api/v1/tag_serializer.rb new file mode 100644 index 000000000..d30f92ade --- /dev/null +++ b/app/serializers/api/v1/tag_serializer.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Api + module V1 + class TagSerializer < ActiveModel::Serializer + type :tags + attributes :id, :name, :color + end + end +end diff --git a/config/routes.rb b/config/routes.rb index abe255714..c0b1bf7bc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -572,9 +572,9 @@ Rails.application.routes.draw do resources :task_users, only: %i(index show), path: 'users', as: :users - resources :my_module_tags, only: %i(index show), - path: 'task_tags', - as: :task_tags + resources :task_tags, only: %i(index show), + path: 'tags', + as: :tags resources :protocols, only: %i(index show), path: 'protocols', as: :protocols From 239b974fa049eac42bbef8aa2868bc43d16944b3 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 11:29:56 +0200 Subject: [PATCH 14/20] Fix GET /tasks/:tid/protocols, GET /tasks/:tid/protocols/:id endpts --- app/controllers/api/v1/protocols_controller.rb | 6 +++--- .../api/v1/protocol_keyword_serializer.rb | 10 ++++++++++ app/serializers/api/v1/protocol_serializer.rb | 14 ++++++++------ config/routes.rb | 4 +--- 4 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 app/serializers/api/v1/protocol_keyword_serializer.rb diff --git a/app/controllers/api/v1/protocols_controller.rb b/app/controllers/api/v1/protocols_controller.rb index 8b8dfbe30..f4cd1a8be 100644 --- a/app/controllers/api/v1/protocols_controller.rb +++ b/app/controllers/api/v1/protocols_controller.rb @@ -10,7 +10,7 @@ module Api before_action :load_protocol, only: :show def index - protocols = @my_module.protocols + protocols = @task.protocols .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) @@ -44,11 +44,11 @@ module Api end def load_task - @my_module = @experiment.my_modules.find(params.require(:task_id)) + @task = @experiment.my_modules.find(params.require(:task_id)) end def load_protocol - @protocol = @my_module.protocols.find( + @protocol = @task.protocols.find( params.require(:id) ) end diff --git a/app/serializers/api/v1/protocol_keyword_serializer.rb b/app/serializers/api/v1/protocol_keyword_serializer.rb new file mode 100644 index 000000000..1f8f838d6 --- /dev/null +++ b/app/serializers/api/v1/protocol_keyword_serializer.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Api + module V1 + class ProtocolKeywordSerializer < ActiveModel::Serializer + type :protocol_keywords + attributes :id, :name + end + end +end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 9f255b377..5e60d2e7e 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -4,12 +4,14 @@ module Api module V1 class ProtocolSerializer < ActiveModel::Serializer type :protocols - attributes :id, :name, :authors, :description, - :team_id, :protocol_type, - :nr_of_linked_children - attribute :my_module_id, key: :task_id - - belongs_to :my_module, serializer: TaskSerializer + attributes :id, :name, :authors, :description, :protocol_type + has_many :protocol_keywords, + key: :keywords, + serializer: ProtocolKeywordSerializer, + class_name: 'ProtocolKeyword', + unless: -> { object.protocol_keywords.empty? } + belongs_to :parent, serializer: ProtocolSerializer, + if: -> { object.parent.present? } end end end diff --git a/config/routes.rb b/config/routes.rb index c0b1bf7bc..497770cfc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -575,9 +575,7 @@ Rails.application.routes.draw do resources :task_tags, only: %i(index show), path: 'tags', as: :tags - resources :protocols, only: %i(index show), - path: 'protocols', - as: :protocols + resources :protocols, only: %i(index show) resources :results, only: %i(index create show), path: 'results', as: :results From fca580face261a160fcdb39ba12cb2a009693bfc Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 11:35:12 +0200 Subject: [PATCH 15/20] Fix GET /tasks/:id/inputs, GET /tasks/:id/outputs endpoints --- app/controllers/api/v1/tasks_controller.rb | 22 ++++++---------------- config/routes.rb | 10 ++-------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index f4e271fa0..562af7919 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -7,7 +7,7 @@ module Api before_action :load_project before_action :load_experiment before_action :load_task, only: :show - before_action :load_task_relative, only: %i(outputs output inputs input) + before_action :load_task_relative, only: %i(inputs outputs) def index tasks = @experiment.my_modules @@ -21,18 +21,6 @@ module Api render jsonapi: @task, serializer: TaskSerializer end - def outputs - outputs = @task.my_modules - .page(params.dig(:page, :number)) - .per(params.dig(:page, :size)) - render jsonapi: outputs, each_serializer: TaskSerializer - end - - def output - output = @task.my_modules.find(params.require(:id)) - render jsonapi: output, serializer: TaskSerializer - end - def inputs inputs = @task.my_module_antecessors .page(params.dig(:page, :number)) @@ -40,9 +28,11 @@ module Api render jsonapi: inputs, each_serializer: TaskSerializer end - def input - input = @task.my_module_antecessors.find(params.require(:id)) - render jsonapi: input, serializer: TaskSerializer + def outputs + outputs = @task.my_modules + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + render jsonapi: outputs, each_serializer: TaskSerializer end private diff --git a/config/routes.rb b/config/routes.rb index 497770cfc..067ac2663 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -579,14 +579,8 @@ Rails.application.routes.draw do resources :results, only: %i(index create show), path: 'results', as: :results - get 'inputs', - to: 'my_modules#inputs' - get 'inputs/:id', - to: 'my_modules#input' - get 'outputs', - to: 'my_modules#outputs' - get 'outputs/:id', - to: 'my_modules#output' + get 'inputs', to: 'tasks#inputs' + get 'outputs', to: 'tasks#outputs' resources :activities, only: %i(index show), path: 'activities', as: :activities From fc5cf336146a2d660765d661db0d8bbbaca8d1ca Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 11:49:11 +0200 Subject: [PATCH 16/20] Fix GET /tasks/:id/activities endpoint --- .../api/v1/activities_controller.rb | 59 ------------------- app/controllers/api/v1/tasks_controller.rb | 11 +++- app/serializers/api/v1/activity_serializer.rb | 12 +++- app/serializers/api/v1/project_serializer.rb | 10 ++++ config/routes.rb | 4 +- 5 files changed, 30 insertions(+), 66 deletions(-) delete mode 100644 app/controllers/api/v1/activities_controller.rb create mode 100644 app/serializers/api/v1/project_serializer.rb diff --git a/app/controllers/api/v1/activities_controller.rb b/app/controllers/api/v1/activities_controller.rb deleted file mode 100644 index 125c44c86..000000000 --- a/app/controllers/api/v1/activities_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class ActivitiesController < BaseController - before_action :load_team - before_action :load_project - before_action :load_experiment - before_action :load_task - before_action :load_activity, only: :show - - def index - activities = @my_module.activities - .page(params.dig(:page, :number)) - .per(params.dig(:page, :size)) - - render jsonapi: activities, - each_serializer: ActivitySerializer - end - - def show - render jsonapi: @activity, serializer: ActivitySerializer - end - - private - - def load_team - @team = Team.find(params.require(:team_id)) - render jsonapi: {}, status: :forbidden unless can_read_team?(@team) - end - - def load_project - @project = @team.projects.find(params.require(:project_id)) - render jsonapi: {}, status: :forbidden unless can_read_project?( - @project - ) - end - - def load_experiment - @experiment = @project.experiments.find(params.require(:experiment_id)) - render jsonapi: {}, status: :forbidden unless can_read_experiment?( - @experiment - ) - end - - def load_task - @my_module = @experiment.my_modules.find(params.require(:task_id)) - render jsonapi: {}, status: :not_found if @my_module.nil? - end - - def load_activity - @activity = @my_module.activities.find( - params.require(:id) - ) - render jsonapi: {}, status: :not_found if @activity.nil? - end - end - end -end diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 562af7919..9ab8ed1ea 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -7,7 +7,7 @@ module Api before_action :load_project before_action :load_experiment before_action :load_task, only: :show - before_action :load_task_relative, only: %i(inputs outputs) + before_action :load_task_relative, only: %i(inputs outputs activities) def index tasks = @experiment.my_modules @@ -35,6 +35,15 @@ module Api render jsonapi: outputs, each_serializer: TaskSerializer end + def activities + activities = @task.activities + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: activities, + each_serializer: ActivitySerializer + end + private def load_team diff --git a/app/serializers/api/v1/activity_serializer.rb b/app/serializers/api/v1/activity_serializer.rb index 28910b7f5..251bc3711 100644 --- a/app/serializers/api/v1/activity_serializer.rb +++ b/app/serializers/api/v1/activity_serializer.rb @@ -4,9 +4,15 @@ module Api module V1 class ActivitySerializer < ActiveModel::Serializer type :activities - attributes :id, :my_module_id, :user_id, :type_of, :message, - :project_id, :experiment_id - belongs_to :my_module, serializer: TaskSerializer + attributes :id, :type_of, :message + belongs_to :project, serializer: ProjectSerializer + belongs_to :experiment, serializer: TaskSerializer, + if: -> { object.experiment.present? } + belongs_to :my_module, key: :task, + serializer: TaskSerializer, + class_name: 'MyModule', + if: -> { object.my_module.present? } + belongs_to :user, serializer: UserSerializer end end end diff --git a/app/serializers/api/v1/project_serializer.rb b/app/serializers/api/v1/project_serializer.rb new file mode 100644 index 000000000..db413ece6 --- /dev/null +++ b/app/serializers/api/v1/project_serializer.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Api + module V1 + class ProjectSerializer < ActiveModel::Serializer + type :projects + attributes :id + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 067ac2663..f4440c769 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -581,9 +581,7 @@ Rails.application.routes.draw do as: :results get 'inputs', to: 'tasks#inputs' get 'outputs', to: 'tasks#outputs' - resources :activities, only: %i(index show), - path: 'activities', - as: :activities + get 'activities', to: 'tasks#activities' end end end From 7527dc7352faf0e7ca89da6e77dabd2a7f0079fc Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 12:36:58 +0200 Subject: [PATCH 17/20] Fix READ index, READ show, POST create /tasks/:id/results endpoints --- app/controllers/api/v1/results_controller.rb | 6 ++-- .../v1/repository_asset_value_serializer.rb | 3 +- .../api/v1/result_asset_serializer.rb | 28 +++++++++++++++++-- app/serializers/api/v1/result_serializer.rb | 22 +++++++-------- .../api/v1/result_table_serializer.rb | 10 ++++++- config/routes.rb | 4 +-- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/v1/results_controller.rb b/app/controllers/api/v1/results_controller.rb index 068d927f3..938c4e20a 100644 --- a/app/controllers/api/v1/results_controller.rb +++ b/app/controllers/api/v1/results_controller.rb @@ -14,7 +14,7 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) render jsonapi: results, each_serializer: ResultSerializer, - include: %i(asset table text) + include: %i(text table file) end def create @@ -22,13 +22,13 @@ module Api throw ActionController::ParameterMissing unless @result render jsonapi: @result, serializer: ResultSerializer, - include: %i(asset table text), + include: %i(text table file), status: :created end def show render jsonapi: @result, serializer: ResultSerializer, - include: %i(asset table text) + include: %i(text table file) end private diff --git a/app/serializers/api/v1/repository_asset_value_serializer.rb b/app/serializers/api/v1/repository_asset_value_serializer.rb index be1373efb..50fac8350 100644 --- a/app/serializers/api/v1/repository_asset_value_serializer.rb +++ b/app/serializers/api/v1/repository_asset_value_serializer.rb @@ -23,8 +23,9 @@ module Api elsif object.asset&.file&.is_stored_on_s3? object.asset.presigned_url(download: true) else + # TODO # separate api endpoint for local files download is needed - download_asset_path(object.asset.id) + 'url'#download_asset_path(object.asset.id) end end end diff --git a/app/serializers/api/v1/result_asset_serializer.rb b/app/serializers/api/v1/result_asset_serializer.rb index f6638c2b7..f69dbbae8 100644 --- a/app/serializers/api/v1/result_asset_serializer.rb +++ b/app/serializers/api/v1/result_asset_serializer.rb @@ -3,8 +3,32 @@ module Api module V1 class ResultAssetSerializer < ActiveModel::Serializer - type :result_assets - attributes :asset_id + type :result_files + attributes :file_id, :file_name, :file_size, :url + + def file_id + object.asset&.id + end + + def file_name + object.asset&.file_file_name + end + + def file_size + object.asset&.file_file_size + end + + def url + if !object.asset&.file_present + nil + elsif object.asset&.file&.is_stored_on_s3? + object.asset.presigned_url(download: true) + else + # TODO + # separate api endpoint for local files download is needed + 'url'#download_asset_path(object.asset.id) + end + end end end end diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index 5e990f1cb..ea0f4b334 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -4,22 +4,20 @@ module Api module V1 class ResultSerializer < ActiveModel::Serializer type :results - attributes :name, :user_id, :archived - attribute :my_module_id, key: :task_id - - belongs_to :my_module, serializer: TaskSerializer - has_one :result_asset, key: :asset, - serializer: ResultAssetSerializer, - class_name: 'ResultAsset', - if: -> { object.is_asset } - has_one :result_table, key: :table, - serializer: ResultTableSerializer, - class_name: 'ResultTable', - if: -> { object.is_table } + attributes :name, :archived + belongs_to :user, serializer: UserSerializer has_one :result_text, key: :text, serializer: ResultTextSerializer, class_name: 'ResultText', if: -> { object.is_text } + has_one :result_table, key: :table, + serializer: ResultTableSerializer, + class_name: 'ResultTable', + if: -> { object.is_table } + has_one :result_asset, key: :file, + serializer: ResultAssetSerializer, + class_name: 'ResultAsset', + if: -> { object.is_asset } end end end diff --git a/app/serializers/api/v1/result_table_serializer.rb b/app/serializers/api/v1/result_table_serializer.rb index b4bdddc1c..211950441 100644 --- a/app/serializers/api/v1/result_table_serializer.rb +++ b/app/serializers/api/v1/result_table_serializer.rb @@ -4,7 +4,15 @@ module Api module V1 class ResultTableSerializer < ActiveModel::Serializer type :result_tables - attributes :table_id + attributes :table_id, :table_contents + + def table_id + object.table&.id + end + + def table_contents + object.table&.contents + end end end end diff --git a/config/routes.rb b/config/routes.rb index f4440c769..4b5ebcef1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -576,9 +576,7 @@ Rails.application.routes.draw do path: 'tags', as: :tags resources :protocols, only: %i(index show) - resources :results, only: %i(index create show), - path: 'results', - as: :results + resources :results, only: %i(index create show) get 'inputs', to: 'tasks#inputs' get 'outputs', to: 'tasks#outputs' get 'activities', to: 'tasks#activities' From 0bd3c81e39e52b0c66ec6dbd90b1ac3d7cf44644 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 13:07:27 +0200 Subject: [PATCH 18/20] Fix /users, /users/:id/identities endpoints --- config/routes.rb | 4 +++- .../{user_identeties.rb => user_identities.rb} | 0 ..._spec.rb => user_identities_controller_spec.rb} | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) rename spec/factories/{user_identeties.rb => user_identities.rb} (100%) rename spec/requests/api/v1/{users_identeties_controller_spec.rb => user_identities_controller_spec.rb} (89%) diff --git a/config/routes.rb b/config/routes.rb index 4b5ebcef1..e07102f33 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -586,7 +586,9 @@ Rails.application.routes.draw do end resources :users, only: %i(show) do resources :user_identities, - only: %i(index create show update destroy) + only: %i(index create show update destroy), + path: 'identities', + as: :identities end end end diff --git a/spec/factories/user_identeties.rb b/spec/factories/user_identities.rb similarity index 100% rename from spec/factories/user_identeties.rb rename to spec/factories/user_identities.rb diff --git a/spec/requests/api/v1/users_identeties_controller_spec.rb b/spec/requests/api/v1/user_identities_controller_spec.rb similarity index 89% rename from spec/requests/api/v1/users_identeties_controller_spec.rb rename to spec/requests/api/v1/user_identities_controller_spec.rb index 3a927f5a2..e0d80d110 100644 --- a/spec/requests/api/v1/users_identeties_controller_spec.rb +++ b/spec/requests/api/v1/user_identities_controller_spec.rb @@ -15,7 +15,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'GET user_identities, #index' do it 'When valid request, requested identities for current user' do hash_body = nil - get api_v1_user_user_identities_path(user_id: @user1.id), + get api_v1_user_identities_path(user_id: @user1.id), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( @@ -28,7 +28,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do it 'When invalid request, requested user is not signed in user' do hash_body = nil - get api_v1_user_user_identities_path(user_id: @user2.id), + get api_v1_user_identities_path(user_id: @user2.id), headers: @valid_headers expect(response).to have_http_status(403) expect(hash_body).to match(nil) @@ -36,7 +36,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do it 'When invalid request, non existing user' do hash_body = nil - get api_v1_user_user_identities_path(user_id: 123), + get api_v1_user_identities_path(user_id: 123), headers: @valid_headers expect(response).to have_http_status(403) expect(hash_body).to match(nil) @@ -46,7 +46,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'POST user_identities, #create' do it 'When valid request, create new identity for current user' do hash_body = nil - post api_v1_user_user_identities_path(user_id: @user1.id), + post api_v1_user_identities_path(user_id: @user1.id), params: { data: { type: 'user_identities', attributes: { uid: Faker::Crypto.unique.sha1, @@ -66,7 +66,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'GET user_identity, #show' do it 'When valid request, requested specific identity for current user' do hash_body = nil - get api_v1_user_user_identity_path( + get api_v1_user_identity_path( user_id: @user1.id, id: @user1.user_identities.order(:id).last ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception @@ -82,7 +82,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'PUT user_identities, #update' do it 'When valid request, update identity for current user' do hash_body = nil - put api_v1_user_user_identity_path(user_id: @user1.id, + put api_v1_user_identity_path(user_id: @user1.id, id: @user1.user_identities.order(:id).last), params: { data: { id: @user1.user_identities.order(:id).last.id, @@ -103,7 +103,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'DELETE user_identity, #destroy' do it 'When valid request, destroy specified identity for current user' do identity = @user1.user_identities.order(:id).last - delete api_v1_user_user_identity_path(user_id: @user1.id, id: identity), + delete api_v1_user_identity_path(user_id: @user1.id, id: identity), headers: @valid_headers expect(response).to have_http_status(200) expect(response.body).to eq('') From dc2ab5fdc0108124e3df96f6a6118817b7ded875 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 13:11:56 +0200 Subject: [PATCH 19/20] Fix the Doorkeeper config/access for all users (due to update of Gem) --- config/initializers/doorkeeper.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 9153fbabd..ffd7015c1 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -8,11 +8,9 @@ Doorkeeper.configure do end # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below. - # admin_authenticator do - # # Put your admin authentication logic here. - # # Example implementation: - # Admin.find_by_id(session[:admin_id]) || redirect_to(new_admin_session_url) - # end + admin_authenticator do + current_user || redirect_to(new_admin_session_url) + end # Authorization Code expiration time (default 10 minutes). authorization_code_expires_in 10.minutes From a8d56d32e2a04dd68259652390bb1b4dd919bc43 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 13:28:29 +0200 Subject: [PATCH 20/20] Hound is love, Hound is life --- .../api/v1/task_inventory_items_controller.rb | 9 ++++----- app/controllers/api/v1/tasks_controller.rb | 4 ++-- app/serializers/api/v1/inventory_column_serializer.rb | 11 ++++++----- app/serializers/api/v1/protocol_serializer.rb | 8 ++++---- .../api/v1/inventory_columns_controller_spec.rb | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/controllers/api/v1/task_inventory_items_controller.rb b/app/controllers/api/v1/task_inventory_items_controller.rb index ab28c6996..a7e87e96a 100644 --- a/app/controllers/api/v1/task_inventory_items_controller.rb +++ b/app/controllers/api/v1/task_inventory_items_controller.rb @@ -12,11 +12,10 @@ module Api def index items = @task.repository_rows - .includes(repository_cells: :repository_column) - .includes( - repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES - ).page(params.dig(:page, :number)) - .per(params.dig(:page, :size)) + .includes(repository_cells: :repository_column) + .includes(repository_cells: Extends::REPOSITORY_SEARCH_INCLUDES) + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) incl = params[:include] == 'inventory_cells' ? :inventory_cells : nil render jsonapi: items, each_serializer: InventoryItemSerializer, diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 9ab8ed1ea..46466be10 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -23,8 +23,8 @@ module Api def inputs inputs = @task.my_module_antecessors - .page(params.dig(:page, :number)) - .per(params.dig(:page, :size)) + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) render jsonapi: inputs, each_serializer: TaskSerializer end diff --git a/app/serializers/api/v1/inventory_column_serializer.rb b/app/serializers/api/v1/inventory_column_serializer.rb index 64fe83d1d..268cb151d 100644 --- a/app/serializers/api/v1/inventory_column_serializer.rb +++ b/app/serializers/api/v1/inventory_column_serializer.rb @@ -5,11 +5,12 @@ module Api class InventoryColumnSerializer < ActiveModel::Serializer type :inventory_columns attributes :name, :data_type - has_many :repository_list_items, key: :inventory_list_items, - serializer: InventoryListItemSerializer, - class_name: 'RepositoryListItem', - if: -> { object.data_type == 'RepositoryListValue' && - !instance_options[:hide_list_items] } + has_many :repository_list_items, + key: :inventory_list_items, + serializer: InventoryListItemSerializer, + class_name: 'RepositoryListItem', + if: -> { object.data_type == 'RepositoryListValue' && + !instance_options[:hide_list_items] } end end end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 5e60d2e7e..c2995f847 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -6,10 +6,10 @@ module Api type :protocols attributes :id, :name, :authors, :description, :protocol_type has_many :protocol_keywords, - key: :keywords, - serializer: ProtocolKeywordSerializer, - class_name: 'ProtocolKeyword', - unless: -> { object.protocol_keywords.empty? } + key: :keywords, + serializer: ProtocolKeywordSerializer, + class_name: 'ProtocolKeyword', + unless: -> { object.protocol_keywords.empty? } belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? } end diff --git a/spec/requests/api/v1/inventory_columns_controller_spec.rb b/spec/requests/api/v1/inventory_columns_controller_spec.rb index 9a8992882..1478a451c 100644 --- a/spec/requests/api/v1/inventory_columns_controller_spec.rb +++ b/spec/requests/api/v1/inventory_columns_controller_spec.rb @@ -93,7 +93,7 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do expect(hash_body[:data]).to match( ActiveModelSerializers::SerializableResource .new(text_column, - serializer: Api::V1::InventoryColumnSerializer) + serializer: Api::V1::InventoryColumnSerializer) .as_json[:data] ) expect(hash_body[:data]).not_to include('relationships') @@ -111,7 +111,7 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do expect(hash_body[:data]).to match( ActiveModelSerializers::SerializableResource .new(list_column, - serializer: Api::V1::InventoryColumnSerializer) + serializer: Api::V1::InventoryColumnSerializer) .as_json[:data] ) expect(hash_body[:data]).to include('relationships') @@ -136,7 +136,7 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do expect(hash_body[:data]).to match( ActiveModelSerializers::SerializableResource .new(file_column, - serializer: Api::V1::InventoryColumnSerializer) + serializer: Api::V1::InventoryColumnSerializer) .as_json[:data] ) expect(hash_body[:data]).not_to include('relationships')