Add site setting to disable User Directory, include restricted info

This commit is contained in:
Robin Ward 2015-03-26 11:26:19 -04:00
parent e6ba3344fa
commit 2cc5858163
6 changed files with 21 additions and 2 deletions

View file

@ -22,7 +22,9 @@
</li> </li>
{{/if}} {{/if}}
{{#if siteSettings.enable_user_directory}}
<li>{{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}</li> <li>{{#link-to 'users'}}{{i18n "directory.title"}}{{/link-to}}</li>
{{/if}}
{{plugin-outlet "site-map-links"}} {{plugin-outlet "site-map-links"}}

View file

@ -2,6 +2,8 @@ class DirectoryItemsController < ApplicationController
PAGE_SIZE = 50 PAGE_SIZE = 50
def index def index
raise Discourse::InvalidAccess.new(:enable_user_directory) unless SiteSetting.enable_user_directory?
period = params.require(:period) period = params.require(:period)
period_type = DirectoryItem.period_types[period.to_sym] period_type = DirectoryItem.period_types[period.to_sym]
raise Discourse::InvalidAccess.new(:period_type) unless period_type raise Discourse::InvalidAccess.new(:period_type) unless period_type

View file

@ -24,6 +24,10 @@ class DirectoryItem < ActiveRecord::Base
end end
def self.refresh_period!(period_type) def self.refresh_period!(period_type)
# Don't calculate it if the user directory is disabled
return unless SiteSetting.enable_user_directory?
since = case period_type since = case period_type
when :daily then 1.day.ago when :daily then 1.day.ago
when :weekly then 1.week.ago when :weekly then 1.week.ago
@ -57,7 +61,6 @@ class DirectoryItem < ActiveRecord::Base
AND COALESCE(t.archetype, 'regular') = 'regular' AND COALESCE(t.archetype, 'regular') = 'regular'
AND p.deleted_at IS NULL AND p.deleted_at IS NULL
AND (NOT (COALESCE(p.hidden, false))) AND (NOT (COALESCE(p.hidden, false)))
AND (NOT COALESCE(c.read_restricted, false))
AND COALESCE(p.post_type, :regular_post_type) != :moderator_action AND COALESCE(p.post_type, :regular_post_type) != :moderator_action
AND u.id > 0 AND u.id > 0
GROUP BY u.id", GROUP BY u.id",

View file

@ -1086,6 +1086,7 @@ en:
max_daily_gravatar_crawls: "Maximum number of times Discourse will check Gravatar for custom avatars in a day" max_daily_gravatar_crawls: "Maximum number of times Discourse will check Gravatar for custom avatars in a day"
public_user_custom_fields: "A whitelist of custom fields for a user that can be shown publicly." public_user_custom_fields: "A whitelist of custom fields for a user that can be shown publicly."
staff_user_custom_fields: "A whitelist of custom fields for a user that can be shown to staff." staff_user_custom_fields: "A whitelist of custom fields for a user that can be shown to staff."
enable_user_directory: "Provide a directory of users for browsing"
allow_profile_backgrounds: "Allow users to upload profile backgrounds." allow_profile_backgrounds: "Allow users to upload profile backgrounds."

View file

@ -303,6 +303,9 @@ users:
staff_user_custom_fields: staff_user_custom_fields:
type: list type: list
default: '' default: ''
enable_user_directory:
client: true
default: true
posting: posting:
min_post_length: min_post_length:

View file

@ -11,6 +11,7 @@ describe DirectoryItemsController do
response.should_not be_success response.should_not be_success
end end
context "without data" do context "without data" do
context "and a logged in user" do context "and a logged in user" do
@ -42,5 +43,12 @@ describe DirectoryItemsController do
json['total_rows_directory_items'].should be_present json['total_rows_directory_items'].should be_present
json['load_more_directory_items'].should be_present json['load_more_directory_items'].should be_present
end end
it "fails when the directory is disabled" do
SiteSetting.enable_user_directory = false
xhr :get, :index, period: 'all'
response.should_not be_success
end
end end
end end