mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
Fix subject references for repository row activities [SCI-6906] (#4203)
This commit is contained in:
parent
dce755b294
commit
26820b9abb
18 changed files with 96 additions and 37 deletions
|
@ -405,7 +405,7 @@ class RepositoryRowsController < ApplicationController
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: type_of,
|
.call(activity_type: type_of,
|
||||||
owner: current_user,
|
owner: current_user,
|
||||||
subject: @repository,
|
subject: repository_row,
|
||||||
team: current_team,
|
team: current_team,
|
||||||
message_items: {
|
message_items: {
|
||||||
repository_row: repository_row.id,
|
repository_row: repository_row.id,
|
||||||
|
|
|
@ -20,37 +20,6 @@ module SearchableByNameModel
|
||||||
|
|
||||||
sql_q.limit(Constants::SEARCH_LIMIT)
|
sql_q.limit(Constants::SEARCH_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.filter_by_teams(teams = [])
|
|
||||||
return self if teams.blank?
|
|
||||||
|
|
||||||
if column_names.include? 'team_id'
|
|
||||||
where(team_id: teams)
|
|
||||||
else
|
|
||||||
valid_subjects = Extends::ACTIVITY_SUBJECT_CHILDREN
|
|
||||||
parent_array = [to_s.underscore]
|
|
||||||
find_parent = true
|
|
||||||
# Trying to build parent array
|
|
||||||
while find_parent
|
|
||||||
possible_parent = valid_subjects.find { |_sub, ch| ((ch || []).include? parent_array[-1].pluralize.to_sym) }
|
|
||||||
possible_parent = { Project: nil } if parent_array[-1] == 'experiment'
|
|
||||||
if possible_parent
|
|
||||||
parent_array.push(possible_parent.flatten[0].to_s.underscore)
|
|
||||||
else
|
|
||||||
find_parent = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
parent_array.shift
|
|
||||||
# Now we will go from parent to child direction
|
|
||||||
last_parent = parent_array.reverse!.shift
|
|
||||||
query = last_parent.to_s.camelize.constantize.where(team_id: teams)
|
|
||||||
parent_array.each do |child|
|
|
||||||
query = child.to_s.camelize.constantize.where("#{last_parent}_id" => query)
|
|
||||||
last_parent = child
|
|
||||||
end
|
|
||||||
where("#{last_parent}_id" => query)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/BlockLength
|
# rubocop:enable Metrics/BlockLength
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,6 +86,12 @@ class Experiment < ApplicationRecord
|
||||||
.where(project: Project.viewable_by_user(user, teams))
|
.where(project: Project.viewable_by_user(user, teams))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
return self if teams.blank?
|
||||||
|
|
||||||
|
joins(:project).where(project: { team: teams })
|
||||||
|
end
|
||||||
|
|
||||||
def archived_branch?
|
def archived_branch?
|
||||||
archived? || project.archived?
|
archived? || project.archived?
|
||||||
end
|
end
|
||||||
|
|
|
@ -117,6 +117,12 @@ class MyModule < ApplicationRecord
|
||||||
.where(experiment: Experiment.viewable_by_user(user, teams))
|
.where(experiment: Experiment.viewable_by_user(user, teams))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
return self if teams.blank?
|
||||||
|
|
||||||
|
joins(experiment: :project).where(experiment: { projects: { team: teams } })
|
||||||
|
end
|
||||||
|
|
||||||
def navigable?
|
def navigable?
|
||||||
!experiment.archived? && experiment.navigable?
|
!experiment.archived? && experiment.navigable?
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,6 +104,10 @@ class Project < ApplicationRecord
|
||||||
.distinct
|
.distinct
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
teams.blank? ? self : where(team: teams)
|
||||||
|
end
|
||||||
|
|
||||||
def permission_parent
|
def permission_parent
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,6 +69,10 @@ class ProjectFolder < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
teams.blank? ? self : where(team: teams)
|
||||||
|
end
|
||||||
|
|
||||||
def parent_folders
|
def parent_folders
|
||||||
outer_folders_sql =
|
outer_folders_sql =
|
||||||
'WITH RECURSIVE outer_project_folders(id, parent_folder_id, selected_folders_ids) AS (
|
'WITH RECURSIVE outer_project_folders(id, parent_folder_id, selected_folders_ids) AS (
|
||||||
|
|
|
@ -202,6 +202,10 @@ class Protocol < ApplicationRecord
|
||||||
user_id: user.id))
|
user_id: user.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
teams.blank? ? self : where(team: teams)
|
||||||
|
end
|
||||||
|
|
||||||
def insert_step(step, position)
|
def insert_step(step, position)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
steps.where('position >= ?', position).desc_order.each do |s|
|
steps.where('position >= ?', position).desc_order.each do |s|
|
||||||
|
|
|
@ -85,6 +85,10 @@ class Report < ApplicationRecord
|
||||||
where(project: Project.viewable_by_user(user, teams))
|
where(project: Project.viewable_by_user(user, teams))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
teams.blank? ? self : where(team: teams)
|
||||||
|
end
|
||||||
|
|
||||||
def root_elements
|
def root_elements
|
||||||
report_elements.active.where(parent: nil).order(:position)
|
report_elements.active.where(parent: nil).order(:position)
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,10 @@ class Repository < RepositoryBase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
teams.blank? ? self : where(team: teams)
|
||||||
|
end
|
||||||
|
|
||||||
def default_table_state
|
def default_table_state
|
||||||
Constants::REPOSITORY_TABLE_DEFAULT_STATE
|
Constants::REPOSITORY_TABLE_DEFAULT_STATE
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,12 @@ class RepositoryRow < ApplicationRecord
|
||||||
where(repository: Repository.viewable_by_user(user, teams))
|
where(repository: Repository.viewable_by_user(user, teams))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
return self if teams.blank?
|
||||||
|
|
||||||
|
joins(:repository).where(repository: { team: teams })
|
||||||
|
end
|
||||||
|
|
||||||
def self.name_like(query)
|
def self.name_like(query)
|
||||||
where('repository_rows.name ILIKE ?', "%#{query}%")
|
where('repository_rows.name ILIKE ?', "%#{query}%")
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,6 +55,12 @@ class Result < ApplicationRecord
|
||||||
where(my_module: MyModule.viewable_by_user(user, teams))
|
where(my_module: MyModule.viewable_by_user(user, teams))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
return self if teams.blank?
|
||||||
|
|
||||||
|
joins(my_module: { experiment: :project }).where(my_module: { experiments: { projects: { team: teams } } })
|
||||||
|
end
|
||||||
|
|
||||||
def navigable?
|
def navigable?
|
||||||
!my_module.archived? && my_module.navigable?
|
!my_module.archived? && my_module.navigable?
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,6 +72,13 @@ class Step < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_by_teams(teams = [])
|
||||||
|
return self if teams.blank?
|
||||||
|
|
||||||
|
joins(protocol: { my_module: { experiment: :project } })
|
||||||
|
.where(protocol: { my_modules: { experiments: { projects: { team: teams } } } })
|
||||||
|
end
|
||||||
|
|
||||||
def default_view_state
|
def default_view_state
|
||||||
{ 'assets' => { 'sort' => 'new' } }
|
{ 'assets' => { 'sort' => 'new' } }
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,7 +68,7 @@ module ReportActions
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: :edit_item_inventory,
|
.call(activity_type: :edit_item_inventory,
|
||||||
owner: @user,
|
owner: @user,
|
||||||
subject: @repository,
|
subject: @repository_row,
|
||||||
team: @team,
|
team: @team,
|
||||||
message_items: {
|
message_items: {
|
||||||
repository_row: @repository_row.id,
|
repository_row: @repository_row.id,
|
||||||
|
|
|
@ -52,7 +52,7 @@ module RepositoryActions
|
||||||
Activities::CreateActivityService
|
Activities::CreateActivityService
|
||||||
.call(activity_type: type,
|
.call(activity_type: type,
|
||||||
owner: @user,
|
owner: @user,
|
||||||
subject: row.repository,
|
subject: row,
|
||||||
team: @team,
|
team: @team,
|
||||||
message_items: {
|
message_items: {
|
||||||
repository_row: row.id
|
repository_row: row.id
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<%= render partial: "global_activities/references/team.html.erb",
|
||||||
|
locals: { team: team, subject: team, breadcrumbs: breadcrumbs, values: values, type_of: type_of } %>
|
||||||
|
<div class="ga-breadcrumb">
|
||||||
|
<span class="fas fa-list-alt"></span>
|
||||||
|
<% if subject %>
|
||||||
|
<%= route_to_other_team(repository_path(subject.repository.id, team: subject.repository.team.id),
|
||||||
|
team,
|
||||||
|
subject.repository.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
|
||||||
|
title: subject.repository.name) %>
|
||||||
|
<% else %>
|
||||||
|
<span title="<%= breadcrumbs['repository'] %>">
|
||||||
|
<%= breadcrumbs['repository']&.truncate(Constants::NAME_TRUNCATION_LENGTH) %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
|
@ -201,7 +201,7 @@ class Extends
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
ACTIVITY_SUBJECT_CHILDREN = {
|
ACTIVITY_SUBJECT_CHILDREN = {
|
||||||
repository: [:repository_rows],
|
repository_base: [:repository_rows],
|
||||||
repository_row: nil,
|
repository_row: nil,
|
||||||
report: nil,
|
report: nil,
|
||||||
project: nil,
|
project: nil,
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ChangeSubjectOnRepositoryRowActivities < ActiveRecord::Migration[6.1]
|
||||||
|
def up
|
||||||
|
execute(
|
||||||
|
"UPDATE activities " \
|
||||||
|
"SET subject_id = (values -> 'message_items' -> 'repository_row' ->> 'id')::bigint, "\
|
||||||
|
"subject_type = 'RepositoryRow' " \
|
||||||
|
"WHERE \"activities\".\"subject_type\" = 'RepositoryBase' "\
|
||||||
|
"AND (values -> 'message_items' -> 'repository_row' IS NOT NULL);"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
Activity.where(subject_type: 'RepositoryRow').find_each do |activity|
|
||||||
|
next if activity.subject.blank?
|
||||||
|
|
||||||
|
activity.update_columns(subject_type: 'RepositoryBase', subject_id: activity.subject.repository_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -8511,8 +8511,11 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20220321122111'),
|
('20220321122111'),
|
||||||
('20220325101011'),
|
('20220325101011'),
|
||||||
('20220328164215'),
|
('20220328164215'),
|
||||||
('20220530144300');
|
|
||||||
('20220414095100'),
|
('20220414095100'),
|
||||||
('20220414143955');
|
('20220414143955'),
|
||||||
|
('20220429083335'),
|
||||||
|
('20220530144300'),
|
||||||
|
('20220602120714'),
|
||||||
|
('20220705091621');
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue