about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/accounts_controller.rb48
-rw-r--r--app/controllers/admin/silences_controller.rb23
-rw-r--r--app/controllers/admin/suspensions_controller.rb23
-rw-r--r--app/controllers/settings/exports/base_controller.rb2
-rw-r--r--app/controllers/settings/exports/blocked_accounts_controller.rb4
-rw-r--r--app/controllers/settings/exports/following_accounts_controller.rb4
-rw-r--r--app/controllers/settings/exports/muted_accounts_controller.rb4
-rw-r--r--app/controllers/settings/exports_controller.rb5
-rw-r--r--app/controllers/well_known/host_meta_controller.rb13
-rw-r--r--app/controllers/well_known/webfinger_controller.rb43
-rw-r--r--app/controllers/xrd_controller.rb55
11 files changed, 124 insertions, 100 deletions
diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb
index 71cb8edd8..0e9e52f42 100644
--- a/app/controllers/admin/accounts_controller.rb
+++ b/app/controllers/admin/accounts_controller.rb
@@ -2,49 +2,29 @@
 
 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
+      @accounts = filtered_accounts.page(params[:page])
     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
+    def show
+      @account = Account.find(params[:id])
     end
 
     private
 
-    def set_account
-      @account = Account.find(params[:id])
+    def filtered_accounts
+      AccountFilter.new(filter_params).results
     end
 
-    def account_params
-      params.require(:account).permit(:silenced, :suspended)
+    def filter_params
+      params.permit(
+        :local,
+        :remote,
+        :by_domain,
+        :silenced,
+        :recent,
+        :suspended
+      )
     end
   end
 end
diff --git a/app/controllers/admin/silences_controller.rb b/app/controllers/admin/silences_controller.rb
new file mode 100644
index 000000000..81a3008b9
--- /dev/null
+++ b/app/controllers/admin/silences_controller.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Admin
+  class SilencesController < BaseController
+    before_action :set_account
+
+    def create
+      @account.update(silenced: true)
+      redirect_to admin_accounts_path
+    end
+
+    def destroy
+      @account.update(silenced: false)
+      redirect_to admin_accounts_path
+    end
+
+    private
+
+    def set_account
+      @account = Account.find(params[:account_id])
+    end
+  end
+end
diff --git a/app/controllers/admin/suspensions_controller.rb b/app/controllers/admin/suspensions_controller.rb
new file mode 100644
index 000000000..5d9048d94
--- /dev/null
+++ b/app/controllers/admin/suspensions_controller.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Admin
+  class SuspensionsController < BaseController
+    before_action :set_account
+
+    def create
+      Admin::SuspensionWorker.perform_async(@account.id)
+      redirect_to admin_accounts_path
+    end
+
+    def destroy
+      @account.update(suspended: false)
+      redirect_to admin_accounts_path
+    end
+
+    private
+
+    def set_account
+      @account = Account.find(params[:account_id])
+    end
+  end
+end
diff --git a/app/controllers/settings/exports/base_controller.rb b/app/controllers/settings/exports/base_controller.rb
index 0b790959f..c082ed806 100644
--- a/app/controllers/settings/exports/base_controller.rb
+++ b/app/controllers/settings/exports/base_controller.rb
@@ -6,7 +6,7 @@ module Settings
       before_action :authenticate_user!
 
       def index
-        export_data = Export.new(export_accounts).to_csv
+        @export = Export.new(current_account)
 
         respond_to do |format|
           format.csv { send_data export_data, filename: export_filename }
diff --git a/app/controllers/settings/exports/blocked_accounts_controller.rb b/app/controllers/settings/exports/blocked_accounts_controller.rb
index 9c4bcaa53..f1115b21e 100644
--- a/app/controllers/settings/exports/blocked_accounts_controller.rb
+++ b/app/controllers/settings/exports/blocked_accounts_controller.rb
@@ -5,8 +5,8 @@ module Settings
     class BlockedAccountsController < BaseController
       private
 
-      def export_accounts
-        current_account.blocking
+      def export_data
+        @export.to_blocked_accounts_csv
       end
     end
   end
diff --git a/app/controllers/settings/exports/following_accounts_controller.rb b/app/controllers/settings/exports/following_accounts_controller.rb
index 8d06bcc95..0011d2463 100644
--- a/app/controllers/settings/exports/following_accounts_controller.rb
+++ b/app/controllers/settings/exports/following_accounts_controller.rb
@@ -5,8 +5,8 @@ module Settings
     class FollowingAccountsController < BaseController
       private
 
-      def export_accounts
-        current_account.following
+      def export_data
+        @export.to_following_accounts_csv
       end
     end
   end
