Fix keys in connection serializer, fix destroy method [SCI-6087] (#3677)

This commit is contained in:
artoscinote 2021-11-18 16:10:07 +01:00 committed by GitHub
parent ebfd2f7924
commit ee8cb033fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View file

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

View file

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