Merge pull request #5950 from rekonder/aj_SCI_8962

Implemented trial period for open vector editor [SCI-8962]
This commit is contained in:
ajugo 2023-08-10 10:57:47 +02:00 committed by GitHub
commit 5aaf1af1d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 16 deletions

View file

@ -5,6 +5,7 @@ class GeneSequenceAssetsController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :check_open_vector_service_enabled, except: :edit
before_action :load_vars, except: %i(new create)
before_action :load_create_vars, only: %i(new create)
@ -18,6 +19,7 @@ class GeneSequenceAssetsController < ApplicationController
def edit
@file_url = rails_representation_url(@asset.file)
@file_name = @asset.render_file_name
@ove_enabled = OpenVectorEditorService.enabled?
render :edit, layout: false
end
@ -111,11 +113,15 @@ class GeneSequenceAssetsController < ApplicationController
end
def check_manage_permission
render_403 unless can_manage_asset?
render_403 unless asset_managable?
end
helper_method :can_manage_asset?
def can_manage_asset?
def check_open_vector_service_enabled
render_403 unless OpenVectorEditorService.enabled?
end
helper_method :asset_managable?
def asset_managable?
case @parent
when Step
can_manage_step?(@parent)

View file

@ -6,6 +6,10 @@
<input v-model="sequenceName" class="sci-input-field" type="text" :disabled="readOnly" />
</div>
</span>
<div v-if="oveEnabledDaysLeft <= 30" class="flex items-center">
<i class="mr-1 text-brand-warning sn-icon sn-icon-alert-warning"></i>
<p v-html="i18n.t('open_vector_editor.trial_expiration_warning_html', { count: oveEnabledDaysLeft })" class="mb-0"></p>
</div>
<div class="ove-buttons">
<button v-if="!readOnly" @click="saveAndClose" class="btn btn-light">
<i class="sn-icon sn-icon-save"></i>
@ -31,7 +35,8 @@
fileUrl: { type: String },
fileName: { type: String },
updateUrl: { type: String },
readOnly: { type: Boolean, default: false }
readOnly: { type: Boolean, default: false },
oveEnabledDaysLeft: { type: Number }
},
data() {
return {

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
class OpenVectorEditorService
class << self
def enabled?
ove_enabled_until = ENV.fetch('SCINOTE_OVE_ENABLED_UNTIL', nil)
return false if ove_enabled_until.blank?
DateTime.now.utc.to_date < DateTime.strptime(ove_enabled_until, '%d-%m-%Y').utc.to_date
end
def evaluation_period_left
return 0 unless enabled?
ove_enabled_until = ENV.fetch('SCINOTE_OVE_ENABLED_UNTIL', nil)
return 0 if ove_enabled_until.blank?
(DateTime.strptime(ove_enabled_until, '%d-%m-%Y').utc.to_date - DateTime.now.utc.to_date).to_i
end
end
end

View file

@ -11,15 +11,20 @@
</style>
</head>
<body>
<div id="open-vector-editor" data-behaviour="vue">
<open-vector-editor
file-url="<%= @file_url %>"
file-name="<%= @file_name %>"
update-url="<%= @asset ? gene_sequence_asset_url(@asset) : gene_sequence_assets_url(parent_type: params[:parent_type], parent_id: params[:parent_id]) %>"
:read-only="<%= !can_manage_asset? %>"
/>
</div>
<%= javascript_include_tag 'open_vector_editor' %>
<%= javascript_include_tag 'vue_components_open_vector_editor' %>
<% if @ove_enabled %>
<div id="open-vector-editor" data-behaviour="vue">
<open-vector-editor
file-url="<%= @file_url %>"
file-name="<%= @file_name %>"
update-url="<%= @asset ? gene_sequence_asset_url(@asset) : gene_sequence_assets_url(parent_type: params[:parent_type], parent_id: params[:parent_id]) %>"
:read-only="<%= !asset_managable? %>"
:ove-enabled-days-left="<%= OpenVectorEditorService.evaluation_period_left %>"
/>
</div>
<%= javascript_include_tag 'open_vector_editor' %>
<%= javascript_include_tag 'vue_components_open_vector_editor' %>
<% else %>
<%# TODO render promo %>
<% end %>
</body>
</html>

View file

@ -3640,7 +3640,9 @@ en:
new_sequence: "New sequence"
edit_sequence: "Edit sequence"
default_sequence_name: "New sequence"
trial_expiration_warning_html:
one: "Your Sequence editor trial expires in %{count} day. <a href='mailto:support@scinote.net'> Contact SciNote for more information.</a>"
other: "Your Sequence editor trial expires in %{count} days. <a href='mailto:support@scinote.net'> Contact SciNote for more information.</a>"
pdf_preview:
fit_to_screen: 'Fit to screen'
pages:

View file

@ -19,7 +19,8 @@ module.exports = {
},
colors: {
transparent: 'transparent',
current: 'currentColor'
current: 'currentColor',
'brand-warning': '#f0ad4e'
}
}
},