From 720daa81435b4c632cdf7b64044cf1ee59af977a Mon Sep 17 00:00:00 2001
From: ThibG <thib@sitedethib.com>
Date: Tue, 11 Dec 2018 19:18:29 +0100
Subject: Add instance-wide setting to disable profile directory (#9497)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* 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/views/admin/dashboard/index.html.haml  | 6 ++++++
 app/views/admin/settings/edit.html.haml    | 3 +++
 app/views/layouts/public.html.haml         | 3 ++-
 app/views/settings/profiles/show.html.haml | 5 +++--
 4 files changed, 14 insertions(+), 3 deletions(-)

(limited to 'app/views')

diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml
index 1996eef4d..fa3d70e9e 100644
--- a/app/views/admin/dashboard/index.html.haml
+++ b/app/views/admin/dashboard/index.html.haml
@@ -57,6 +57,12 @@
             %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
diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml
index 04b1a6754..7afa9ec37 100644
--- a/app/views/admin/settings/edit.html.haml
+++ b/app/views/admin/settings/edit.html.haml
@@ -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
diff --git a/app/views/layouts/public.html.haml b/app/views/layouts/public.html.haml
index 831c7f012..93ed12f18 100644
--- a/app/views/layouts/public.html.haml
+++ b/app/views/layouts/public.html.haml
@@ -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
diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml
index fa3869f6f..eb232dc57 100644
--- a/app/views/settings/profiles/show.html.haml
+++ b/app/views/settings/profiles/show.html.haml
@@ -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/
 
-- 
cgit 


From cf6ee4ff243b66b2b53faaceed1266999b84c3c1 Mon Sep 17 00:00:00 2001
From: ThibG <thib@sitedethib.com>
Date: Tue, 11 Dec 2018 19:28:03 +0100
Subject: Add admin ability to remove an user's header image (#9495)

* Fix markup in admin/accounts/:id table for avatar

* Add admin ability to remove an user's header image
---
 app/controllers/admin/accounts_controller.rb | 13 ++++++++++++-
 app/helpers/admin/action_logs_helper.rb      |  2 +-
 app/policies/account_policy.rb               |  4 ++++
 app/views/admin/accounts/show.html.haml      |  9 ++++++++-
 config/routes.rb                             |  1 +
 5 files changed, 26 insertions(+), 3 deletions(-)

(limited to 'app/views')

diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb
index f155543ce..771302db8 100644
--- a/app/controllers/admin/accounts_controller.rb
+++ b/app/controllers/admin/accounts_controller.rb
@@ -2,7 +2,7 @@
 
 module Admin
   class AccountsController < BaseController
-    before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :enable, :disable, :memorialize]
+    before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :disable, :memorialize]
     before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
     before_action :require_local_account!, only: [:enable, :disable, :memorialize]
 
@@ -71,6 +71,17 @@ module Admin
       redirect_to admin_account_path(@account.id)
     end
 
+    def remove_header
+      authorize @account, :remove_header?
+
+      @account.header = nil
+      @account.save!
+
+      log_action :remove_header, @account.user
+
+      redirect_to admin_account_path(@account.id)
+    end
+
     private
 
     def set_account
diff --git a/app/helpers/admin/action_logs_helper.rb b/app/helpers/admin/action_logs_helper.rb
index c28f0be6b..68cf8c75d 100644
--- a/app/helpers/admin/action_logs_helper.rb
+++ b/app/helpers/admin/action_logs_helper.rb
@@ -92,7 +92,7 @@ module Admin::ActionLogsHelper
       opposite_verbs?(log) ? 'negative' : 'positive'
     when :update, :reset_password, :disable_2fa, :memorialize, :change_email
       'neutral'
-    when :demote, :silence, :disable, :suspend, :remove_avatar, :reopen
+    when :demote, :silence, :disable, :suspend, :remove_avatar, :remove_header, :reopen
       'negative'
     when :destroy
       opposite_verbs?(log) ? 'positive' : 'negative'
diff --git a/app/policies/account_policy.rb b/app/policies/account_policy.rb
index efabe80d0..07bae68ef 100644
--- a/app/policies/account_policy.rb
+++ b/app/policies/account_policy.rb
@@ -33,6 +33,10 @@ class AccountPolicy < ApplicationPolicy
     staff?
   end
 
+  def remove_header?
+    staff?
+  end
+
   def subscribe?
     admin?
   end
diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml
index c1a5fc1bd..e9f765107 100644
--- a/app/views/admin/accounts/show.html.haml
+++ b/app/views/admin/accounts/show.html.haml
@@ -16,11 +16,18 @@
 
       %tr
         %th= t('admin.accounts.avatar')
-        %th
+        %td
           = link_to @account.avatar.url(:original) do
             = image_tag @account.avatar.url(:original), alt: '', width: 40, height: 40, class: 'avatar'
           - if @account.local? && @account.avatar?
             = table_link_to 'trash', t('admin.accounts.remove_avatar'), remove_avatar_admin_account_path(@account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:remove_avatar, @account)
+      %tr
+        %th= t('admin.accounts.header')
+        %td
+          = link_to @account.header.url(:original) do
+            = image_tag @account.header.url(:original), alt: '', width: 128, height: 40, class: 'header'
+          - if @account.local? && @account.header?
+            = table_link_to 'trash', t('admin.accounts.remove_header'), remove_header_admin_account_path(@account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:remove_header, @account)
 
       - if @account.local?
         %tr
diff --git a/config/routes.rb b/config/routes.rb
index 262868413..4a0289465 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -176,6 +176,7 @@ Rails.application.routes.draw do
         post :disable
         post :redownload
         post :remove_avatar
+        post :remove_header
         post :memorialize
       end
 
-- 
cgit 


From 11a91592aac049c6c0efffbb9b17347663303d47 Mon Sep 17 00:00:00 2001
From: ThibG <thib@sitedethib.com>
Date: Fri, 14 Dec 2018 01:47:50 +0100
Subject: Restore profile links in /admin/accounts (#9494)

Fixes #9431
---
 app/views/admin/accounts/_account.html.haml | 3 +++
 app/views/admin/accounts/index.html.haml    | 1 +
 2 files changed, 4 insertions(+)

(limited to 'app/views')

diff --git a/app/views/admin/accounts/_account.html.haml b/app/views/admin/accounts/_account.html.haml
index 0fadaae1e..1e1bb1812 100644
--- a/app/views/admin/accounts/_account.html.haml
+++ b/app/views/admin/accounts/_account.html.haml
@@ -13,3 +13,6 @@
       %time.time-ago{ datetime: account.user_current_sign_in_at.iso8601, title: l(account.user_current_sign_in_at) }= l account.user_current_sign_in_at
     - else
       \-
+  %td
+    = table_link_to 'circle', t('admin.accounts.web'), web_path("accounts/#{account.id}")
+    = table_link_to 'globe', t('admin.accounts.public'), TagManager.instance.url_for(account)
diff --git a/app/views/admin/accounts/index.html.haml b/app/views/admin/accounts/index.html.haml
index 0d31eee36..91fddadf8 100644
--- a/app/views/admin/accounts/index.html.haml
+++ b/app/views/admin/accounts/index.html.haml
@@ -41,6 +41,7 @@
         %th= t('admin.accounts.role')
         %th= t('admin.accounts.most_recent_ip')
         %th= t('admin.accounts.most_recent_activity')
+        %th
     %tbody
       = render @accounts
 
-- 
cgit 


From 7c48688d85d0ab64501cea6b8a516867a786bb4c Mon Sep 17 00:00:00 2001
From: ThibG <thib@sitedethib.com>
Date: Fri, 14 Dec 2018 20:34:18 +0100
Subject: Make avatar and headers respect `auto_play_gif` (#9515)

* Do not animate account header art if user's GIF autoplay setting is off

Fixes #9472

* Honour currently logged-in user's GIF autoplay setting for account avatars

Fixes #9467

* Fix avatar display on some public pages when data is stored on a different host

* Use ternary operator instead of if/else for avatar/header URL
---
 app/helpers/home_helper.rb                                    | 2 +-
 app/javascript/mastodon/features/account/components/header.js | 2 +-
 app/views/accounts/_header.html.haml                          | 7 ++-----
 3 files changed, 4 insertions(+), 7 deletions(-)

(limited to 'app/views')

diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb
index ba7c443c2..9b3f1380b 100644
--- a/app/helpers/home_helper.rb
+++ b/app/helpers/home_helper.rb
@@ -23,7 +23,7 @@ module HomeHelper
                   else
                     link_to(path || TagManager.instance.url_for(account), class: 'account__display-name') do
                       content_tag(:div, class: 'account__avatar-wrapper') do
-                        content_tag(:div, '', class: 'account__avatar', style: "width: #{size}px; height: #{size}px; background-size: #{size}px #{size}px; background-image: url(#{account.avatar.url})")
+                        content_tag(:div, '', class: 'account__avatar', style: "width: #{size}px; height: #{size}px; background-size: #{size}px #{size}px; background-image: url(#{full_asset_url(current_account&.user&.setting_auto_play_gif ? account.avatar_original_url : account.avatar_static_url)})")
                       end +
                         content_tag(:span, class: 'display-name') do
                           content_tag(:bdi) do
diff --git a/app/javascript/mastodon/features/account/components/header.js b/app/javascript/mastodon/features/account/components/header.js
index 8604e7167..2ab25cde4 100644
--- a/app/javascript/mastodon/features/account/components/header.js
+++ b/app/javascript/mastodon/features/account/components/header.js
@@ -158,7 +158,7 @@ class Header extends ImmutablePureComponent {
     const badge           = account.get('bot') ? (<div className='roles'><div className='account-role bot'><FormattedMessage id='account.badges.bot' defaultMessage='Bot' /></div></div>) : null;
 
     return (
-      <div className={classNames('account__header', { inactive: !!account.get('moved') })} style={{ backgroundImage: `url(${account.get('header')})` }}>
+      <div className={classNames('account__header', { inactive: !!account.get('moved') })} style={{ backgroundImage: `url(${autoPlayGif ? account.get('header') : account.get('header_static')})` }}>
         <div>
           <Avatar account={account} />
 
diff --git a/app/views/accounts/_header.html.haml b/app/views/accounts/_header.html.haml
index 9ceae007d..370e7e470 100644
--- a/app/views/accounts/_header.html.haml
+++ b/app/views/accounts/_header.html.haml
@@ -1,12 +1,9 @@
 .public-account-header{:class => ("inactive" if account.moved?)}
   .public-account-header__image
-    = image_tag account.header.url, class: 'parallax'
+    = image_tag (current_account&.user&.setting_auto_play_gif ? account.header_original_url : account.header_static_url), class: 'parallax'
   .public-account-header__bar
     = link_to short_account_url(account), class: 'avatar' do
-      - if current_account&.user&.setting_auto_play_gif
-        = image_tag account.avatar_original_url
-      - else
-        = image_tag account.avatar_static_url
+      = image_tag (current_account&.user&.setting_auto_play_gif ? account.avatar_original_url : account.avatar_static_url)
     .public-account-header__tabs
       .public-account-header__tabs__name
         %h1
-- 
cgit