Add an /identity.json endpoint to obtain the identity accounts and users

This commit is contained in:
Jay Ohms
2025-12-04 10:52:21 -05:00
committed by Stanko K.R.
parent 9fceef16e9
commit 26fc9ecad4
5 changed files with 27 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
class IdentitiesController < ApplicationController
disallow_account_scope
def show
@identity = Current.identity
end
end
@@ -0,0 +1,4 @@
json.cache! account do
json.(account, :id, :name, :external_account_id)
json.created_at account.created_at.utc
end
+6
View File
@@ -0,0 +1,6 @@
json.accounts @identity.users do |user|
json.partial! "identities/account", account: user.account
json.user do
json.partial! "users/user", user: user
end
end
+2
View File
@@ -163,6 +163,8 @@ Rails.application.routes.draw do
resource :landing resource :landing
resource :identity, only: :show
namespace :my do namespace :my do
resources :access_tokens resources :access_tokens
resources :pins resources :pins
+8
View File
@@ -70,6 +70,14 @@ class ApiTest < ActionDispatch::IntegrationTest
assert_equal users(:david).name, @response.parsed_body["name"] assert_equal users(:david).name, @response.parsed_body["name"]
end end
test "get identity" do
identity = identities(:david)
get identity_path(format: :json), env: @davids_bearer_token
assert_response :success # Fix 302 redirect
assert_equal identity.accounts.count, @response.parsed_body["accounts"].count
end
private private
def bearer_token_env(token) def bearer_token_env(token)
{ "HTTP_AUTHORIZATION" => "Bearer #{token}" } { "HTTP_AUTHORIZATION" => "Bearer #{token}" }