Commit e58a5e24 authored by James Lopez's avatar James Lopez

Refactor URL display logic

parent adbb8233
......@@ -12,8 +12,9 @@ class Groups::SamlProvidersController < Groups::ApplicationController
def show
@saml_provider = @group.saml_provider || @group.build_saml_provider
@scim_token_exists = ScimOauthAccessToken.exists?(group: @group)
@scim_token_url = group_scim_oauth_url(@group)
scim_token = ScimOauthAccessToken.find_by_group_id(@group.id)
@scim_token_url = scim_token.as_entity_json[:scim_api_url] if scim_token
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -15,7 +15,7 @@ class Groups::ScimOauthController < Groups::ApplicationController
respond_to do |format|
format.json do
if scim_token
render json: ScimOauthAccessTokenEntity.new(scim_token).as_json
render json: scim_token.as_entity_json
else
render json: {}
end
......@@ -36,7 +36,7 @@ class Groups::ScimOauthController < Groups::ApplicationController
respond_to do |format|
format.json do
if scim_token.valid?
render json: ScimOauthAccessTokenEntity.new(scim_token).as_json
render json: scim_token.as_entity_json
else
render json: { errors: scim_token.errors.full_messages }, status: :unprocessable_entity
end
......
......@@ -9,4 +9,8 @@ class ScimOauthAccessToken < ApplicationRecord
validates :group, presence: true
before_save :ensure_token
def as_entity_json
ScimOauthAccessTokenEntity.new(self).as_json
end
end
......@@ -79,21 +79,21 @@ describe Groups::SamlProvidersController do
expect(response).to render_template 'groups/saml_providers/show'
end
it 'has the SCIM token URL' do
it 'has no SCIM token URL' do
group.add_owner(user)
subject
expect(assigns(:scim_token_url)).to eq('http://test.host/groups/group1/-/scim_oauth')
expect(assigns(:scim_token_url)).to be_nil
end
it 'sets scim_token_exists if SCIM token is found' do
it 'has the SCIM token URL when it exists' do
create(:scim_oauth_access_token, group: group)
group.add_owner(user)
subject
expect(assigns(:scim_token_exists)).to be true
expect(assigns(:scim_token_url)).to eq("http://localhost/api/scim/v2/groups/#{group.full_path}")
end
context 'not on a top level group', :nested_groups do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment