diff --git a/app/controllers/api/v1/accounts/agents_controller.rb b/app/controllers/api/v1/accounts/agents_controller.rb index 7cdd6dbb5..85a05fbc1 100644 --- a/app/controllers/api/v1/accounts/agents_controller.rb +++ b/app/controllers/api/v1/accounts/agents_controller.rb @@ -17,11 +17,11 @@ class Api::V1::Accounts::AgentsController < Api::BaseController def update @agent.update!(agent_params.except(:role)) @agent.current_account_user.update!(role: agent_params[:role]) if agent_params[:role] - render 'api/v1/models/user.json', locals: { resource: @agent } + render partial: 'api/v1/models/agent.json.jbuilder', locals: { resource: @agent } end def create - render 'api/v1/models/user.json', locals: { resource: @user } + render partial: 'api/v1/models/agent.json.jbuilder', locals: { resource: @user } end private diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index 9a0bbfc17..bd415ffeb 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -2,7 +2,7 @@ class Api::V1::ProfilesController < Api::BaseController before_action :set_user def show - render json: @user + render partial: 'api/v1/models/user.json.jbuilder', locals: { resource: @user } end def update diff --git a/app/views/api/v1/accounts/agents/index.json.jbuilder b/app/views/api/v1/accounts/agents/index.json.jbuilder index 0b6a01f1c..8374ce793 100644 --- a/app/views/api/v1/accounts/agents/index.json.jbuilder +++ b/app/views/api/v1/accounts/agents/index.json.jbuilder @@ -1,10 +1,3 @@ json.array! @agents do |agent| - json.account_id agent.account.id - json.availability_status agent.availability_status - json.confirmed agent.confirmed? - json.email agent.email - json.id agent.id - json.name agent.name - json.role agent.role - json.thumbnail agent.avatar_url + json.partial! 'api/v1/models/agent.json.jbuilder', resource: agent end diff --git a/app/views/api/v1/models/_agent.json.jbuilder b/app/views/api/v1/models/_agent.json.jbuilder new file mode 100644 index 000000000..a53b1f2cc --- /dev/null +++ b/app/views/api/v1/models/_agent.json.jbuilder @@ -0,0 +1,8 @@ +json.account_id resource.account.id +json.availability_status resource.availability_status +json.confirmed resource.confirmed? +json.email resource.email +json.id resource.id +json.name resource.name +json.role resource.role +json.thumbnail resource.avatar_url diff --git a/app/views/api/v1/models/_user.json.jbuilder b/app/views/api/v1/models/_user.json.jbuilder new file mode 100644 index 000000000..4fdacf14a --- /dev/null +++ b/app/views/api/v1/models/_user.json.jbuilder @@ -0,0 +1,21 @@ +json.id resource.id +json.provider resource.provider +json.uid resource.uid +json.name resource.name +json.nickname resource.nickname +json.email resource.email +json.account_id resource.active_account_user.account_id +json.pubsub_token resource.pubsub_token +json.role resource.active_account_user.role +json.inviter_id resource.active_account_user.inviter_id +json.confirmed resource.confirmed? +json.avatar_url resource.avatar_url +json.access_token resource.access_token.token +json.accounts do + json.array! resource.account_users do |account_user| + json.id account_user.account_id + json.name account_user.account.name + json.active_at account_user.active_at + json.role account_user.role + end +end diff --git a/app/views/api/v1/models/user.json.jbuilder b/app/views/api/v1/models/user.json.jbuilder deleted file mode 100644 index d12a35657..000000000 --- a/app/views/api/v1/models/user.json.jbuilder +++ /dev/null @@ -1,12 +0,0 @@ -json.id resource.id -json.provider resource.provider -json.uid resource.uid -json.name resource.name -json.nickname resource.nickname -json.email resource.email -json.account_id resource.current_account_user.account_id -json.pubsub_token resource.pubsub_token -json.role resource.current_account_user.role -json.inviter_id resource.current_account_user.inviter_id -json.confirmed resource.confirmed? -json.avatar_url resource.avatar_url diff --git a/app/views/api/v1/profiles/update.json.jbuilder b/app/views/api/v1/profiles/update.json.jbuilder index f4eef3516..5a6dc2dad 100644 --- a/app/views/api/v1/profiles/update.json.jbuilder +++ b/app/views/api/v1/profiles/update.json.jbuilder @@ -1,9 +1 @@ -json.id @user.id -json.provider @user.provider -json.uid @user.uid -json.name @user.name -json.nickname @user.nickname -json.email @user.email -json.pubsub_token @user.pubsub_token -json.confirmed @user.confirmed? -json.avatar_url @user.avatar_url +json.partial! 'api/v1/models/user.json.jbuilder', resource: @user diff --git a/app/views/devise/_auth.json.jbuilder b/app/views/devise/_auth.json.jbuilder index a5035d7a1..3c8c11d52 100644 --- a/app/views/devise/_auth.json.jbuilder +++ b/app/views/devise/_auth.json.jbuilder @@ -1,22 +1,3 @@ json.data do - json.id resource.id - json.provider resource.provider - json.uid resource.uid - json.name resource.name - json.nickname resource.nickname - json.email resource.email - json.account_id resource.active_account_user.account_id - json.pubsub_token resource.pubsub_token - json.role resource.active_account_user.role - json.inviter_id resource.active_account_user.inviter_id - json.confirmed resource.confirmed? - json.avatar_url resource.avatar_url - json.accounts do - json.array! resource.account_users do |account_user| - json.id account_user.account_id - json.name account_user.account.name - json.active_at account_user.active_at - json.role account_user.role - end - end + json.partial! 'api/v1/models/user.json.jbuilder', resource: resource end diff --git a/spec/controllers/api/v1/accounts/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts/accounts_controller_spec.rb index 30bffd9f2..17eea3043 100644 --- a/spec/controllers/api/v1/accounts/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/accounts_controller_spec.rb @@ -70,8 +70,10 @@ RSpec.describe 'Accounts API', type: :request do headers: { api_access_token: super_admin.access_token.token }, as: :json - expect(User.find_by(email: email).confirmed?).to eq(true) + created_user = User.find_by(email: email) + expect(created_user.confirmed?).to eq(true) expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid') + expect(response.body).to include(created_user.access_token.token) end end diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 9355177ed..a2226d68b 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -24,6 +24,7 @@ RSpec.describe 'Profile API', type: :request do json_response = JSON.parse(response.body) expect(json_response['id']).to eq(agent.id) expect(json_response['email']).to eq(agent.email) + expect(json_response['access_token']).to eq(agent.access_token.token) end end end