diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/about_controller.rb | 29 | ||||
-rw-r--r-- | app/controllers/accounts_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/admin/accounts_controller.rb | 93 | ||||
-rw-r--r-- | app/controllers/admin/base_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/admin/domain_blocks_controller.rb | 42 | ||||
-rw-r--r-- | app/controllers/admin/pubsubhubbub_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/admin/reports_controller.rb | 81 | ||||
-rw-r--r-- | app/controllers/admin/settings_controller.rb | 46 | ||||
-rw-r--r-- | app/controllers/api/v1/accounts_controller.rb | 15 | ||||
-rw-r--r-- | app/controllers/api/v1/notifications_controller.rb | 10 | ||||
-rw-r--r-- | app/controllers/api_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/concerns/localized.rb | 4 | ||||
-rw-r--r-- | app/controllers/remote_follow_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/settings/exports_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/xrd_controller.rb | 2 |
15 files changed, 185 insertions, 169 deletions
diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index 7fd43489f..04e7ddacf 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -2,30 +2,25 @@ class AboutController < ApplicationController before_action :set_body_classes + before_action :set_instance_presenter, only: [:show, :more] - def index - @description = Setting.site_description - @open_registrations = Setting.open_registrations - @closed_registrations_message = Setting.closed_registrations_message + def show; end - @user = User.new - @user.build_account - end - - def more - @description = Setting.site_description - @extended_description = Setting.site_extended_description - @contact_account = Account.find_local(Setting.site_contact_username) - @contact_email = Setting.site_contact_email - @user_count = Rails.cache.fetch('user_count') { User.count } - @status_count = Rails.cache.fetch('local_status_count') { Status.local.count } - @domain_count = Rails.cache.fetch('distinct_domain_count') { Account.distinct.count(:domain) } - end + def more; end def terms; end private + def new_user + User.new.tap(&:build_account) + end + helper_method :new_user + + def set_instance_presenter + @instance_presenter = InstancePresenter.new + end + def set_body_classes @body_classes = 'about-body' end diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 619c04be2..d4f157614 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -35,11 +35,11 @@ class AccountsController < ApplicationController end def followers - @followers = @account.followers.order('follows.created_at desc').paginate(page: params[:page], per_page: 12) + @followers = @account.followers.order('follows.created_at desc').page(params[:page]).per(12) end def following - @following = @account.following.order('follows.created_at desc').paginate(page: params[:page], per_page: 12) + @following = @account.following.order('follows.created_at desc').page(params[:page]).per(12) end private @@ -53,7 +53,7 @@ class AccountsController < ApplicationController end def webfinger_account_url - webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}") + webfinger_url(resource: @account.to_webfinger_s) end def check_account_suspension diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index df2c7bebf..71cb8edd8 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -1,51 +1,50 @@ # frozen_string_literal: true -class Admin::AccountsController < ApplicationController - before_action :require_admin! - before_action :set_account, except: :index - - layout 'admin' - - def index - @accounts = Account.alphabetic.paginate(page: params[:page], per_page: 40) - - @accounts = @accounts.local if params[:local].present? - @accounts = @accounts.remote if params[:remote].present? - @accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present? - @accounts = @accounts.silenced if params[:silenced].present? - @accounts = @accounts.recent if params[:recent].present? - @accounts = @accounts.suspended if params[:suspended].present? - end - - def show; end - - def suspend - Admin::SuspensionWorker.perform_async(@account.id) - redirect_to admin_accounts_path - end - - def unsuspend - @account.update(suspended: false) - redirect_to admin_accounts_path - end - - def silence - @account.update(silenced: true) - redirect_to admin_accounts_path - end - - def unsilence - @account.update(silenced: false) - redirect_to admin_accounts_path - end - - private - - def set_account - @account = Account.find(params[:id]) - end - - def account_params - params.require(:account).permit(:silenced, :suspended) +module Admin + class AccountsController < BaseController + before_action :set_account, except: :index + + def index + @accounts = Account.alphabetic.page(params[:page]) + + @accounts = @accounts.local if params[:local].present? + @accounts = @accounts.remote if params[:remote].present? + @accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present? + @accounts = @accounts.silenced if params[:silenced].present? + @accounts = @accounts.recent if params[:recent].present? + @accounts = @accounts.suspended if params[:suspended].present? + end + + def show; end + + def suspend + Admin::SuspensionWorker.perform_async(@account.id) + redirect_to admin_accounts_path + end + + def unsuspend + @account.update(suspended: false) + redirect_to admin_accounts_path + end + + def silence + @account.update(silenced: true) + redirect_to admin_accounts_path + end + + def unsilence + @account.update(silenced: false) + redirect_to admin_accounts_path + end + + private + + def set_account + @account = Account.find(params[:id]) + end + + def account_params + params.require(:account).permit(:silenced, :suspended) + end end end diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb new file mode 100644 index 000000000..11fe326bc --- /dev/null +++ b/app/controllers/admin/base_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Admin + class BaseController < ApplicationController + before_action :require_admin! + + layout 'admin' + end +end diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 1f4432847..a8b56c085 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -1,32 +1,30 @@ # frozen_string_literal: true -class Admin::DomainBlocksController < ApplicationController - before_action :require_admin! - - layout 'admin' - - def index - @blocks = DomainBlock.paginate(page: params[:page], per_page: 40) - end +module Admin + class DomainBlocksController < BaseController + def index + @blocks = DomainBlock.page(params[:page]) + end - def new - @domain_block = DomainBlock.new - end + def new + @domain_block = DomainBlock.new + end - def create - @domain_block = DomainBlock.new(resource_params) + def create + @domain_block = DomainBlock.new(resource_params) - if @domain_block.save - DomainBlockWorker.perform_async(@domain_block.id) - redirect_to admin_domain_blocks_path, notice: 'Domain block is now being processed' - else - render action: :new + if @domain_block.save + DomainBlockWorker.perform_async(@domain_block.id) + redirect_to admin_domain_blocks_path, notice: 'Domain block is now being processed' + else + render action: :new + end end - end - private + private - def resource_params - params.require(:domain_block).permit(:domain, :severity) + def resource_params + params.require(:domain_block).permit(:domain, :severity) + end end end diff --git a/app/controllers/admin/pubsubhubbub_controller.rb b/app/controllers/admin/pubsubhubbub_controller.rb index b9e840ffe..31c80a174 100644 --- a/app/controllers/admin/pubsubhubbub_controller.rb +++ b/app/controllers/admin/pubsubhubbub_controller.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -class Admin::PubsubhubbubController < ApplicationController - before_action :require_admin! - - layout 'admin' - - def index - @subscriptions = Subscription.order('id desc').includes(:account).paginate(page: params[:page], per_page: 40) +module Admin + class PubsubhubbubController < BaseController + def index + @subscriptions = Subscription.order('id desc').includes(:account).page(params[:page]) + end end end diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 2b3b1809f..3c3082318 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -1,45 +1,44 @@ # frozen_string_literal: true -class Admin::ReportsController < ApplicationController - before_action :require_admin! - before_action :set_report, except: [:index] - - layout 'admin' - - def index - @reports = Report.includes(:account, :target_account).order('id desc').paginate(page: params[:page], per_page: 40) - @reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved - end - - def show - @statuses = Status.where(id: @report.status_ids) - end - - def resolve - @report.update(action_taken: true, action_taken_by_account_id: current_account.id) - redirect_to admin_report_path(@report) - end - - def suspend - Admin::SuspensionWorker.perform_async(@report.target_account.id) - Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) - redirect_to admin_report_path(@report) - end - - def silence - @report.target_account.update(silenced: true) - Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) - redirect_to admin_report_path(@report) - end - - def remove - RemovalWorker.perform_async(params[:status_id]) - redirect_to admin_report_path(@report) - end - - private - - def set_report - @report = Report.find(params[:id]) +module Admin + class ReportsController < BaseController + before_action :set_report, except: [:index] + + def index + @reports = Report.includes(:account, :target_account).order('id desc').page(params[:page]) + @reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved + end + + def show + @statuses = Status.where(id: @report.status_ids) + end + + def resolve + @report.update(action_taken: true, action_taken_by_account_id: current_account.id) + redirect_to admin_report_path(@report) + end + + def suspend + Admin::SuspensionWorker.perform_async(@report.target_account.id) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) + redirect_to admin_report_path(@report) + end + + def silence + @report.target_account.update(silenced: true) + Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id) + redirect_to admin_report_path(@report) + end + + def remove + RemovalWorker.perform_async(params[:status_id]) + redirect_to admin_report_path(@report) + end + + private + + def set_report + @report = Report.find(params[:id]) + end end end diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 7615c781d..6cca5c3e3 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,35 +1,33 @@ # frozen_string_literal: true -class Admin::SettingsController < ApplicationController - before_action :require_admin! - - layout 'admin' +module Admin + class SettingsController < BaseController + def index + @settings = Setting.all_as_records + end - def index - @settings = Setting.all_as_records - end + def update + @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id]) + value = settings_params[:value] - def update - @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id]) - value = settings_params[:value] + # Special cases + value = value == 'true' if @setting.var == 'open_registrations' - # Special cases - value = value == 'true' if @setting.var == 'open_registrations' + if @setting.value != value + @setting.value = value + @setting.save + end - if @setting.value != value - @setting.value = value - @setting.save + respond_to do |format| + format.html { redirect_to admin_settings_path } + format.json { respond_with_bip(@setting) } + end end - respond_to do |format| - format.html { redirect_to admin_settings_path } - format.json { respond_with_bip(@setting) } - end - end - - private + private - def settings_params - params.require(:setting).permit(:value) + def settings_params + params.require(:setting).permit(:value) + end end end diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 454873116..2c44e36a7 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true class Api::V1::AccountsController < ApiController - before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock, :mute, :unmute] + before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock, :mute, :unmute, :update_credentials] before_action -> { doorkeeper_authorize! :follow }, only: [:follow, :unfollow, :block, :unblock, :mute, :unmute] + before_action -> { doorkeeper_authorize! :write }, only: [:update_credentials] before_action :require_user!, except: [:show, :following, :followers, :statuses] - before_action :set_account, except: [:verify_credentials, :suggestions, :search] + before_action :set_account, except: [:verify_credentials, :update_credentials, :suggestions, :search] respond_to :json @@ -15,6 +16,12 @@ class Api::V1::AccountsController < ApiController render action: :show end + def update_credentials + current_account.update!(account_params) + @account = current_account + render action: :show + end + def following results = Follow.where(account: @account).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id]) accounts = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h @@ -135,4 +142,8 @@ class Api::V1::AccountsController < ApiController def statuses_pagination_params(core_params) params.permit(:limit, :only_media, :exclude_replies).merge(core_params) end + + def account_params + params.permit(:display_name, :note, :avatar, :header) + end end diff --git a/app/controllers/api/v1/notifications_controller.rb b/app/controllers/api/v1/notifications_controller.rb index 71c054334..3cff29982 100644 --- a/app/controllers/api/v1/notifications_controller.rb +++ b/app/controllers/api/v1/notifications_controller.rb @@ -9,7 +9,7 @@ class Api::V1::NotificationsController < ApiController DEFAULT_NOTIFICATIONS_LIMIT = 15 def index - @notifications = Notification.where(account: current_account).browserable.paginate_by_max_id(limit_param(DEFAULT_NOTIFICATIONS_LIMIT), params[:max_id], params[:since_id]) + @notifications = Notification.where(account: current_account).browserable(exclude_types).paginate_by_max_id(limit_param(DEFAULT_NOTIFICATIONS_LIMIT), params[:max_id], params[:since_id]) @notifications = cache_collection(@notifications, Notification) statuses = @notifications.select { |n| !n.target_status.nil? }.map(&:target_status) @@ -32,7 +32,13 @@ class Api::V1::NotificationsController < ApiController private + def exclude_types + val = params.permit(exclude_types: [])[:exclude_types] || [] + val = [val] unless val.is_a?(Enumerable) + val + end + def pagination_params(core_params) - params.permit(:limit).merge(core_params) + params.permit(:limit, exclude_types: []).merge(core_params) end end diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index db16f82e5..57604f1dc 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -7,6 +7,7 @@ class ApiController < ApplicationController protect_from_forgery with: :null_session skip_before_action :verify_authenticity_token + skip_before_action :store_current_location before_action :set_rate_limit_headers diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb index 6528ce45e..bcf3fd0a0 100644 --- a/app/controllers/concerns/localized.rb +++ b/app/controllers/concerns/localized.rb @@ -26,6 +26,8 @@ module Localized end def default_locale - ENV.fetch('DEFAULT_LOCALE') { I18n.default_locale } + ENV.fetch('DEFAULT_LOCALE') { + http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale + } end end diff --git a/app/controllers/remote_follow_controller.rb b/app/controllers/remote_follow_controller.rb index 1e3f786ec..22e376836 100644 --- a/app/controllers/remote_follow_controller.rb +++ b/app/controllers/remote_follow_controller.rb @@ -25,7 +25,7 @@ class RemoteFollowController < ApplicationController session[:remote_follow] = @remote_follow.acct - redirect_to Addressable::Template.new(redirect_url_link.template).expand(uri: "#{@account.username}@#{Rails.configuration.x.local_domain}").to_s + redirect_to Addressable::Template.new(redirect_url_link.template).expand(uri: @account.to_webfinger_s).to_s else render :new end diff --git a/app/controllers/settings/exports_controller.rb b/app/controllers/settings/exports_controller.rb index 4fcec5322..ff688978c 100644 --- a/app/controllers/settings/exports_controller.rb +++ b/app/controllers/settings/exports_controller.rb @@ -39,7 +39,7 @@ class Settings::ExportsController < ApplicationController def accounts_list_to_csv(list) CSV.generate do |csv| list.each do |account| - csv << [(account.local? ? "#{account.username}@#{Rails.configuration.x.local_domain}" : account.acct)] + csv << [(account.local? ? account.local_username_and_domain : account.acct)] end end end diff --git a/app/controllers/xrd_controller.rb b/app/controllers/xrd_controller.rb index 6db87cefc..5964172e9 100644 --- a/app/controllers/xrd_controller.rb +++ b/app/controllers/xrd_controller.rb @@ -14,7 +14,7 @@ class XrdController < ApplicationController def webfinger @account = Account.find_local!(username_from_resource) - @canonical_account_uri = "acct:#{@account.username}@#{Rails.configuration.x.local_domain}" + @canonical_account_uri = @account.to_webfinger_s @magic_key = pem_to_magic_key(@account.keypair.public_key) respond_to do |format| |