From d4882aa64a7a483ec30ca61a507c2a6f5d3294f5 Mon Sep 17 00:00:00 2001 From: ThibG Date: Wed, 3 Apr 2019 18:17:43 +0200 Subject: Export and import `hide_notifications` alongside user mutes (#10335) * Export hide_notifications along with user mutes * Import hide_notifications along with muted users list * Add headers for CSV exports --- .../exports/muted_accounts_controller_spec.rb | 2 +- spec/fixtures/files/mute-imports.txt | 4 ++ spec/fixtures/files/new-mute-imports.txt | 4 ++ spec/models/export_spec.rb | 7 +- spec/services/import_service_spec.rb | 84 ++++++++++++++++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/files/mute-imports.txt create mode 100644 spec/fixtures/files/new-mute-imports.txt create mode 100644 spec/services/import_service_spec.rb (limited to 'spec') diff --git a/spec/controllers/settings/exports/muted_accounts_controller_spec.rb b/spec/controllers/settings/exports/muted_accounts_controller_spec.rb index f42d7881e..642f0a9b8 100644 --- a/spec/controllers/settings/exports/muted_accounts_controller_spec.rb +++ b/spec/controllers/settings/exports/muted_accounts_controller_spec.rb @@ -11,7 +11,7 @@ describe Settings::Exports::MutedAccountsController do sign_in user, scope: :user get :index, format: :csv - expect(response.body).to eq "username@domain\n" + expect(response.body).to eq "Account address,Hide notifications\nusername@domain,true\n" end end end diff --git a/spec/fixtures/files/mute-imports.txt b/spec/fixtures/files/mute-imports.txt new file mode 100644 index 000000000..125cbd384 --- /dev/null +++ b/spec/fixtures/files/mute-imports.txt @@ -0,0 +1,4 @@ +bob + +eve@example.com + diff --git a/spec/fixtures/files/new-mute-imports.txt b/spec/fixtures/files/new-mute-imports.txt new file mode 100644 index 000000000..c1c9bca9b --- /dev/null +++ b/spec/fixtures/files/new-mute-imports.txt @@ -0,0 +1,4 @@ +Account address,Hide notifications +bob,true +eve@example.com,false + diff --git a/spec/models/export_spec.rb b/spec/models/export_spec.rb index 277dcc526..0553f4098 100644 --- a/spec/models/export_spec.rb +++ b/spec/models/export_spec.rb @@ -21,10 +21,11 @@ describe Export do target_accounts.each(&account.method(:mute!)) export = Export.new(account).to_muted_accounts_csv - results = export.strip.split + results = export.strip.split("\n") - expect(results.size).to eq 2 - expect(results.first).to eq 'one@local.host' + expect(results.size).to eq 3 + expect(results.first).to eq 'Account address,Hide notifications' + expect(results.second).to eq 'one@local.host,true' end it 'returns a csv of the following accounts' do diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb new file mode 100644 index 000000000..bd23781ce --- /dev/null +++ b/spec/services/import_service_spec.rb @@ -0,0 +1,84 @@ +require 'rails_helper' + +RSpec.describe ImportService, type: :service do + let!(:account) { Fabricate(:account) } + let!(:bob) { Fabricate(:account, username: 'bob') } + let!(:eve) { Fabricate(:account, username: 'eve', domain: 'example.com') } + + context 'import old-style list of muted users' do + subject { ImportService.new } + + let(:csv) { attachment_fixture('mute-imports.txt') } + + describe 'when no accounts are muted' do + let(:import) { Import.create(account: account, type: 'muting', data: csv) } + it 'mutes the listed accounts, including notifications' do + subject.call(import) + expect(account.muting.count).to eq 2 + expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true + end + end + + describe 'when some accounts are muted and overwrite is not set' do + let(:import) { Import.create(account: account, type: 'muting', data: csv) } + + it 'mutes the listed accounts, including notifications' do + account.mute!(bob, notifications: false) + subject.call(import) + expect(account.muting.count).to eq 2 + expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true + end + end + + describe 'when some accounts are muted and overwrite is set' do + let(:import) { Import.create(account: account, type: 'muting', data: csv, overwrite: true) } + + it 'mutes the listed accounts, including notifications' do + account.mute!(bob, notifications: false) + subject.call(import) + expect(account.muting.count).to eq 2 + expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true + end + end + end + + context 'import new-style list of muted users' do + subject { ImportService.new } + + let(:csv) { attachment_fixture('new-mute-imports.txt') } + + describe 'when no accounts are muted' do + let(:import) { Import.create(account: account, type: 'muting', data: csv) } + it 'mutes the listed accounts, respecting notifications' do + subject.call(import) + expect(account.muting.count).to eq 2 + expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true + expect(Mute.find_by(account: account, target_account: eve).hide_notifications).to be false + end + end + + describe 'when some accounts are muted and overwrite is not set' do + let(:import) { Import.create(account: account, type: 'muting', data: csv) } + + it 'mutes the listed accounts, respecting notifications' do + account.mute!(bob, notifications: true) + subject.call(import) + expect(account.muting.count).to eq 2 + expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true + expect(Mute.find_by(account: account, target_account: eve).hide_notifications).to be false + end + end + + describe 'when some accounts are muted and overwrite is set' do + let(:import) { Import.create(account: account, type: 'muting', data: csv, overwrite: true) } + + it 'mutes the listed accounts, respecting notifications' do + account.mute!(bob, notifications: true) + subject.call(import) + expect(account.muting.count).to eq 2 + expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true + expect(Mute.find_by(account: account, target_account: eve).hide_notifications).to be false + end + end + end +end -- cgit From 67b3b62b98b89f24097a2757e42bc94f1bce123c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 7 Apr 2019 04:59:13 +0200 Subject: Improve blocked view of profiles (#10491) * Revert "Fix filtering of favourited_by, reblogged_by, followers and following (#10447)" This reverts commit 120544067fcca4bf6e71ba1ffb276c451c17c656. * Revert "Hide blocking accounts from blocked users (#10442)" This reverts commit 62bafa20a112ccdddaedb25723fc819dbbcd8e9a. * 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 --- .../v1/accounts/follower_accounts_controller.rb | 8 ++++-- .../v1/accounts/following_accounts_controller.rb | 8 ++++-- .../api/v1/accounts/statuses_controller.rb | 10 -------- app/controllers/api/v1/accounts_controller.rb | 5 ---- .../statuses/favourited_by_accounts_controller.rb | 1 - .../statuses/reblogged_by_accounts_controller.rb | 2 +- app/helpers/stream_entries_helper.rb | 2 +- .../mastodon/features/account/components/header.js | 2 +- .../mastodon/features/account_timeline/index.js | 22 +++++++++++----- .../mastodon/features/followers/index.js | 8 +++--- .../mastodon/features/following/index.js | 8 +++--- app/javascript/styles/mastodon/components.scss | 3 ++- app/javascript/styles/mastodon/stream_entries.scss | 17 ++++++++++++ app/models/account.rb | 1 - app/presenters/account_relationships_presenter.rb | 6 ++++- app/serializers/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 + .../accounts/follower_accounts_controller_spec.rb | 29 ++------------------- .../accounts/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(-) (limited to 'spec') diff --git a/app/controllers/api/v1/accounts/follower_accounts_controller.rb b/app/controllers/api/v1/accounts/follower_accounts_controller.rb index 7a45e6dd2..2dabb8398 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 0369cb25e..44e89804b 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 7aba2d0bd..8cd8f8e79 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 685e044c3..b0c62778e 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 e00c4d708..657e57831 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 9b2d0e59e..6851099f6 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 4734e32a4..d56efbfb9 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 4faba5589..e5b60e33e 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 =