Commit 1cec65d0 authored by James Lopez's avatar James Lopez

Add email and users entities

parent a652a631
# 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 User < Grape::Entity
expose :schemas
expose :extern_uid, as: :id
expose :active
expose 'name.formatted' do |identity, _options|
identity.user.name
end
present_collection true, :email
expose :email_user, as: :emails, using: '::EE::Gitlab::Scim::Emails'
private
def schemas
["urn:ietf:params:scim:schemas:core:2.0:User"]
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
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe ::EE::Gitlab::Scim::Emails do
let(:user) { create(:user) }
let(:identity) { create(:group_saml_identity, user: user) }
let(:entity) do
described_class.new(user)
end
subject { entity.as_json }
it 'contains the email' do
expect(subject[:value]).to eq(user.email)
end
it 'contains the type' do
expect(subject[:type]).to eq('work')
end
it 'contains the email' do
expect(subject[:primary]).to be true
end
end
# frozen_string_literal: true
require 'spec_helper'
describe ::EE::Gitlab::Scim::User do
let(:user) { create(:user) }
let(:identity) { create(:group_saml_identity, user: user) }
let(:entity) do
described_class.new(identity)
end
subject { entity.as_json }
it 'contains the schemas' do
expect(subject[:schemas]).to eq(["urn:ietf:params:scim:schemas:core:2.0:User"])
end
it 'contains the extern UID' do
expect(subject[:id]).to eq(identity.extern_uid)
end
it 'contains the active flag' do
expect(subject[:active]).to be true
end
it 'contains the name' do
expect(subject[:'name.formatted']).to eq(user.name)
end
it 'contains the email' do
expect(subject[:emails].first[:value]).to eq(user.email)
end
end
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