From b65a5b8e307fa272bec2948fa8caa663fb617c75 Mon Sep 17 00:00:00 2001 From: "Jason R. Blevins" Date: Tue, 27 Feb 2007 22:27:20 -0500 Subject: [PATCH] Bug fix. Previously, all categories were visible from all webs. Now category lists are restricted to the current web. --- app/controllers/wiki_controller.rb | 2 +- app/models/wiki_reference.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 181ed53c..a5cb8b99 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -356,7 +356,7 @@ class WikiController < ApplicationController end def parse_category - @categories = WikiReference.list_categories.sort + @categories = WikiReference.list_categories(@web).sort @category = @params['category'] if @category @set_name = "category '#{@category}'" diff --git a/app/models/wiki_reference.rb b/app/models/wiki_reference.rb index 3d1eddd7..0616d173 100644 --- a/app/models/wiki_reference.rb +++ b/app/models/wiki_reference.rb @@ -46,8 +46,12 @@ class WikiReference < ActiveRecord::Base names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] } end - def self.list_categories - query = "SELECT DISTINCT referenced_name FROM wiki_references WHERE link_type = '#{CATEGORY}'" + def self.list_categories(web) + query = "SELECT DISTINCT wiki_references.referenced_name " + + "FROM wiki_references LEFT OUTER JOIN pages " + + "ON wiki_references.page_id = pages.id " + + "WHERE wiki_references.link_type = '#{CATEGORY}' " + + "AND pages.web_id = #{web.id}" connection.select_all(query).map { |row| row['referenced_name'] } end