From ee8cb033fa7ceffc50b72231ae621e05d8fe9c7b Mon Sep 17 00:00:00 2001 From: artoscinote <85488244+artoscinote@users.noreply.github.com> Date: Thu, 18 Nov 2021 16:10:07 +0100 Subject: [PATCH] Fix keys in connection serializer, fix destroy method [SCI-6087] (#3677) --- app/controllers/api/v1/connections_controller.rb | 8 +++++--- app/serializers/api/v1/connection_serializer.rb | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/connections_controller.rb b/app/controllers/api/v1/connections_controller.rb index a56d9d2f0..3c84ce2f8 100644 --- a/app/controllers/api/v1/connections_controller.rb +++ b/app/controllers/api/v1/connections_controller.rb @@ -7,7 +7,7 @@ module Api before_action :load_project before_action :load_experiment before_action :load_connections - before_action :load_connection, only: :show + before_action :load_connection, only: %i(show destroy) before_action :check_manage_permissions, except: %i(index show) def index @@ -21,7 +21,7 @@ module Api def show render jsonapi: @connection, serializer: ConnectionSerializer, - include: %i(to from) + include: include_params end def create @@ -29,10 +29,12 @@ module Api render jsonapi: connection, serializer: ConnectionSerializer, - include: %i(to from) + include: include_params end def destroy + raise PermissionError.new(Connection, :destroy) unless can_manage_experiment?(@experiment) + @connection.destroy! render body: nil end diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index 143f440e9..e30c3c441 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -5,10 +5,10 @@ module Api class ConnectionSerializer < ActiveModel::Serializer type :connections attributes :id - belongs_to :from, key: :input_task, + belongs_to :from, key: :from, serializer: TaskSerializer, class_name: 'MyModule' - belongs_to :to, key: :output_task, + belongs_to :to, key: :to, serializer: TaskSerializer, class_name: 'MyModule' end