about summary refs log tree commit diff
path: root/app/controllers/api/v1/directories_controller.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-08-30 00:14:36 +0200
committerGitHub <noreply@github.com>2019-08-30 00:14:36 +0200
commitcb447b28c403c7db32e3e3d7c2510004287edfda (patch)
tree5bf7b38a977107857407ba7e9d03044eb0c1534a /app/controllers/api/v1/directories_controller.rb
parent7802ebd5f3de1ef4b7384f24fe5067977aff8da3 (diff)
Add profile directory to web UI (#11688)
* Add profile directory to web UI

* Add a line of bio to the directory
Diffstat (limited to 'app/controllers/api/v1/directories_controller.rb')
-rw-r--r--app/controllers/api/v1/directories_controller.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/controllers/api/v1/directories_controller.rb b/app/controllers/api/v1/directories_controller.rb
new file mode 100644
index 000000000..c91543e3a
--- /dev/null
+++ b/app/controllers/api/v1/directories_controller.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class Api::V1::DirectoriesController < Api::BaseController
+  before_action :require_enabled!
+  before_action :set_accounts
+
+  def show
+    render json: @accounts, each_serializer: REST::AccountSerializer
+  end
+
+  private
+
+  def require_enabled!
+    return not_found unless Setting.profile_directory
+  end
+
+  def set_accounts
+    @accounts = accounts_scope.offset(params[:offset]).limit(limit_param(DEFAULT_ACCOUNTS_LIMIT))
+  end
+
+  def accounts_scope
+    Account.discoverable.tap do |scope|
+      scope.merge!(Account.local)                                          if truthy_param?(:local)
+      scope.merge!(Account.by_recent_status)                               if params[:order].blank? || params[:order] == 'active'
+      scope.merge!(Account.order(id: :desc))                               if params[:order] == 'new'
+      scope.merge!(Account.not_excluded_by_account(current_account))       if current_account
+      scope.merge!(Account.not_domain_blocked_by_account(current_account)) if current_account && !truthy_param?(:local)
+    end
+  end
+end