mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-28 23:18:10 +08:00
Fix global activities jsonb field [SCI-3830] (#2030)
* Fix global activities jsonb field * Fix tests
This commit is contained in:
parent
759b3acfe9
commit
b1f9e7f1ca
14 changed files with 1146 additions and 29 deletions
|
|
@ -7,12 +7,12 @@ module GlobalActivitiesHelper
|
|||
|
||||
def generate_activity_content(activity, no_links = false)
|
||||
parameters = {}
|
||||
activity.values[:message_items].each do |key, value|
|
||||
activity.message_items.each do |key, value|
|
||||
parameters[key] =
|
||||
if value.is_a? String
|
||||
value
|
||||
elsif value[:type] == 'Time' # use saved date for printing
|
||||
l(Time.at(value[:value]), format: :full_date)
|
||||
elsif value['type'] == 'Time' # use saved date for printing
|
||||
l(Time.at(value['value']), format: :full_date)
|
||||
else
|
||||
no_links ? generate_name(value) : generate_link(value, activity)
|
||||
end
|
||||
|
|
@ -21,15 +21,15 @@ module GlobalActivitiesHelper
|
|||
I18n.t("global_activities.content.#{activity.type_of}_html", parameters.symbolize_keys),
|
||||
team: activity.team
|
||||
)
|
||||
rescue StandardError => ex
|
||||
Rails.logger.error(ex.message)
|
||||
Rails.logger.error(ex.backtrace.join("\n"))
|
||||
rescue StandardError => e
|
||||
Rails.logger.error(e.message)
|
||||
Rails.logger.error(e.backtrace.join("\n"))
|
||||
I18n.t('global_activities.index.content_generation_error', activity_id: activity.id)
|
||||
end
|
||||
|
||||
def generate_link(message_item, activity)
|
||||
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
||||
return message_item[:value] unless obj
|
||||
obj = message_item['type'].constantize.find_by_id(message_item['id'])
|
||||
return message_item['value'] unless obj
|
||||
|
||||
current_value = generate_name(message_item)
|
||||
team = activity.team
|
||||
|
|
@ -98,10 +98,10 @@ module GlobalActivitiesHelper
|
|||
end
|
||||
|
||||
def generate_name(message_item)
|
||||
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
||||
return message_item[:value] unless obj
|
||||
obj = message_item['type'].constantize.find_by_id(message_item['id'])
|
||||
return message_item['value'] unless obj
|
||||
|
||||
value = obj.public_send(message_item[:value_for] || 'name')
|
||||
value = obj.public_send(message_item['value_for'] || 'name')
|
||||
value = I18n.t('global_activities.index.no_name') if value.blank?
|
||||
|
||||
value
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ module ActivityValuesModel
|
|||
# rubocop:enable Style/ClassVars
|
||||
|
||||
included do
|
||||
serialize :values, JsonbHashSerializer
|
||||
after_initialize :init_default_values, if: :new_record?
|
||||
before_create :add_user
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name) %>
|
||||
<% else %>
|
||||
<% name = subject&.name || breadcrumbs[:experiment] %>
|
||||
<% name = subject&.name || breadcrumbs['experiment'] %>
|
||||
<span title="<%= name %>">
|
||||
<%= name&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name) %>
|
||||
<% else %>
|
||||
<% name = subject&.name || breadcrumbs[:my_module] %>
|
||||
<% name = subject&.name || breadcrumbs['my_module'] %>
|
||||
<span title="<%= name %>">
|
||||
<%= name&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name) %>
|
||||
<% else %>
|
||||
<span title="<%= breadcrumbs[:project] %>">
|
||||
<%= breadcrumbs[:project]&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
<span title="<%= breadcrumbs['project'] %>">
|
||||
<%= breadcrumbs['project']&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
<% else %>
|
||||
<div class="ga-breadcrumb">
|
||||
<span class="fas fa-edit"></span>
|
||||
<span title="<%= breadcrumbs[:protocol] %>">
|
||||
<%= breadcrumbs[:protocol]&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
<span title="<%= breadcrumbs['protocol'] %>">
|
||||
<%= breadcrumbs['protocol']&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name) %>
|
||||
<% else %>
|
||||
<span title="<%= breadcrumbs[:report] %>">
|
||||
<%= breadcrumbs[:report]&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
<span title="<%= breadcrumbs['report'] %>">
|
||||
<%= breadcrumbs['report']&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name) %>
|
||||
<% else %>
|
||||
<span title="<%= breadcrumbs[:repository] %>">
|
||||
<%= breadcrumbs[:repository]&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
<span title="<%= breadcrumbs['repository'] %>">
|
||||
<%= breadcrumbs['repository']&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name) %>
|
||||
<% else %>
|
||||
<% name = subject&.name || breadcrumbs[:result] %>
|
||||
<% name = subject&.name || breadcrumbs['result'] %>
|
||||
<span title="<%= name %>">
|
||||
<%= name&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||
title: subject.name %>
|
||||
<% else %>
|
||||
<span title="<%= breadcrumbs[:team] %>">
|
||||
<%= breadcrumbs[:team]&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
<span title="<%= breadcrumbs['team'] %>">
|
||||
<%= breadcrumbs['team']&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ConvertActivitiesJsonToJsonb < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :activities, :values, 'jsonb USING CAST(values AS jsonb)'
|
||||
ActiveRecord::Base.connection.execute("
|
||||
UPDATE activities SET values = REGEXP_REPLACE(values::text, '^\"||\"$||\\\\', '', 'g')::jsonb
|
||||
")
|
||||
end
|
||||
end
|
||||
1108
db/schema.rb
Normal file
1108
db/schema.rb
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -65,7 +65,7 @@ describe Activity, type: :model do
|
|||
it 'adds user to message items' do
|
||||
activity.save
|
||||
|
||||
expect(activity.message_items).to include(user: be_an(Hash))
|
||||
expect(activity.message_items).to include('user' => be_an(Hash))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -73,14 +73,14 @@ describe Activity, type: :model do
|
|||
context 'when do not have subject' do
|
||||
it 'does not add breadcrumbs to activity' do
|
||||
expect { old_activity.generate_breadcrumbs }
|
||||
.not_to(change { activity.values[:breadcrumbs] })
|
||||
.not_to(change { activity.values['breadcrumbs'] })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when have subject' do
|
||||
it 'adds breadcrumbs to activity' do
|
||||
expect { activity.generate_breadcrumbs }
|
||||
.to(change { activity.values[:breadcrumbs] })
|
||||
.to(change { activity.values['breadcrumbs'] })
|
||||
end
|
||||
|
||||
context 'when subject is a my_module' do
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ describe Activities::CreateActivityService do
|
|||
a = service_call.activity
|
||||
|
||||
expect(a.message_items[:project].keys)
|
||||
.to contain_exactly('type', 'value', 'id', 'value_for')
|
||||
.to contain_exactly(:type, :value, :id, :value_for)
|
||||
end
|
||||
|
||||
it 'adds object project to message items as hash' do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue