fix topic controller bugs
This commit is contained in:
parent
97c118a20b
commit
7156fab3e2
2 changed files with 6 additions and 6 deletions
|
@ -88,7 +88,7 @@ class TopicsController < ApplicationController
|
|||
|
||||
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||
|
||||
alltopics = policy_scope(Topic.relatives(@topic.id)).to_a
|
||||
alltopics = policy_scope(Topic.relatives(@topic.id, current_user)).to_a
|
||||
alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i } if params[:metacode].present?
|
||||
alltopics.delete_if do |topic|
|
||||
!topicsAlreadyHas.index(topic.id.to_s).nil?
|
||||
|
|
|
@ -36,19 +36,19 @@ class Topic < ApplicationRecord
|
|||
validates_attachment_content_type :audio, content_type: /\Aaudio\/.*\Z/
|
||||
|
||||
def synapses
|
||||
synapses1 + synapses2
|
||||
synapses1.or(synapses2)
|
||||
end
|
||||
|
||||
def relatives
|
||||
topics1 + topics2
|
||||
topics1.or(topics2)
|
||||
end
|
||||
|
||||
scope :relatives, ->(topic_id = nil, user = nil) {
|
||||
# should only see topics through *visible* synapses
|
||||
# e.g. Topic A (commons) -> synapse (private) -> Topic B (commons) must be filtered out
|
||||
synapses = Pundit.policy_scope(user, Synapse.where(topic1_id: topic_id)).pluck(:topic2_id)
|
||||
synapses += Pundit.policy_scope(user, Synapse.where(topic2_id: topic_id)).pluck(:topic1_id)
|
||||
where(id: synapses.uniq)
|
||||
topic_ids = Pundit.policy_scope(user, Synapse.where(topic1_id: topic_id)).pluck(:topic2_id)
|
||||
topic_ids += Pundit.policy_scope(user, Synapse.where(topic2_id: topic_id)).pluck(:topic1_id)
|
||||
where(id: topic_ids.uniq)
|
||||
}
|
||||
|
||||
delegate :name, to: :user, prefix: true
|
||||
|
|
Loading…
Reference in a new issue