mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-27 01:05:21 +08:00
Update external protocol importer backend in order to work with new protocol versioning [SCI-7829] (#5017)
This commit is contained in:
parent
95d04d11d2
commit
5de5d64be5
5 changed files with 16 additions and 17 deletions
|
@ -83,17 +83,13 @@ class ExternalProtocolsController < ApplicationController
|
|||
service_call = ProtocolImporters::ImportProtocolService.call(
|
||||
protocol_params: create_protocol_params,
|
||||
steps_params_json: create_steps_params[:steps],
|
||||
user_id: current_user.id,
|
||||
team_id: @team.id
|
||||
user: current_user,
|
||||
team: @team
|
||||
)
|
||||
|
||||
if service_call.succeed?
|
||||
protocol_type = service_call.protocol.in_repository_public? ? 'public' : 'private'
|
||||
message = t('protocols.index.external_protocols.import.success_flash',
|
||||
name: service_call.protocol.name,
|
||||
type: t("protocols.index.external_protocols.import.#{protocol_type}"))
|
||||
render json: { protocol: service_call.protocol,
|
||||
message: message }
|
||||
message = t('protocols.index.protocolsio.import.success_flash', name: service_call.protocol.name)
|
||||
render json: { protocol: service_call.protocol, message: message }
|
||||
else
|
||||
render json: { validation_errors: service_call.errors }, status: :bad_request
|
||||
end
|
||||
|
@ -120,7 +116,10 @@ class ExternalProtocolsController < ApplicationController
|
|||
end
|
||||
|
||||
def create_protocol_params
|
||||
params.require(:protocol).permit(:name, :authors, :published_on, :protocol_type, :description).except(:steps)
|
||||
params
|
||||
.require(:protocol)
|
||||
.permit(:name, :authors, :published_on, :protocol_type, :description, :visibility, :default_public_user_role_id)
|
||||
.except(:steps)
|
||||
end
|
||||
|
||||
def create_steps_params
|
||||
|
|
|
@ -6,9 +6,9 @@ module ProtocolImporters
|
|||
|
||||
attr_reader :errors, :protocol
|
||||
|
||||
def initialize(protocol_params:, steps_params_json:, team_id:, user_id:)
|
||||
@user = User.find_by_id user_id
|
||||
@team = Team.find_by_id team_id
|
||||
def initialize(protocol_params:, steps_params_json:, team:, user:)
|
||||
@user = user
|
||||
@team = team
|
||||
@protocol_params = protocol_params
|
||||
@steps_params = JSON.parse(steps_params_json)
|
||||
@errors = {}
|
||||
|
|
|
@ -43,7 +43,7 @@ module ProtocolImporters
|
|||
|
||||
def protocol_attributes
|
||||
{
|
||||
protocol_type: :in_repository_public,
|
||||
protocol_type: :in_repository_draft,
|
||||
added_by: @user,
|
||||
team: @team,
|
||||
name: @normalized_protocol_data[:name],
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<button type="button" class="btn btn-secondary" data-dismiss="modal"><%=t "general.cancel" %></button>
|
||||
<button type="button" class="btn btn-primary" data-action="import_protocol" data-import_type="in_repository_public"><%=t "protocols.import_export.import_modal.import_to_team_protocols_label" %></button>
|
||||
<button type="button" class="btn btn-primary" data-action="import_protocol" data-import_type="in_repository_private"><%=t "protocols.import_export.import_modal.import_to_private_protocols_label" %></button>
|
||||
<button type="button" class="btn btn-primary" data-action="import_protocol" data-import_type="in_repository_draft"><%=t "protocols.import_export.import_modal.import_to_team_protocols_label" %></button>
|
||||
<button type="button" class="btn btn-primary" data-action="import_protocol" data-import_type="in_repository_draft"><%=t "protocols.import_export.import_modal.import_to_private_protocols_label" %></button>
|
||||
|
|
|
@ -15,7 +15,7 @@ describe ProtocolImporters::ImportProtocolService do
|
|||
|
||||
let(:service_call) do
|
||||
ProtocolImporters::ImportProtocolService
|
||||
.call(protocol_params: protocol_params, steps_params_json: steps_params, user_id: user.id, team_id: team.id)
|
||||
.call(protocol_params: protocol_params, steps_params_json: steps_params, user: user, team: team)
|
||||
end
|
||||
|
||||
context 'when have invalid arguments' do
|
||||
|
@ -33,7 +33,7 @@ describe ProtocolImporters::ImportProtocolService do
|
|||
|
||||
s = ProtocolImporters::ImportProtocolService.call(protocol_params: protocol_params,
|
||||
steps_params_json: steps_invalid_params,
|
||||
user_id: user.id, team_id: team.id)
|
||||
user: user, team: team)
|
||||
expect(s.protocol).to be_invalid
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue