From c84c30c542bdb9b65d5c847cb5113e697a7d83dd Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 7 Apr 2019 04:59:13 +0200 Subject: [PATCH] Improve blocked view of profiles (#10491) * Revert "Fix filtering of favourited_by, reblogged_by, followers and following (#10447)" This reverts commit 0317f37c6ff05d675c7e8547b02cec9b218f60a9. * Revert "Hide blocking accounts from blocked users (#10442)" This reverts commit 4cd944d3643228bad2e5a708746c1c70c24612f9. * Improve blocked view of profiles - Change "You are blocked" to "Profile unavailable" - Hide following/followers in API when blocked - Disable follow button and show "Profile unavailable" on public profile as well --- .../accounts/follower_accounts_controller.rb | 8 +++-- .../accounts/following_accounts_controller.rb | 8 +++-- .../api/v1/accounts/statuses_controller.rb | 10 ------- app/controllers/api/v1/accounts_controller.rb | 5 ---- .../favourited_by_accounts_controller.rb | 1 - .../reblogged_by_accounts_controller.rb | 2 +- app/helpers/stream_entries_helper.rb | 2 +- .../features/account/components/header.js | 2 +- .../features/account_timeline/index.js | 22 ++++++++++---- .../mastodon/features/followers/index.js | 8 +++-- .../mastodon/features/following/index.js | 8 +++-- .../styles/mastodon/components.scss | 3 +- .../styles/mastodon/stream_entries.scss | 17 +++++++++++ app/models/account.rb | 1 - .../account_relationships_presenter.rb | 6 +++- .../rest/relationship_serializer.rb | 6 +++- app/services/account_search_service.rb | 10 +------ app/services/search_service.rb | 2 -- app/views/accounts/show.html.haml | 4 ++- app/views/follower_accounts/index.html.haml | 2 ++ app/views/following_accounts/index.html.haml | 2 ++ config/locales/en.yml | 1 + .../follower_accounts_controller_spec.rb | 29 ++---------------- .../following_accounts_controller_spec.rb | 29 ++---------------- spec/services/account_search_service_spec.rb | 17 ----------- spec/services/search_service_spec.rb | 30 +++++++++---------- 26 files changed, 97 insertions(+), 138 deletions(-) diff --git a/app/controllers/api/v1/accounts/follower_accounts_controller.rb b/app/controllers/api/v1/accounts/follower_accounts_controller.rb index 7a45e6dd26..2dabb8398c 100644 --- a/app/controllers/api/v1/accounts/follower_accounts_controller.rb +++ b/app/controllers/api/v1/accounts/follower_accounts_controller.rb @@ -19,13 +19,17 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController end def load_accounts - return [] if @account.user_hides_network? && current_account.id != @account.id + return [] if hide_results? default_accounts.merge(paginated_follows).to_a end + def hide_results? + (@account.user_hides_network? && current_account.id != @account.id) || (current_account && @account.blocking?(current_account)) + end + def default_accounts - Account.without_blocking(current_account).includes(:active_relationships, :account_stat).references(:active_relationships) + Account.includes(:active_relationships, :account_stat).references(:active_relationships) end def paginated_follows diff --git a/app/controllers/api/v1/accounts/following_accounts_controller.rb b/app/controllers/api/v1/accounts/following_accounts_controller.rb index 0369cb25e9..44e89804b3 100644 --- a/app/controllers/api/v1/accounts/following_accounts_controller.rb +++ b/app/controllers/api/v1/accounts/following_accounts_controller.rb @@ -19,13 +19,17 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController end def load_accounts - return [] if @account.user_hides_network? && current_account.id != @account.id + return [] if hide_results? default_accounts.merge(paginated_follows).to_a end + def hide_results? + (@account.user_hides_network? && current_account.id != @account.id) || (current_account && @account.blocking?(current_account)) + end + def default_accounts - Account.without_blocking(current_account).includes(:passive_relationships, :account_stat).references(:passive_relationships) + Account.includes(:passive_relationships, :account_stat).references(:passive_relationships) end def paginated_follows diff --git a/app/controllers/api/v1/accounts/statuses_controller.rb b/app/controllers/api/v1/accounts/statuses_controller.rb index 7aba2d0bdb..8cd8f8e799 100644 --- a/app/controllers/api/v1/accounts/statuses_controller.rb +++ b/app/controllers/api/v1/accounts/statuses_controller.rb @@ -3,8 +3,6 @@ class Api::V1::Accounts::StatusesController < Api::BaseController before_action -> { authorize_if_got_token! :read, :'read:statuses' } before_action :set_account - before_action :check_account_suspension - before_action :check_account_block after_action :insert_pagination_headers respond_to :json @@ -20,14 +18,6 @@ class Api::V1::Accounts::StatusesController < Api::BaseController @account = Account.find(params[:account_id]) end - def check_account_suspension - gone if @account.suspended? - end - - def check_account_block - gone if current_account.present? && @account.blocking?(current_account) - end - def load_statuses cached_account_statuses end diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 685e044c34..b0c62778e6 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -10,7 +10,6 @@ class Api::V1::AccountsController < Api::BaseController before_action :require_user!, except: [:show, :create] before_action :set_account, except: [:create] before_action :check_account_suspension, only: [:show] - before_action :check_account_block, only: [:show] before_action :check_enabled_registrations, only: [:create] respond_to :json @@ -76,10 +75,6 @@ class Api::V1::AccountsController < Api::BaseController gone if @account.suspended? end - def check_account_block - gone if current_account.present? && @account.blocking?(current_account) - end - def account_params params.permit(:username, :email, :password, :agreement, :locale) end diff --git a/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb b/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb index e00c4d7088..657e578319 100644 --- a/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb @@ -22,7 +22,6 @@ class Api::V1::Statuses::FavouritedByAccountsController < Api::BaseController def default_accounts Account - .without_blocking(current_account) .includes(:favourites, :account_stat) .references(:favourites) .where(favourites: { status_id: @status.id }) diff --git a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb index 9b2d0e59e9..6851099f66 100644 --- a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb @@ -21,7 +21,7 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::BaseController end def default_accounts - Account.without_blocking(current_account).includes(:statuses, :account_stat).references(:statuses) + Account.includes(:statuses, :account_stat).references(:statuses) end def paginated_statuses diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index 4734e32a43..d56efbfb91 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -23,7 +23,7 @@ module StreamEntriesHelper safe_join([render(file: Rails.root.join('app', 'javascript', 'images', 'logo.svg')), t('accounts.unfollow')]) end elsif !(account.memorial? || account.moved?) - link_to account_follow_path(account), class: 'button logo-button', data: { method: :post } do + link_to account_follow_path(account), class: "button logo-button#{account.blocking?(current_account) ? ' disabled' : ''}", data: { method: :post } do safe_join([render(file: Rails.root.join('app', 'javascript', 'images', 'logo.svg')), t('accounts.follow')]) end end diff --git a/app/javascript/mastodon/features/account/components/header.js b/app/javascript/mastodon/features/account/components/header.js index 4faba55895..e5b60e33e1 100644 --- a/app/javascript/mastodon/features/account/components/header.js +++ b/app/javascript/mastodon/features/account/components/header.js @@ -109,7 +109,7 @@ class Header extends ImmutablePureComponent { } else if (account.getIn(['relationship', 'requested'])) { actionBtn =