Skip to content

Commit be4f9ff

Browse files
committed
Add an /identity.json endpoint to obtain the identity accounts and users
1 parent 9d89967 commit be4f9ff

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class IdentitiesController < ApplicationController
2+
disallow_account_scope
3+
4+
def show
5+
@identity = Current.identity
6+
end
7+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
json.cache! account do
2+
json.(account, :id, :name, :external_account_id)
3+
json.created_at account.created_at.utc
4+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
json.accounts @identity.users do |user|
2+
json.partial! "identities/account", account: user.account
3+
json.user do
4+
json.partial! "users/user", user: user
5+
end
6+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@
170170

171171
resource :landing
172172

173+
resource :identity, only: :show
174+
173175
namespace :my do
174176
resources :access_tokens
175177
resources :pins

test/controllers/api_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ class ApiTest < ActionDispatch::IntegrationTest
7070
assert_equal users(:david).name, @response.parsed_body["name"]
7171
end
7272

73+
test "get identity" do
74+
identity = identities(:david)
75+
76+
get identity_path(format: :json), env: @davids_bearer_token
77+
assert_response :success # Fix 302 redirect
78+
assert_equal identity.accounts.count, @response.parsed_body["accounts"].count
79+
end
80+
7381
private
7482
def bearer_token_env(token)
7583
{ "HTTP_AUTHORIZATION" => "Bearer #{token}" }

0 commit comments

Comments
 (0)