From 5d2fc6de321ac556ded72e5a8fa9fcf47d172e16 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 24 Dec 2018 19:12:38 +0100 Subject: Add REST API for creating an account (#9572) * Add REST API for creating an account The method is available to apps with a token obtained via the client credentials grant. It creates a user and account records, as well as an access token for the app that initiated the request. The user is unconfirmed, and an e-mail is sent as usual. The method returns the access token, which the app should save for later. The REST API is not available to users with unconfirmed accounts, so the app must be smart to wait for the user to click a link in their e-mail inbox. The method is rate-limited by IP to 5 requests per 30 minutes. * Redirect users back to app from confirmation if they were created with an app * Add tests * Return 403 on the method if registrations are not open * Require agreement param to be true in the API when creating an account --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config/routes.rb') diff --git a/config/routes.rb b/config/routes.rb index 7723a08af..808bb5acd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -336,7 +336,7 @@ Rails.application.routes.draw do resources :relationships, only: :index end - resources :accounts, only: [:show] do + resources :accounts, only: [:create, :show] do resources :statuses, only: :index, controller: 'accounts/statuses' resources :followers, only: :index, controller: 'accounts/follower_accounts' resources :following, only: :index, controller: 'accounts/following_accounts' -- cgit From c3465f699e345e6909271a3159293783df0f0891 Mon Sep 17 00:00:00 2001 From: "chr v1.x" Date: Thu, 27 Dec 2018 04:15:39 -0800 Subject: Add local followers page to admin account UI (#9610) * Add local followers page to admin account UI For moderation, I often find myself wondering who, locally, is following a remote user. Currently, to see this, I have to go back to the web UI, paste in their full handle, click their profile, and go to the "Followers" tab (plus, this information is incidental, and if mastodon ever decides to resolve all of the follower information, there will be no place local followers are shown). This PR adds a new page which is accessible via the "following" count on the admin's account view page, which shows the local followers. (It has filter parameters for account location to indicate that only local followers are shown, and leave room for expansion if mastodon ever decides to store the entire remote follow list). * Normalize en.yml --- app/controllers/admin/followers_controller.rb | 22 ++++++++++++++++++++ app/models/account.rb | 4 ++++ app/views/admin/accounts/show.html.haml | 4 +++- app/views/admin/followers/index.html.haml | 29 +++++++++++++++++++++++++++ config/locales/en.yml | 4 ++++ config/routes.rb | 1 + 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/followers_controller.rb create mode 100644 app/views/admin/followers/index.html.haml (limited to 'config/routes.rb') diff --git a/app/controllers/admin/followers_controller.rb b/app/controllers/admin/followers_controller.rb new file mode 100644 index 000000000..819628b20 --- /dev/null +++ b/app/controllers/admin/followers_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Admin + class FollowersController < BaseController + before_action :set_account + + PER_PAGE = 40 + + def index + authorize :account, :index? + @followers = followers.recent.page(params[:page]).per(PER_PAGE) + end + + def set_account + @account = Account.find(params[:account_id]) + end + + def followers + Follow.includes(:account).where(target_account: @account) + end + end +end diff --git a/app/models/account.rb b/app/models/account.rb index cf804fc67..66f02b27d 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -139,6 +139,10 @@ class Account < ApplicationRecord "#{username}@#{Rails.configuration.x.local_domain}" end + def local_followers_count + Follow.where(target_account_id: id).count + end + def to_webfinger_s "acct:#{local_username_and_domain}" end diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index 226aef732..47cf41073 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -89,7 +89,9 @@ %td= number_to_human @account.following_count %tr %th= t('admin.accounts.followers') - %td= number_to_human @account.followers_count + %td + = number_to_human @account.followers_count + = link_to t('admin.accounts.followers_local', local: number_to_human(@account.local_followers_count)), admin_account_followers_path(@account.id) %tr %th= t('admin.accounts.statuses') %td= link_to number_to_human(@account.statuses_count), admin_account_statuses_path(@account.id) diff --git a/app/views/admin/followers/index.html.haml b/app/views/admin/followers/index.html.haml new file mode 100644 index 000000000..baf34bc95 --- /dev/null +++ b/app/views/admin/followers/index.html.haml @@ -0,0 +1,29 @@ +- content_for :header_tags do + = javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous' + +- content_for :page_title do + = t('admin.followers.title', acct: @account.acct) + +.filters + .filter-subset + %strong= t('admin.accounts.location.title') + %ul + %li= link_to t('admin.accounts.location.local'), admin_account_followers_path(@account.id), class: 'selected' + .back-link{ style: 'flex: 1 1 auto; text-align: right' } + = link_to admin_account_path(@account.id) do + %i.fa.fa-chevron-left.fa-fw + = t('admin.followers.back_to_account') + +.table-wrapper + %table.table + %thead + %tr + %th= t('admin.accounts.username') + %th= t('admin.accounts.role') + %th= t('admin.accounts.most_recent_ip') + %th= t('admin.accounts.most_recent_activity') + %th + %tbody + = render partial: 'admin/accounts/account', collection: @followers.map{|a| a.account} + += paginate @followers diff --git a/config/locales/en.yml b/config/locales/en.yml index 091a4b72c..7ccff2ffd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -105,6 +105,7 @@ en: enabled: Enabled feed_url: Feed URL followers: Followers + followers_local: "(%{local} local)" followers_url: Followers URL follows: Follows header: Header @@ -296,6 +297,9 @@ en: create: Add domain title: New e-mail blacklist entry title: E-mail blacklist + followers: + back_to_account: Back To Account + title: "%{acct}'s Followers" instances: account_count: Known accounts domain_name: Domain diff --git a/config/routes.rb b/config/routes.rb index 808bb5acd..1556aa577 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -191,6 +191,7 @@ Rails.application.routes.draw do resource :reset, only: [:create] resource :action, only: [:new, :create], controller: 'account_actions' resources :statuses, only: [:index, :create, :update, :destroy] + resources :followers, only: [:index] resource :confirmation, only: [:create] do collection do -- cgit From 7fc7437d05bf1441bb694b847f7e65ce37cd74fa Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 1 Jan 2019 13:44:04 +0100 Subject: Add CSV export for lists and domain blocks (#9677) Fix #6893 Fix #9268 --- .../settings/exports/blocked_domains_controller.rb | 19 +++++++++++ .../settings/exports/lists_controller.rb | 19 +++++++++++ app/models/export.rb | 38 +++++++++++++++++++--- app/views/settings/exports/show.html.haml | 8 +++++ config/routes.rb | 2 ++ 5 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 app/controllers/settings/exports/blocked_domains_controller.rb create mode 100644 app/controllers/settings/exports/lists_controller.rb (limited to 'config/routes.rb') diff --git a/app/controllers/settings/exports/blocked_domains_controller.rb b/app/controllers/settings/exports/blocked_domains_controller.rb new file mode 100644 index 000000000..6676ce340 --- /dev/null +++ b/app/controllers/settings/exports/blocked_domains_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Settings + module Exports + class BlockedDomainsController < ApplicationController + include ExportControllerConcern + + def index + send_export_file + end + + private + + def export_data + @export.to_blocked_domains_csv + end + end + end +end diff --git a/app/controllers/settings/exports/lists_controller.rb b/app/controllers/settings/exports/lists_controller.rb new file mode 100644 index 000000000..cf5a9de44 --- /dev/null +++ b/app/controllers/settings/exports/lists_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Settings + module Exports + class ListsController < ApplicationController + include ExportControllerConcern + + def index + send_export_file + end + + private + + def export_data + @export.to_lists_csv + end + end + end +end diff --git a/app/models/export.rb b/app/models/export.rb index 0eeac0dc0..a2520e9c2 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -9,15 +9,33 @@ class Export end def to_blocked_accounts_csv - to_csv account.blocking + to_csv account.blocking.select(:username, :domain) end def to_muted_accounts_csv - to_csv account.muting + to_csv account.muting.select(:username, :domain) end def to_following_accounts_csv - to_csv account.following + to_csv account.following.select(:username, :domain) + end + + def to_lists_csv + CSV.generate do |csv| + account.owned_lists.select(:title).each do |list| + list.accounts.select(:username, :domain).each do |account| + csv << [list.title, acct(account)] + end + end + end + end + + def to_blocked_domains_csv + CSV.generate do |csv| + account.domain_blocks.pluck(:domain).each do |domain| + csv << [domain] + end + end end def total_storage @@ -32,6 +50,10 @@ class Export account.following_count end + def total_lists + account.owned_lists.count + end + def total_followers account.followers_count end @@ -44,13 +66,21 @@ class Export account.muting.count end + def total_domain_blocks + account.domain_blocks.count + end + private def to_csv(accounts) CSV.generate do |csv| accounts.each do |account| - csv << [(account.local? ? account.local_username_and_domain : account.acct)] + csv << [acct(account)] end end end + + def acct(account) + account.local? ? account.local_username_and_domain : account.acct + end end diff --git a/app/views/settings/exports/show.html.haml b/app/views/settings/exports/show.html.haml index 6c030b1ab..b13cea976 100644 --- a/app/views/settings/exports/show.html.haml +++ b/app/views/settings/exports/show.html.haml @@ -16,6 +16,10 @@ %th= t('exports.follows') %td= number_with_delimiter @export.total_follows %td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv) + %tr + %th= t('exports.lists') + %td= number_with_delimiter @export.total_lists + %td= table_link_to 'download', t('exports.csv'), settings_exports_lists_path(format: :csv) %tr %th= t('accounts.followers', count: @export.total_followers) %td= number_with_delimiter @export.total_followers @@ -28,6 +32,10 @@ %th= t('exports.mutes') %td= number_with_delimiter @export.total_mutes %td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv) + %tr + %th= t('exports.domain_blocks') + %td= number_with_delimiter @export.total_domain_blocks + %td= table_link_to 'download', t('exports.csv'), settings_exports_domain_blocks_path(format: :csv) %p.muted-hint= t('exports.archive_takeout.hint_html') diff --git a/config/routes.rb b/config/routes.rb index 1556aa577..6e4da48a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,6 +94,8 @@ Rails.application.routes.draw do resources :follows, only: :index, controller: :following_accounts resources :blocks, only: :index, controller: :blocked_accounts resources :mutes, only: :index, controller: :muted_accounts + resources :lists, only: :index, controller: :lists + resources :domain_blocks, only: :index, controller: :blocked_domains end resource :two_factor_authentication, only: [:show, :create, :destroy] -- cgit