mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 09:23:58 +08:00
Merge pull request #7865 from artoscinote/ma_SCI_11057
Simplify and fix shareable scope [SCI-11057]
This commit is contained in:
commit
926a9ee6d4
1 changed files with 17 additions and 15 deletions
|
@ -27,21 +27,23 @@ module Shareable
|
||||||
end
|
end
|
||||||
|
|
||||||
scope :viewable_by_user, lambda { |user, teams = user.current_team|
|
scope :viewable_by_user, lambda { |user, teams = user.current_team|
|
||||||
readable = readable_by_user(user).left_outer_joins(:team_shared_objects)
|
readable_ids = readable_by_user(user).pluck(:id)
|
||||||
readable
|
shared_with_team_ids = joins(:team_shared_objects, :team).where(team_shared_objects: { team: teams }).pluck(:id)
|
||||||
.where(team: teams)
|
globally_shared_ids =
|
||||||
.or(model.where(team_shared_objects: { team: teams }))
|
if column_names.include?('permission_level')
|
||||||
.or(model.where(if column_names.include?('permission_level')
|
joins(:team).where(
|
||||||
{
|
{
|
||||||
permission_level: [
|
permission_level: [
|
||||||
Extends::SHARED_OBJECTS_PERMISSION_LEVELS[:shared_read],
|
Extends::SHARED_OBJECTS_PERMISSION_LEVELS[:shared_read],
|
||||||
Extends::SHARED_OBJECTS_PERMISSION_LEVELS[:shared_write]
|
Extends::SHARED_OBJECTS_PERMISSION_LEVELS[:shared_write]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
else
|
).pluck(:id)
|
||||||
{}
|
else
|
||||||
end).where.not(team: teams))
|
none.pluck(:id)
|
||||||
.distinct
|
end
|
||||||
|
|
||||||
|
where(id: (readable_ids + shared_with_team_ids + globally_shared_ids).uniq)
|
||||||
}
|
}
|
||||||
rescue ActiveRecord::NoDatabaseError,
|
rescue ActiveRecord::NoDatabaseError,
|
||||||
ActiveRecord::ConnectionNotEstablished,
|
ActiveRecord::ConnectionNotEstablished,
|
||||||
|
|
Loading…
Reference in a new issue