mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-20 14:31:30 +08:00
Merge pull request #6142 from G-Chubinidze/gc_SCI_9178
Unable to create a MarvinJS attachment [SCI-9178]
This commit is contained in:
commit
ad9152a137
3 changed files with 27 additions and 38 deletions
|
@ -15,25 +15,19 @@ class MarvinJsAssetsController < ApplicationController
|
|||
|
||||
create_create_marvinjs_activity(result[:asset], current_user)
|
||||
|
||||
if result[:asset] && marvin_params[:object_type] == 'Step'
|
||||
render json: {
|
||||
html: render_to_string(partial: 'assets/asset', locals: {
|
||||
asset: result[:asset],
|
||||
gallery_view_id: marvin_params[:object_id]
|
||||
})
|
||||
}
|
||||
elsif result[:asset] && marvin_params[:object_type] == 'Result'
|
||||
@my_module = result[:object].my_module
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'my_modules/result',
|
||||
locals: { result: result[:object] }
|
||||
)
|
||||
}, status: :ok
|
||||
elsif result[:asset]
|
||||
render json: result[:asset]
|
||||
if result[:asset]
|
||||
if marvin_params[:object_type] == 'Step' || marvin_params[:object_type] == 'Result'
|
||||
render json: {
|
||||
html: render_to_string(partial: 'assets/asset', locals: {
|
||||
asset: result[:asset],
|
||||
gallery_view_id: marvin_params[:object_id]
|
||||
})
|
||||
}
|
||||
else
|
||||
render json: result[:asset]
|
||||
end
|
||||
else
|
||||
render json: result[:asset].errors, status: :unprocessable_entity
|
||||
render json: result[:asset]&.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,12 +67,12 @@ class MarvinJsAssetsController < ApplicationController
|
|||
|
||||
def load_create_vars
|
||||
@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
|
||||
@protocol = @assoc.protocol
|
||||
elsif @assoc.class == MyModule
|
||||
@my_module = @assoc
|
||||
elsif @assoc.class == Result
|
||||
@my_module = @assoc.my_module
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,7 +80,7 @@ class MarvinJsAssetsController < ApplicationController
|
|||
if @assoc.class == Step
|
||||
return render_403 unless can_read_protocol_in_module?(@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)
|
||||
else
|
||||
render_403
|
||||
|
@ -96,8 +90,8 @@ class MarvinJsAssetsController < ApplicationController
|
|||
def check_edit_permission
|
||||
if @assoc.class == Step
|
||||
return render_403 unless can_manage_step?(@assoc)
|
||||
elsif @assoc.class == Result || @assoc.class == MyModule
|
||||
return render_403 unless can_manage_my_module?(@my_module)
|
||||
elsif @assoc.class == Result
|
||||
return render_403 unless can_manage_my_module?(@assoc.my_module)
|
||||
else
|
||||
render_403
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class ResultSerializer < ActiveModel::Serializer
|
|||
include InputSanitizeHelper
|
||||
|
||||
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
|
||||
|
||||
def marvinjs_enabled
|
||||
|
|
|
@ -47,20 +47,15 @@ class MarvinJsService
|
|||
private
|
||||
|
||||
def connect_asset(asset, params, current_user)
|
||||
if params[:object_type] == 'Step'
|
||||
object = params[:object_type].constantize.find(params[:object_id])
|
||||
asset.update!(view_mode: object.assets_view_mode)
|
||||
object.assets << asset
|
||||
elsif params[:object_type] == 'Result'
|
||||
my_module = MyModule.find_by(id: params[:object_id])
|
||||
return unless my_module
|
||||
object = case params[:object_type]
|
||||
when 'Step'
|
||||
Step.find(params[:object_id])
|
||||
when 'Result'
|
||||
Result.find(params[:object_id])
|
||||
end
|
||||
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 }
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue