From 8551d821a0e3fbb8049fb61b6196b09dd26eace5 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 22 Dec 2016 14:14:03 +0800 Subject: [PATCH] FEATURE: Add site setting to disable group directory. --- .../javascripts/discourse/widgets/hamburger-menu.js.es6 | 4 +++- app/controllers/groups_controller.rb | 4 ++++ config/locales/server.en.yml | 1 + config/site_settings.yml | 5 +++++ spec/integration/groups_spec.rb | 9 +++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 b/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 index c1ad1961c79..016d14c4fb4 100644 --- a/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/hamburger-menu.js.es6 @@ -103,7 +103,9 @@ export default createWidget('hamburger-menu', { links.push({ route: 'users', className: 'user-directory-link', label: 'directory.title' }); } - links.push({ route: 'groups', className: 'groups-link', label: 'groups.index.title' }); + if (!this.siteSettings.show_group_directory) { + links.push({ route: 'groups', className: 'groups-link', label: 'groups.index.title' }); + } if (this.siteSettings.tagging_enabled) { links.push({ route: 'tags', label: 'tagging.tags' }); diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 2cb0d473297..28c454be0e0 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -11,6 +11,10 @@ class GroupsController < ApplicationController skip_before_filter :preload_json, :check_xhr, only: [:posts_feed, :mentions_feed] def index + unless SiteSetting.enable_group_directory? + raise Discourse::InvalidAccess.new(:enable_group_directory) + end + page_size = 30 page = params[:page]&.to_i || 0 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index c6c4ef390bb..ac3cc342ff0 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1315,6 +1315,7 @@ en: 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." enable_user_directory: "Provide a directory of users for browsing" + enable_group_directory: "Provide a directory of groups for browsing" allow_anonymous_posting: "Allow users to switch to anonymous mode" anonymous_posting_min_trust_level: "Minimum trust level required to enable anonymous posting" anonymous_account_duration_minutes: "To protect anonymity create a new anonymous account every N minutes for each user. Example: if set to 600, as soon as 600 minutes elapse from last post AND user switches to anon, a new anonymous account is created." diff --git a/config/site_settings.yml b/config/site_settings.yml index 2c3fd145b5a..dd9e472ae61 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -411,6 +411,11 @@ users: default: false client: true +groups: + enable_group_directory: + client: true + default: true + posting: min_post_length: client: true diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb index 57cab61253d..a3606490d3f 100644 --- a/spec/integration/groups_spec.rb +++ b/spec/integration/groups_spec.rb @@ -14,6 +14,15 @@ describe "Groups" do group.update_attributes!(automatic: true, visible: true) end + context 'when group directory is disabled' do + site_setting(:enable_group_directory, false) + + it 'should deny access' do + get "/groups.json" + expect(response).to be_forbidden + end + end + it 'should return the right response' do get "/groups.json"