diff --git a/app/controllers/settings/exports/muted_accounts_controller.rb b/app/controllers/settings/exports/muted_accounts_controller.rb
index a77a9af6d..dfe72cfcb 100644
--- a/app/controllers/settings/exports/muted_accounts_controller.rb
+++ b/app/controllers/settings/exports/muted_accounts_controller.rb
@@ -5,8 +5,8 @@ module Settings
     class MutedAccountsController < BaseController
       private
 
-      def export_accounts
-        current_account.muting
+      def export_data
+        @export.to_muted_accounts_csv
       end
     end
   end
diff --git a/app/controllers/settings/exports_controller.rb b/app/controllers/settings/exports_controller.rb
index 77dea3231..ae62f00c1 100644
--- a/app/controllers/settings/exports_controller.rb
+++ b/app/controllers/settings/exports_controller.rb
@@ -6,9 +6,6 @@ class Settings::ExportsController < ApplicationController
   before_action :authenticate_user!
 
   def show
-    @total_storage = current_account.media_attachments.sum(:file_file_size)
-    @total_follows = current_account.following.count
-    @total_blocks  = current_account.blocking.count
-    @total_mutes = current_account.muting.count
+    @export = Export.new(current_account)
   end
 end
diff --git a/app/controllers/well_known/host_meta_controller.rb b/app/controllers/well_known/host_meta_controller.rb
new file mode 100644
index 000000000..2f0960acd
--- /dev/null
+++ b/app/controllers/well_known/host_meta_controller.rb
@@ -0,0 +1,13 @@
+  # frozen_string_literal: true
+
+module WellKnown
+  class HostMetaController < ApplicationController
+    def show
+      @webfinger_template = "#{webfinger_url}?resource={uri}"
+
+      respond_to do |format|
+        format.xml { render content_type: 'application/xrd+xml' }
+      end
+    end
+  end
+end
diff --git a/app/controllers/well_known/webfinger_controller.rb b/app/controllers/well_known/webfinger_controller.rb
new file mode 100644
index 000000000..1a8ef5f90
--- /dev/null
+++ b/app/controllers/well_known/webfinger_controller.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module WellKnown
+  class WebfingerController < ApplicationController
+    def show
+      @account = Account.find_local!(username_from_resource)
+      @canonical_account_uri = @account.to_webfinger_s
+      @magic_key = pem_to_magic_key(@account.keypair.public_key)
+
+      respond_to do |format|
+        format.xml  { render content_type: 'application/xrd+xml' }
+        format.json { render content_type: 'application/jrd+json' }
+      end
+    rescue ActiveRecord::RecordNotFound
+      head 404
+    end
+
+    private
+
+    def username_from_resource
+      WebfingerResource.new(resource_param).username
+    end
+
+    def pem_to_magic_key(public_key)
+      modulus, exponent = [public_key.n, public_key.e].map do |component|
+        result = []
+
+        until component.zero?
+          result << [component % 256].pack('C')
+          component >>= 8
+        end
+
+        result.reverse.join
+      end
+
+      (['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
+    end
+
+    def resource_param
+      params.require(:resource)
+    end
+  end
+end
diff --git a/app/controllers/xrd_controller.rb b/app/controllers/xrd_controller.rb
deleted file mode 100644
index 2886315ac..000000000
--- a/app/controllers/xrd_controller.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-class XrdController < ApplicationController
-  before_action :set_default_format_xml, only: :host_meta
-
-  def host_meta
-    @webfinger_template = "#{webfinger_url}?resource={uri}"
-
-    respond_to do |format|
-      format.xml { render content_type: 'application/xrd+xml' }
-    end
-  end
-
-  def webfinger
-    @account = Account.find_local!(username_from_resource)
-    @canonical_account_uri = @account.to_webfinger_s
-    @magic_key = pem_to_magic_key(@account.keypair.public_key)
-
-    respond_to do |format|
-      format.xml  { render content_type: 'application/xrd+xml' }
-      format.json { render content_type: 'application/jrd+json' }
-    end
-  rescue ActiveRecord::RecordNotFound
-    head 404
-  end
-
-  private
-
-  def set_default_format_xml
-    request.format = 'xml' if request.headers['HTTP_ACCEPT'].nil? && params[:format].nil?
-  end
-
-  def username_from_resource
-    WebfingerResource.new(resource_param).username
-  end
-
-  def pem_to_magic_key(public_key)
-    modulus, exponent = [public_key.n, public_key.e].map do |component|
-      result = []
-
-      until component.zero?
-        result << [component % 256].pack('C')
-        component >>= 8
-      end
-
-      result.reverse.join
-    end
-
-    (['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
-  end
-
-  def resource_param
-    params.require(:resource)
-  end
-end