]> cat aescling's git repositories - mastodon.git/commitdiff
Add instance-wide setting to disable profile directory (#9497)
authorThibG <thib@sitedethib.com>
Tue, 11 Dec 2018 18:18:29 +0000 (19:18 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 11 Dec 2018 18:18:29 +0000 (19:18 +0100)
* Add instance-wide setting to disable profile directory

Fixes #9496

When the profile directory is disabled:
- The “discoverable” setting is hidden from users
- The “profile directory” link is not shown on public pages
- /explore returns 404

* Move Setting.profile_directory check to a before_action filter

app/controllers/admin/dashboard_controller.rb
app/controllers/admin/settings_controller.rb
app/controllers/directories_controller.rb
app/models/form/admin_settings.rb
app/views/admin/dashboard/index.html.haml
app/views/admin/settings/edit.html.haml
app/views/layouts/public.html.haml
app/views/settings/profiles/show.html.haml
config/locales/en.yml
config/settings.yml

index 7be753c9b345f69e9feb4125fc0c992f82b5b054..bb923c18594c78fee477a00eee9238466e715a4e 100644 (file)
@@ -28,6 +28,7 @@ module Admin
       @pam_enabled           = ENV['PAM_ENABLED'] == 'true'
       @hidden_service        = ENV['ALLOW_ACCESS_TO_HIDDEN_SERVICE'] == 'true'
       @trending_hashtags     = TrendingTags.get(7)
+      @profile_directory     = Setting.profile_directory
     end
 
     private
index d9f2614899fc639cdad5c635b621eb55963f34d8..4a049fc235638a649dad3f4045e6c2a521f36b84 100644 (file)
@@ -26,6 +26,7 @@ module Admin
       show_known_fediverse_at_about_page
       preview_sensitive_media
       custom_css
+      profile_directory
     ).freeze
 
     BOOLEAN_SETTINGS = %w(
@@ -37,6 +38,7 @@ module Admin
       peers_api_enabled
       show_known_fediverse_at_about_page
       preview_sensitive_media
+      profile_directory
     ).freeze
 
     UPLOAD_SETTINGS = %w(
index 265fd5fab28c1d634729751cafbc6074d9f314b9..b8565af4b50f53cfd1878695687f364f63d9438b 100644 (file)
@@ -3,6 +3,7 @@
 class DirectoriesController < ApplicationController
   layout 'public'
 
+  before_action :check_enabled
   before_action :set_instance_presenter
   before_action :set_tag, only: :show
   before_action :set_tags
@@ -18,6 +19,10 @@ class DirectoriesController < ApplicationController
 
   private
 
+  def check_enabled
+    return not_found unless Setting.profile_directory
+  end
+
   def set_tag
     @tag = Tag.discoverable.find_by!(name: params[:id].downcase)
   end
index 9fef7da97fc87fa165039f377152915a360b353b..eca71bf6214f466efb2782c5b12a04fd19a985f0 100644 (file)
@@ -44,6 +44,8 @@ class Form::AdminSettings
     :preview_sensitive_media=,
     :custom_css,
     :custom_css=,
+    :profile_directory,
+    :profile_directory=,
     to: Setting
   )
 end
index 1996eef4d23ac436f43080797f70b3314435f131..fa3d70e9eddd4b45d5bd53ffedc55926c595f1e0 100644 (file)
             %span.pull-right.positive-hint= fa_icon 'check fw'
           - else
             %span.pull-right.negative-hint= fa_icon 'times fw'
+        %li
+          = link_to t('admin.dashboard.feature_profile_directory'), edit_admin_settings_path
+          - if @profile_directory
+            %span.pull-right.positive-hint= fa_icon 'check fw'
+          - else
+            %span.pull-right.negative-hint= fa_icon 'times fw'
         %li
           = link_to t('admin.dashboard.feature_relay'), admin_relays_path
           - if @relay_enabled
index 04b1a67540f64acb18db8214ae9db84ddf39579a..7afa9ec3718df12ab521d70a448aeb0067595b01 100644 (file)
@@ -62,6 +62,9 @@
   .fields-group
     = f.input :preview_sensitive_media, as: :boolean, wrapper: :with_label, label: t('admin.settings.preview_sensitive_media.title'), hint: t('admin.settings.preview_sensitive_media.desc_html')
 
+  .fields-group
+    = f.input :profile_directory, as: :boolean, wrapper: :with_label, label: t('admin.settings.profile_directory.title'), hint: t('admin.settings.profile_directory.desc_html')
+
   %hr.spacer/
 
   .fields-group
index 831c7f012eaf280419453e677257290cebc2c530..93ed12f18900b4d9c7c47e8783c787133f4e41f4 100644 (file)
@@ -9,7 +9,8 @@
           = link_to root_url, class: 'brand' do
             = image_tag asset_pack_path('logo_full.svg'), alt: 'Mastodon'
 
-          = link_to t('directories.directory'), explore_path, class: 'nav-link'
+          - if Setting.profile_directory
+            = link_to t('directories.directory'), explore_path, class: 'nav-link'
           = link_to t('about.about_this'), about_more_path, class: 'nav-link'
           = link_to t('about.apps'), 'https://joinmastodon.org/apps', class: 'nav-link'
         .nav-center
index fa3869f6f988ba872e2687f8d7484ae0f0769c1b..eb232dc57b535b5d7ad8e90d4ba1c55f31f3d313 100644 (file)
@@ -26,8 +26,9 @@
   .fields-group
     = f.input :bot, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.bot')
 
-  .fields-group
-    = f.input :discoverable, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.discoverable_html', min_followers: Account::MIN_FOLLOWERS_DISCOVERY, path: explore_path)
+  - if Setting.profile_directory
+    .fields-group
+      = f.input :discoverable, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.discoverable_html', min_followers: Account::MIN_FOLLOWERS_DISCOVERY, path: explore_path)
 
   %hr.spacer/
 
index 243b513fd653dedfd426442b48354e56c200c9c1..314787acd5055ed23ff630a65b1771ae64c82afa 100644 (file)
@@ -229,6 +229,7 @@ en:
       config: Configuration
       feature_deletions: Account deletions
       feature_invites: Invite links
+      feature_profile_directory: Profile directory
       feature_registrations: Registrations
       feature_relay: Federation relay
       features: Features
@@ -376,6 +377,9 @@ en:
       preview_sensitive_media:
         desc_html: Link previews on other websites will display a thumbnail even if the media is marked as sensitive
         title: Show sensitive media in OpenGraph previews
+      profile_directory:
+        desc_html: Allow users to be discoverable
+        title: Enable profile directory
       registrations:
         closed_message:
           desc_html: Displayed on frontpage when registrations are closed. You can use HTML tags
index 4036d419fe0a69522545916cb69680d0f86c37d9..b3d2e0240339650c8f4332678211f9bd0a3640e6 100644 (file)
@@ -15,6 +15,7 @@ defaults: &defaults
   site_contact_username: ''
   site_contact_email: ''
   open_registrations: true
+  profile_directory: true
   closed_registrations_message: ''
   open_deletion: true
   min_invite_role: 'admin'