mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Multiple small bugfixes [SCI-5494]
This commit is contained in:
parent
784ec5583a
commit
7d89088b14
7 changed files with 18 additions and 45 deletions
|
@ -11,7 +11,10 @@ module ActiveStorage
|
|||
private
|
||||
|
||||
def check_read_permissions
|
||||
case @blob.attachments.first.record_type
|
||||
attachment = @blob.attachments.take
|
||||
return render_404 if attachment.blank?
|
||||
|
||||
case attachment.record_type
|
||||
when 'Asset'
|
||||
check_asset_read_permissions
|
||||
when 'TinyMceAsset'
|
||||
|
|
|
@ -73,6 +73,8 @@ class TeamRepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def teams_to_update
|
||||
return [] if update_params[:permission_changes].blank?
|
||||
|
||||
teams_to_update = JSON.parse(update_params[:permission_changes]).keys.map(&:to_i).to_a &
|
||||
update_params[:share_team_ids]&.map(&:to_i).to_a
|
||||
wp = update_params[:write_permissions]&.map(&:to_i)
|
||||
|
|
|
@ -12,7 +12,7 @@ module GlobalActivitiesHelper
|
|||
if value.is_a? String
|
||||
value
|
||||
elsif value['type'] == 'Time' # use saved date for printing
|
||||
l(Time.at(value['value']), format: :full)
|
||||
I18n.l(Time.zone.at(value['value']), format: :full)
|
||||
else
|
||||
no_links ? generate_name(value) : generate_link(value, activity)
|
||||
end
|
||||
|
|
|
@ -43,17 +43,4 @@ class Tag < ApplicationRecord
|
|||
.offset((page - 1) * Constants::SEARCH_LIMIT)
|
||||
end
|
||||
end
|
||||
|
||||
def clone_to_project_or_return_existing(project)
|
||||
tag = Tag.find_by(project: project, name: name, color: color)
|
||||
return tag if tag
|
||||
|
||||
Tag.create(
|
||||
name: name,
|
||||
color: color,
|
||||
created_by: created_by,
|
||||
last_modified_by: last_modified_by,
|
||||
project: project
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ class ActivitiesService
|
|||
subjects_with_children = load_subjects_children(filters[:subjects])
|
||||
if subjects_with_children['Project']
|
||||
query = query.where('project_id IN (?)', subjects_with_children['Project'])
|
||||
subjects_with_children.except!('Project')
|
||||
subjects_with_children = subjects_with_children.except('Project')
|
||||
end
|
||||
where_condition = subjects_with_children.to_h.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR ')
|
||||
where_arguments = subjects_with_children.to_h.flatten
|
||||
|
|
|
@ -20,15 +20,19 @@ module Experiments
|
|||
ActiveRecord::Base.transaction do
|
||||
@exp.project = @project
|
||||
|
||||
@exp.my_modules.each do |m|
|
||||
new_tags = m.tags.map do |t|
|
||||
t.clone_to_project_or_return_existing(@project)
|
||||
@exp.my_modules.each do |my_module|
|
||||
new_tags = []
|
||||
my_module.tags.each do |tag|
|
||||
new_tag = @project.tags.where.not(id: new_tags).find_by(name: tag.name, color: tag.color)
|
||||
new_tag ||=
|
||||
@project.tags.create!(name: tag.name, color: tag.color, created_by: @user, last_modified_by: @user)
|
||||
new_tags << new_tag
|
||||
end
|
||||
m.my_module_tags.delete_all
|
||||
m.tags = new_tags
|
||||
my_module.tags.destroy_all
|
||||
my_module.tags = new_tags
|
||||
end
|
||||
|
||||
raise ActiveRecord::Rollback unless @exp.save
|
||||
@exp.save!
|
||||
end
|
||||
|
||||
@errors.merge!(@exp.errors.to_hash) unless @exp.valid?
|
||||
|
|
|
@ -46,27 +46,4 @@ describe Tag, type: :model do
|
|||
it { is_expected.to validate_presence_of :project }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.clone_to_project_or_return_existing' do
|
||||
let(:project) { create :project }
|
||||
let(:tag) { create :tag }
|
||||
|
||||
context 'when tag does not exits' do
|
||||
it 'does create new tag for project' do
|
||||
expect do
|
||||
tag.clone_to_project_or_return_existing(project)
|
||||
end.to(change { Tag.where(project_id: project.id).count })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when tag already exists' do
|
||||
it 'return existing tag for project' do
|
||||
Tag.create(name: tag.name, color: tag.color, project: project)
|
||||
|
||||
expect do
|
||||
tag.clone_to_project_or_return_existing(project)
|
||||
end.to_not(change { Tag.where(project_id: project.id).count })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue