Commit ec0a3cb0 authored by Drew Blessing's avatar Drew Blessing Committed by Drew Blessing

Move SCIM API Grape Entities into ::EE::API::Entities namespace

The SCIM API Grape Entities were in an unexpected/nonstandard
location. This moves them into the expected namespace so these
entities are consistent with others and to make them easier to
maintain.
parent 589d96a3
......@@ -34,15 +34,15 @@ module API
end
def scim_not_found!(message:)
render_scim_error(EE::Gitlab::Scim::NotFound, message)
render_scim_error(::EE::API::Entities::Scim::NotFound, message)
end
def scim_error!(message:)
render_scim_error(EE::Gitlab::Scim::Error, message)
render_scim_error(::EE::API::Entities::Scim::Error, message)
end
def scim_conflict!(message:)
render_scim_error(EE::Gitlab::Scim::Conflict, message)
render_scim_error(::EE::API::Entities::Scim::Conflict, message)
end
def check_access_to_group!(group)
......@@ -65,7 +65,7 @@ module API
# rubocop: disable CodeReuse/ActiveRecord
def update_scim_user(identity)
parser = EE::Gitlab::Scim::ParamsParser.new(params)
parser = ::EE::Gitlab::Scim::ParamsParser.new(params)
parsed_hash = parser.update_params
if parser.deprovision_user?
......@@ -107,7 +107,7 @@ module API
status 200
result_set = { resources: response_page, total_results: results.count, items_per_page: per_page(params[:count]), start_index: params[:startIndex] }
present result_set, with: ::EE::Gitlab::Scim::Users
present result_set, with: ::EE::API::Entities::Scim::Users
rescue ScimFinder::UnsupportedFilter
scim_error!(message: 'Unsupported Filter')
end
......@@ -124,7 +124,7 @@ module API
status 200
present identity, with: ::EE::Gitlab::Scim::User
present identity, with: ::EE::API::Entities::Scim::User
end
desc 'Create a SAML user' do
......@@ -132,14 +132,14 @@ module API
end
post do
group = find_and_authenticate_group!(params[:group])
parser = EE::Gitlab::Scim::ParamsParser.new(params)
result = EE::Gitlab::Scim::ProvisioningService.new(group, parser.post_params).execute
parser = ::EE::Gitlab::Scim::ParamsParser.new(params)
result = ::EE::Gitlab::Scim::ProvisioningService.new(group, parser.post_params).execute
case result.status
when :success
status 201
present result.identity, with: ::EE::Gitlab::Scim::User
present result.identity, with: ::EE::API::Entities::Scim::User
when :conflict
scim_conflict!(message: "Error saving user with #{params.inspect}: #{result.message}")
when :error
......
# frozen_string_literal: true
module EE
module Gitlab
module API
module Entities
module Scim
class Conflict < Error
STATUS = 409
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Scim
class Emails < Grape::Entity
expose :type
expose :value do |user, _options|
user.email
end
expose :primary
private
def type
'work'
end
def primary
true
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Scim
class Error < Grape::Entity
STATUS = 412
expose :schemas
expose :detail, safe: true
expose :status
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error'
def schemas
[DEFAULT_SCHEMA]
end
def status
self.class::STATUS
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module API
module Entities
module Scim
class NotFound < EE::Gitlab::Scim::Error
class NotFound < Error
STATUS = 404
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Scim
class User < Grape::Entity
expose :schemas
expose :extern_uid, as: :id
expose :active
expose :email_user, as: :emails, using: ::EE::API::Entities::Scim::Emails
expose 'name.formatted' do |identity, _options|
identity.user.name
end
expose :meta do
expose :resource_type, as: :resourceType
end
expose :username, as: :userName do |identity, _options|
identity.user.username
end
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:User'
def schemas
[DEFAULT_SCHEMA]
end
def active
# We don't block the user yet when deprovisioning
# So the user is always active, until the identity link is removed.
true
end
def email_type
'work'
end
def email_primary
true
end
def email_user
[object.user]
end
def resource_type
'User'
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Scim
class Users < Grape::Entity
expose :schemas
expose :total_results, as: :totalResults
expose :items_per_page, as: :itemsPerPage
expose :start_index, as: :startIndex
expose :resources, as: :Resources, using: ::EE::API::Entities::Scim::User
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:ListResponse'
def schemas
[DEFAULT_SCHEMA]
end
def total_results
object[:total_results] || resources.count
end
def items_per_page
object[:items_per_page] || Kaminari.config.default_per_page
end
def start_index
object[:start_index].presence || 1
end
def resources
object[:resources] || []
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Scim
class Emails < Grape::Entity
expose :type
expose :value do |user, _options|
user.email
end
expose :primary
private
def type
'work'
end
def primary
true
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Scim
class Error < Grape::Entity
STATUS = 412
expose :schemas
expose :detail, safe: true
expose :status
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error'
def schemas
[DEFAULT_SCHEMA]
end
def status
self.class::STATUS
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Scim
class User < Grape::Entity
expose :schemas
expose :extern_uid, as: :id
expose :active
expose :email_user, as: :emails, using: '::EE::Gitlab::Scim::Emails'
expose 'name.formatted' do |identity, _options|
identity.user.name
end
expose :meta do
expose :resource_type, as: :resourceType
end
expose :username, as: :userName do |identity, _options|
identity.user.username
end
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:User'
def schemas
[DEFAULT_SCHEMA]
end
def active
# We don't block the user yet when deprovisioning
# So the user is always active, until the identity link is removed.
true
end
def email_type
'work'
end
def email_primary
true
end
def email_user
[object.user]
end
def resource_type
'User'
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Scim
class Users < Grape::Entity
expose :schemas
expose :total_results, as: :totalResults
expose :items_per_page, as: :itemsPerPage
expose :start_index, as: :startIndex
expose :resources, as: :Resources, using: ::EE::Gitlab::Scim::User
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:ListResponse'
def schemas
[DEFAULT_SCHEMA]
end
def total_results
object[:total_results] || resources.count
end
def items_per_page
object[:items_per_page] || Kaminari.config.default_per_page
end
def start_index
object[:start_index].presence || 1
end
def resources
object[:resources] || []
end
end
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe ::EE::Gitlab::Scim::Conflict do
describe ::EE::API::Entities::Scim::Conflict do
let(:params) { { detail: 'error' } }
let(:entity) do
described_class.new(params)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe ::EE::Gitlab::Scim::Emails do
describe ::EE::API::Entities::Scim::Emails do
let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: user) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe ::EE::Gitlab::Scim::Error do
describe ::EE::API::Entities::Scim::Error do
let(:params) { { detail: 'error' } }
let(:entity) do
described_class.new(params)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe ::EE::Gitlab::Scim::NotFound do
describe ::EE::API::Entities::Scim::NotFound do
let(:entity) do
described_class.new({})
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe ::EE::Gitlab::Scim::User do
describe ::EE::API::Entities::Scim::User do
let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: user) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe ::EE::Gitlab::Scim::Users do
describe ::EE::API::Entities::Scim::Users do
let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: user) }
......
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