Merge pull request #6142 from G-Chubinidze/gc_SCI_9178

Unable to create a MarvinJS attachment [SCI-9178]
This commit is contained in:
G-Chubinidze 2023-09-06 16:39:10 +04:00 committed by GitHub
commit ad9152a137
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 38 deletions

View file

@ -15,25 +15,19 @@ class MarvinJsAssetsController < ApplicationController
create_create_marvinjs_activity(result[:asset], current_user) create_create_marvinjs_activity(result[:asset], current_user)
if result[:asset] && marvin_params[:object_type] == 'Step' if result[:asset]
render json: { if marvin_params[:object_type] == 'Step' || marvin_params[:object_type] == 'Result'
html: render_to_string(partial: 'assets/asset', locals: { render json: {
asset: result[:asset], html: render_to_string(partial: 'assets/asset', locals: {
gallery_view_id: marvin_params[:object_id] asset: result[:asset],
}) gallery_view_id: marvin_params[:object_id]
} })
elsif result[:asset] && marvin_params[:object_type] == 'Result' }
@my_module = result[:object].my_module else
render json: { render json: result[:asset]
html: render_to_string( end
partial: 'my_modules/result',
locals: { result: result[:object] }
)
}, status: :ok
elsif result[:asset]
render json: result[:asset]
else else
render json: result[:asset].errors, status: :unprocessable_entity render json: result[:asset]&.errors, status: :unprocessable_entity
end end
end end
@ -73,12 +67,12 @@ class MarvinJsAssetsController < ApplicationController
def load_create_vars def load_create_vars
@assoc = Step.find_by(id: marvin_params[:object_id]) if marvin_params[:object_type] == 'Step' @assoc = Step.find_by(id: marvin_params[:object_id]) if marvin_params[:object_type] == 'Step'
@assoc = MyModule.find_by(id: params[:object_id]) if marvin_params[:object_type] == 'Result' @assoc = Result.find_by(id: params[:object_id]) if marvin_params[:object_type] == 'Result'
if @assoc.class == Step if @assoc.class == Step
@protocol = @assoc.protocol @protocol = @assoc.protocol
elsif @assoc.class == MyModule elsif @assoc.class == Result
@my_module = @assoc @my_module = @assoc.my_module
end end
end end
@ -86,7 +80,7 @@ class MarvinJsAssetsController < ApplicationController
if @assoc.class == Step if @assoc.class == Step
return render_403 unless can_read_protocol_in_module?(@protocol) || return render_403 unless can_read_protocol_in_module?(@protocol) ||
can_read_protocol_in_repository?(@protocol) can_read_protocol_in_repository?(@protocol)
elsif @assoc.class == Result || @assoc.class == MyModule elsif @assoc.class == Result
return render_403 unless can_read_experiment?(@my_module.experiment) return render_403 unless can_read_experiment?(@my_module.experiment)
else else
render_403 render_403
@ -96,8 +90,8 @@ class MarvinJsAssetsController < ApplicationController
def check_edit_permission def check_edit_permission
if @assoc.class == Step if @assoc.class == Step
return render_403 unless can_manage_step?(@assoc) return render_403 unless can_manage_step?(@assoc)
elsif @assoc.class == Result || @assoc.class == MyModule elsif @assoc.class == Result
return render_403 unless can_manage_my_module?(@my_module) return render_403 unless can_manage_my_module?(@assoc.my_module)
else else
render_403 render_403
end end

View file

@ -8,7 +8,7 @@ class ResultSerializer < ActiveModel::Serializer
include InputSanitizeHelper include InputSanitizeHelper
attributes :name, :id, :urls, :updated_at, :created_at_formatted, :updated_at_formatted, :user, attributes :name, :id, :urls, :updated_at, :created_at_formatted, :updated_at_formatted, :user,
:my_module_id, :attachments_manageble, :marvinjs_enabled, :marvinjs_context, :my_module_id, :attachments_manageble, :marvinjs_enabled, :type, :marvinjs_context,
:wopi_enabled, :wopi_context, :created_at, :created_by :wopi_enabled, :wopi_context, :created_at, :created_by
def marvinjs_enabled def marvinjs_enabled

View file

@ -47,20 +47,15 @@ class MarvinJsService
private private
def connect_asset(asset, params, current_user) def connect_asset(asset, params, current_user)
if params[:object_type] == 'Step' object = case params[:object_type]
object = params[:object_type].constantize.find(params[:object_id]) when 'Step'
asset.update!(view_mode: object.assets_view_mode) Step.find(params[:object_id])
object.assets << asset when 'Result'
elsif params[:object_type] == 'Result' Result.find(params[:object_id])
my_module = MyModule.find_by(id: params[:object_id]) end
return unless my_module asset.update!(view_mode: object.assets_view_mode)
object.assets << asset
object = Result.create(user: current_user,
my_module: my_module,
name: prepare_name(params[:name]),
asset: asset,
last_modified_by: current_user)
end
{ asset: asset, object: object } { asset: asset, object: object }
end end