Bug fix. Previously, all categories were visible from all webs. Now category lists are restricted to the current web.

This commit is contained in:
Jason R. Blevins 2007-02-27 22:27:20 -05:00
parent f208d50032
commit b65a5b8e30
2 changed files with 7 additions and 3 deletions

View file

@ -356,7 +356,7 @@ class WikiController < ApplicationController
end end
def parse_category def parse_category
@categories = WikiReference.list_categories.sort @categories = WikiReference.list_categories(@web).sort
@category = @params['category'] @category = @params['category']
if @category if @category
@set_name = "category '#{@category}'" @set_name = "category '#{@category}'"

View file

@ -46,8 +46,12 @@ class WikiReference < ActiveRecord::Base
names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] } names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] }
end end
def self.list_categories def self.list_categories(web)
query = "SELECT DISTINCT referenced_name FROM wiki_references WHERE link_type = '#{CATEGORY}'" 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'] } connection.select_all(query).map { |row| row['referenced_name'] }
end end