Commit 8141fc87 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'dblessing-move-scim-api-entities' into 'master'

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

See merge request gitlab-org/gitlab!26706
parents b6fb4a98 ec0a3cb0
...@@ -34,15 +34,15 @@ module API ...@@ -34,15 +34,15 @@ module API
end end
def scim_not_found!(message:) def scim_not_found!(message:)
render_scim_error(EE::Gitlab::Scim::NotFound, message) render_scim_error(::EE::API::Entities::Scim::NotFound, message)
end end
def scim_error!(message:) def scim_error!(message:)
render_scim_error(EE::Gitlab::Scim::Error, message) render_scim_error(::EE::API::Entities::Scim::Error, message)
end end
def scim_conflict!(message:) def scim_conflict!(message:)
render_scim_error(EE::Gitlab::Scim::Conflict, message) render_scim_error(::EE::API::Entities::Scim::Conflict, message)
end end
def check_access_to_group!(group) def check_access_to_group!(group)
...@@ -65,7 +65,7 @@ module API ...@@ -65,7 +65,7 @@ module API
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def update_scim_user(identity) def update_scim_user(identity)
parser = EE::Gitlab::Scim::ParamsParser.new(params) parser = ::EE::Gitlab::Scim::ParamsParser.new(params)
parsed_hash = parser.update_params parsed_hash = parser.update_params
if parser.deprovision_user? if parser.deprovision_user?
...@@ -107,7 +107,7 @@ module API ...@@ -107,7 +107,7 @@ module API
status 200 status 200
result_set = { resources: response_page, total_results: results.count, items_per_page: per_page(params[:count]), start_index: params[:startIndex] } 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 rescue ScimFinder::UnsupportedFilter
scim_error!(message: 'Unsupported Filter') scim_error!(message: 'Unsupported Filter')
end end
...@@ -124,7 +124,7 @@ module API ...@@ -124,7 +124,7 @@ module API
status 200 status 200
present identity, with: ::EE::Gitlab::Scim::User present identity, with: ::EE::API::Entities::Scim::User
end end
desc 'Create a SAML user' do desc 'Create a SAML user' do
...@@ -132,14 +132,14 @@ module API ...@@ -132,14 +132,14 @@ module API
end end
post do post do
group = find_and_authenticate_group!(params[:group]) group = find_and_authenticate_group!(params[:group])
parser = EE::Gitlab::Scim::ParamsParser.new(params) parser = ::EE::Gitlab::Scim::ParamsParser.new(params)
result = EE::Gitlab::Scim::ProvisioningService.new(group, parser.post_params).execute result = ::EE::Gitlab::Scim::ProvisioningService.new(group, parser.post_params).execute
case result.status case result.status
when :success when :success
status 201 status 201
present result.identity, with: ::EE::Gitlab::Scim::User present result.identity, with: ::EE::API::Entities::Scim::User
when :conflict when :conflict
scim_conflict!(message: "Error saving user with #{params.inspect}: #{result.message}") scim_conflict!(message: "Error saving user with #{params.inspect}: #{result.message}")
when :error when :error
......
# frozen_string_literal: true # frozen_string_literal: true
module EE module EE
module Gitlab module API
module Entities
module Scim module Scim
class Conflict < Error class Conflict < Error
STATUS = 409 STATUS = 409
end end
end end
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 # frozen_string_literal: true
module EE module EE
module Gitlab module API
module Entities
module Scim module Scim
class NotFound < EE::Gitlab::Scim::Error class NotFound < Error
STATUS = 404 STATUS = 404
end end
end end
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 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ::EE::Gitlab::Scim::Conflict do describe ::EE::API::Entities::Scim::Conflict do
let(:params) { { detail: 'error' } } let(:params) { { detail: 'error' } }
let(:entity) do let(:entity) do
described_class.new(params) described_class.new(params)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ::EE::Gitlab::Scim::Emails do describe ::EE::API::Entities::Scim::Emails do
let(:user) { build(:user) } let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: user) } let(:identity) { build(:group_saml_identity, user: user) }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ::EE::Gitlab::Scim::Error do describe ::EE::API::Entities::Scim::Error do
let(:params) { { detail: 'error' } } let(:params) { { detail: 'error' } }
let(:entity) do let(:entity) do
described_class.new(params) described_class.new(params)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ::EE::Gitlab::Scim::NotFound do describe ::EE::API::Entities::Scim::NotFound do
let(:entity) do let(:entity) do
described_class.new({}) described_class.new({})
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ::EE::Gitlab::Scim::User do describe ::EE::API::Entities::Scim::User do
let(:user) { build(:user) } let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: user) } let(:identity) { build(:group_saml_identity, user: user) }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe ::EE::Gitlab::Scim::Users do describe ::EE::API::Entities::Scim::Users do
let(:user) { build(:user) } let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: 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