From bfdcf76a6481476e84fde34c3dedc86d267bcbf7 Mon Sep 17 00:00:00 2001
From: Yamagishi Kazutoshi <ykzts@desire.sh>
Date: Sun, 19 Nov 2017 12:13:57 +0900
Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9Cstaff=E2=80=9D=20badge=20to=20ad?=
 =?UTF-8?q?min=20user=20pages=20(#5735)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Allow staff badge to change from setting to hidden

* i18n: Update Polish translation
---
 app/controllers/admin/settings_controller.rb |  2 ++
 app/models/form/admin_settings.rb            |  2 ++
 app/views/accounts/_header.html.haml         | 17 +++++++++--------
 app/views/admin/settings/edit.html.haml      |  3 +++
 config/locales/en.yml                        |  3 +++
 config/locales/pl.yml                        |  3 +++
 config/settings.yml                          |  1 +
 7 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index e81290228..d9199b3d5 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -13,6 +13,7 @@ module Admin
       closed_registrations_message
       open_deletion
       timeline_preview
+      show_staff_badge
       bootstrap_timeline_accounts
       thumbnail
     ).freeze
@@ -21,6 +22,7 @@ module Admin
       open_registrations
       open_deletion
       timeline_preview
+      show_staff_badge
     ).freeze
 
     UPLOAD_SETTINGS = %w(
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb
index 2b148c82b..6e9a2cd4b 100644
--- a/app/models/form/admin_settings.rb
+++ b/app/models/form/admin_settings.rb
@@ -24,6 +24,8 @@ class Form::AdminSettings
     :open_deletion=,
     :timeline_preview,
     :timeline_preview=,
+    :show_staff_badge,
+    :show_staff_badge=,
     :bootstrap_timeline_accounts,
     :bootstrap_timeline_accounts=,
     to: Setting
diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml
index 76371b656..d4081af64 100644
--- a/app/views/accounts/_header.html.haml
+++ b/app/views/accounts/_header.html.haml
@@ -27,14 +27,15 @@
         %span @#{account.local_username_and_domain}
         = fa_icon('lock') if account.locked?
 
-    - if account.user_admin?
-      .roles
-        .account-role.admin
-          = t 'accounts.roles.admin'
-    - elsif account.user_moderator?
-      .roles
-        .account-role.moderator
-          = t 'accounts.roles.moderator'
+    - if Setting.show_staff_badge
+      - if account.user_admin?
+        .roles
+          .account-role.admin
+            = t 'accounts.roles.admin'
+      - elsif account.user_moderator?
+        .roles
+          .account-role.moderator
+            = t 'accounts.roles.moderator'
 
     .bio
       .account__header__content.p-note.emojify= Formatter.instance.simplified_format(account)
diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml
index 468166035..b07718315 100644
--- a/app/views/admin/settings/edit.html.haml
+++ b/app/views/admin/settings/edit.html.haml
@@ -18,6 +18,9 @@
   .fields-group
     = f.input :timeline_preview, as: :boolean, wrapper: :with_label, label: t('admin.settings.timeline_preview.title'), hint: t('admin.settings.timeline_preview.desc_html')
 
+  .fields-group
+    = f.input :show_staff_badge, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_staff_badge.title'), hint: t('admin.settings.show_staff_badge.desc_html')
+
   .fields-group
     = f.input :open_registrations, as: :boolean, wrapper: :with_label, label: t('admin.settings.registrations.open.title'), hint: t('admin.settings.registrations.open.desc_html')
 
diff --git a/config/locales/en.yml b/config/locales/en.yml
index cef001341..cadedab8b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -246,6 +246,9 @@ en:
         open:
           desc_html: Allow anyone to create an account
           title: Open registration
+      show_staff_badge:
+        desc_html: Show a staff badge on a user page
+        title: Show staff badge
       site_description:
         desc_html: Introductory paragraph on the frontpage and in meta tags. You can use HTML tags, in particular <code>&lt;a&gt;</code> and <code>&lt;em&gt;</code>.
         title: Instance description
diff --git a/config/locales/pl.yml b/config/locales/pl.yml
index 0f90bc826..8c7c7d5c7 100644
--- a/config/locales/pl.yml
+++ b/config/locales/pl.yml
@@ -245,6 +245,9 @@ pl:
         open:
           desc_html: Pozwól każdemu na założenie konta
           title: Otwarta rejestracja
+      show_staff_badge:
+        desc_html: Pokazuj odznakę uprawnień na stronie profilu użytkownika
+        title: Pokazuj odznakę administracji
       site_description:
         desc_html: Akapit wprowadzający, widoczny na stronie głównej i znacznikach meta. Możesz korzystać z tagów HTML, w szczególności <code>&lt;a&gt;</code> i <code>&lt;em&gt;</code>.
         title: Opis instancji
diff --git a/config/settings.yml b/config/settings.yml
index a4df4094d..5a0170fb4 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -17,6 +17,7 @@ defaults: &defaults
   closed_registrations_message: ''
   open_deletion: true
   timeline_preview: true
+  show_staff_badge: true
   default_sensitive: false
   unfollow_modal: false
   boost_modal: false