use Topic.relatives scope to get all relatives
This commit is contained in:
parent
7de89cfa0f
commit
e761e1693c
2 changed files with 7 additions and 3 deletions
|
@ -24,10 +24,8 @@ class TopicsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id, current_user)).to_a).concat(policy_scope(Topic.relatives2(@topic.id, current_user)).to_a)
|
||||
@alltopics = [@topic].concat(policy_scope(Topic.relatives(@topic.id, current_user)).to_a)
|
||||
@allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
|
||||
puts @alltopics.length
|
||||
puts @allsynapses.length
|
||||
@allcreators = @alltopics.map(&:user).uniq
|
||||
@allcreators += @allsynapses.map(&:user).uniq
|
||||
|
||||
|
|
|
@ -42,6 +42,12 @@ class Topic < ActiveRecord::Base
|
|||
topics1 + topics2
|
||||
end
|
||||
|
||||
scope :relatives, ->(topic_id = nil, user = nil) {
|
||||
synapses = Pundit.policy_scope(user, Synapse.where(node1_id: topic_id)).pluck(:node2_id)
|
||||
synapses += Pundit.policy_scope(user, Synapse.where(node2_id: topic_id)).pluck(:node1_id)
|
||||
where(id: synapses.uniq)
|
||||
}
|
||||
|
||||
scope :relatives1, ->(topic_id = nil, user = nil) {
|
||||
visible = %w(public commons)
|
||||
permission = 'synapses.permission IN (?)'
|
||||
|
|
Loading…
Reference in a new issue