From 7156fab3e29037dc9675be2b1bbc2d2a816203a7 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 30 Sep 2016 14:42:07 +0800 Subject: [PATCH] fix topic controller bugs --- app/controllers/topics_controller.rb | 2 +- app/models/topic.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index f909626a..ce430f43 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -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? diff --git a/app/models/topic.rb b/app/models/topic.rb index 62f81cec..7d83ecac 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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