From 2c63e0292a0a0a530ce814246bb6762983808135 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 6 Apr 2019 17:53:17 +0200 Subject: Fix admin validation being too strict about usernames (#10449) * Fix admin validation being too strict about usernames Fix #10446 * Strip Setting.site_contact_username consistently throughout the codebase --- app/controllers/home_controller.rb | 2 +- app/controllers/shares_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index b5d6460f9..d1bd0601e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -50,7 +50,7 @@ class HomeController < ApplicationController push_subscription: current_account.user.web_push_subscription(current_session), current_account: current_account, token: current_session.token, - admin: Account.find_local(Setting.site_contact_username), + admin: Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')), } end diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb index 9ef1e0749..af605b98f 100644 --- a/app/controllers/shares_controller.rb +++ b/app/controllers/shares_controller.rb @@ -21,7 +21,7 @@ class SharesController < ApplicationController push_subscription: current_account.user.web_push_subscription(current_session), current_account: current_account, token: current_session.token, - admin: Account.find_local(Setting.site_contact_username), + admin: Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')), text: text, } end -- cgit From e1d0390e29b60a6fa06d91a5d33dfb0e81fe7dd7 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 6 Apr 2019 17:53:45 +0200 Subject: Add batch actions for approving and rejecting pending accounts (#10469) --- .../admin/pending_accounts_controller.rb | 52 ++++++++++++++++++++++ app/models/form/account_batch.rb | 19 ++++++++ app/views/admin/accounts/index.html.haml | 2 +- .../admin/pending_accounts/_account.html.haml | 14 ++++++ app/views/admin/pending_accounts/index.html.haml | 33 ++++++++++++++ config/locales/en.yml | 4 +- config/navigation.rb | 2 +- config/routes.rb | 7 +++ 8 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 app/controllers/admin/pending_accounts_controller.rb create mode 100644 app/views/admin/pending_accounts/_account.html.haml create mode 100644 app/views/admin/pending_accounts/index.html.haml (limited to 'app/controllers') diff --git a/app/controllers/admin/pending_accounts_controller.rb b/app/controllers/admin/pending_accounts_controller.rb new file mode 100644 index 000000000..8429d3585 --- /dev/null +++ b/app/controllers/admin/pending_accounts_controller.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +module Admin + class PendingAccountsController < BaseController + before_action :set_accounts, only: :index + + def index + @form = Form::AccountBatch.new + end + + def update + @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button)) + @form.save + rescue ActionController::ParameterMissing + # Do nothing + ensure + redirect_to admin_pending_accounts_path(current_params) + end + + def approve_all + Form::AccountBatch.new(account_ids: User.pending.pluck(:account_id), action: 'approve').save + redirect_to admin_pending_accounts_path(current_params) + end + + def reject_all + Form::AccountBatch.new(account_ids: User.pending.pluck(:account_id), action: 'reject').save + redirect_to admin_pending_accounts_path(current_params) + end + + private + + def set_accounts + @accounts = Account.joins(:user).merge(User.pending).page(params[:page]) + end + + def form_account_batch_params + params.require(:form_account_batch).permit(:action, account_ids: []) + end + + def action_from_button + if params[:approve] + 'approve' + elsif params[:reject] + 'reject' + end + end + + def current_params + params.slice(:page).permit(:page) + end + end +end diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb index 60eaaf0e2..5bc44e809 100644 --- a/app/models/form/account_batch.rb +++ b/app/models/form/account_batch.rb @@ -2,6 +2,7 @@ class Form::AccountBatch include ActiveModel::Model + include Authorization attr_accessor :account_ids, :action, :current_account @@ -13,6 +14,10 @@ class Form::AccountBatch remove_from_followers! when 'block_domains' block_domains! + when 'approve' + approve! + when 'reject' + reject! end end @@ -57,4 +62,18 @@ class Form::AccountBatch ActivityPub::DeliveryWorker.perform_async(json, current_account.id, follow.account.inbox_url) end + + def approve! + users = accounts.includes(:user).map(&:user) + + users.each { |user| authorize(user, :approve?) } + .each(&:approve!) + end + + def reject! + records = accounts.includes(:user) + + records.each { |account| authorize(account.user, :reject?) } + .each { |account| SuspendAccountService.new.call(account, including_user: true, destroy: true, skip_distribution: true) } + end end diff --git a/app/views/admin/accounts/index.html.haml b/app/views/admin/accounts/index.html.haml index 66808add7..7e9adb3ff 100644 --- a/app/views/admin/accounts/index.html.haml +++ b/app/views/admin/accounts/index.html.haml @@ -10,7 +10,7 @@ .filter-subset %strong= t('admin.accounts.moderation.title') %ul - %li= filter_link_to t('admin.accounts.moderation.pending'), pending: '1', silenced: nil, suspended: nil + %li= link_to safe_join([t('admin.accounts.moderation.pending'), "(#{number_with_delimiter(User.pending.count)})"], ' '), admin_pending_accounts_path %li= filter_link_to t('admin.accounts.moderation.active'), silenced: nil, suspended: nil, pending: nil %li= filter_link_to t('admin.accounts.moderation.silenced'), silenced: '1', suspended: nil, pending: nil %li= filter_link_to t('admin.accounts.moderation.suspended'), suspended: '1', silenced: nil, pending: nil diff --git a/app/views/admin/pending_accounts/_account.html.haml b/app/views/admin/pending_accounts/_account.html.haml new file mode 100644 index 000000000..c520dc065 --- /dev/null +++ b/app/views/admin/pending_accounts/_account.html.haml @@ -0,0 +1,14 @@ +.batch-table__row + %label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox + = f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id + .batch-table__row__content.batch-table__row__content--unpadded + %table.accounts-table + %tbody + %tr + %td + = account.user_email + = "(@#{account.username})" + %br/ + = account.user_current_sign_in_ip + %td.accounts-table__count + = table_link_to 'pencil', t('admin.accounts.edit'), admin_account_path(account.id) diff --git a/app/views/admin/pending_accounts/index.html.haml b/app/views/admin/pending_accounts/index.html.haml new file mode 100644 index 000000000..77b96cbca --- /dev/null +++ b/app/views/admin/pending_accounts/index.html.haml @@ -0,0 +1,33 @@ +- content_for :page_title do + = t('admin.pending_accounts.title', count: User.pending.count) + +- content_for :header_tags do + = javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous' + += form_for(@form, url: admin_pending_accounts_path, method: :patch) do |f| + = hidden_field_tag :page, params[:page] || 1 + + .batch-table + .batch-table__toolbar + %label.batch-table__toolbar__select.batch-checkbox-all + = check_box_tag :batch_checkbox_all, nil, false + .batch-table__toolbar__actions + = f.button safe_join([fa_icon('check'), t('admin.accounts.approve')]), name: :approve, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') } + + = f.button safe_join([fa_icon('times'), t('admin.accounts.reject')]), name: :reject, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') } + .batch-table__body + - if @accounts.empty? + = nothing_here 'nothing-here--under-tabs' + - else + = render partial: 'account', collection: @accounts, locals: { f: f } + += paginate @accounts + +%hr.spacer/ + +%div{ style: 'overflow: hidden' } + %div{ style: 'float: right' } + = link_to t('admin.accounts.reject_all'), reject_all_admin_pending_accounts_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button button--destructive' + + %div + = link_to t('admin.accounts.approve_all'), approve_all_admin_pending_accounts_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button' diff --git a/config/locales/en.yml b/config/locales/en.yml index 705024ff5..df9c4913c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -330,6 +330,8 @@ en: expired: Expired title: Filter title: Invites + pending_accounts: + title: Pending accounts (%{count}) relays: add_new: Add new relay delete: Delete @@ -496,7 +498,7 @@ en: salutation: "%{name}," settings: 'Change e-mail preferences: %{link}' view: 'View:' - view_profile: View Profile + view_profile: View profile view_status: View status applications: created: Application successfully created diff --git a/config/navigation.rb b/config/navigation.rb index a6b2b6e4c..dd5825867 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -28,7 +28,7 @@ SimpleNavigation::Configuration.run do |navigation| primary.item :moderation, safe_join([fa_icon('gavel fw'), t('moderation.title')]), admin_reports_url, if: proc { current_user.staff? } do |admin| admin.item :action_logs, safe_join([fa_icon('bars fw'), t('admin.action_logs.title')]), admin_action_logs_url admin.item :reports, safe_join([fa_icon('flag fw'), t('admin.reports.title')]), admin_reports_url, highlights_on: %r{/admin/reports} - admin.item :accounts, safe_join([fa_icon('users fw'), t('admin.accounts.title')]), admin_accounts_url, highlights_on: %r{/admin/accounts} + admin.item :accounts, safe_join([fa_icon('users fw'), t('admin.accounts.title')]), admin_accounts_url, highlights_on: %r{/admin/accounts|/admin/pending_accounts} admin.item :invites, safe_join([fa_icon('user-plus fw'), t('admin.invites.title')]), admin_invites_path admin.item :tags, safe_join([fa_icon('tag fw'), t('admin.tags.title')]), admin_tags_path admin.item :instances, safe_join([fa_icon('cloud fw'), t('admin.instances.title')]), admin_instances_url(limited: '1'), highlights_on: %r{/admin/instances|/admin/domain_blocks}, if: -> { current_user.admin? } diff --git a/config/routes.rb b/config/routes.rb index a98dbb700..1ea6490b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,6 +214,13 @@ Rails.application.routes.draw do end end + resources :pending_accounts, only: [:index, :update] do + collection do + post :approve_all + post :reject_all + end + end + resources :users, only: [] do resource :two_factor_authentication, only: [:destroy] 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 'app/controllers') 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 =