DEV: Modify User model for SCIM
This commit is contained in:
parent
95c62e2941
commit
dafba8c0e1
6 changed files with 121 additions and 19 deletions
|
@ -1,11 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ::DiscourseScimPlugin
|
||||
class ScimController < ::ApplicationController
|
||||
requires_plugin PLUGIN_NAME
|
||||
|
||||
def index
|
||||
render json: { hello: "world" }
|
||||
end
|
||||
end
|
||||
end
|
21
app/controllers/scim_v2/groups_controller.rb
Normal file
21
app/controllers/scim_v2/groups_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "scimitar"
|
||||
|
||||
module Scim
|
||||
class ScimV2::GroupsController < Scimitar::ActiveRecordBackedResourcesController
|
||||
# requires_plugin PLUGIN_NAME
|
||||
protect_from_forgery with: :null_session
|
||||
|
||||
protected
|
||||
|
||||
def storage_class
|
||||
Group
|
||||
end
|
||||
|
||||
def storage_scope
|
||||
Group.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require
|
||||
end
|
||||
|
||||
end
|
||||
end
|
21
app/controllers/scim_v2/users_controller.rb
Normal file
21
app/controllers/scim_v2/users_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "scimitar"
|
||||
|
||||
module Scim
|
||||
class ScimV2::UsersController < Scimitar::ActiveRecordBackedResourcesController
|
||||
# requires_plugin PLUGIN_NAME
|
||||
protect_from_forgery with: :null_session
|
||||
|
||||
protected
|
||||
|
||||
def storage_class
|
||||
User
|
||||
end
|
||||
|
||||
def storage_scope
|
||||
User.all # Or e.g. "User.where(is_deleted: false)" - whatever base scope you require
|
||||
end
|
||||
|
||||
end
|
||||
end
|
9
config/initializers/scimitar.rb
Normal file
9
config/initializers/scimitar.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Rails.application.config.to_prepare do
|
||||
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
|
||||
token_authenticator: Proc.new do | token, options |
|
||||
true
|
||||
end
|
||||
})
|
||||
end
|
|
@ -7,18 +7,29 @@ require "scimitar"
|
|||
# end
|
||||
|
||||
# Discourse::Application.routes.draw { mount ::DiscourseScimPlugin::Engine, at: "/scim" }
|
||||
Discourse::Application.routes.draw {
|
||||
namespace :scim_v2 do
|
||||
# DiscourseScimPlugin::Engine.routes.draw do
|
||||
# get 'Users', to: 'users#index'
|
||||
# get 'Users/:id', to: 'users#show'
|
||||
# post 'Users', to: 'users#create'
|
||||
# put 'Users/:id', to: 'users#replace'
|
||||
# patch 'Users/:id', to: 'users#update'
|
||||
# delete 'Users/:id', to: 'users#destroy'
|
||||
# end
|
||||
|
||||
mount Scimitar::Engine, at: '/'
|
||||
|
||||
namespace :scim_v2 do
|
||||
DiscourseScimPlugin::Engine.routes.draw do
|
||||
get 'Users', to: 'users#index'
|
||||
get 'Users/:id', to: 'users#show'
|
||||
post 'Users', to: 'users#create'
|
||||
put 'Users/:id', to: 'users#replace'
|
||||
patch 'Users/:id', to: 'users#update'
|
||||
delete 'Users/:id', to: 'users#destroy'
|
||||
end
|
||||
|
||||
Discourse::Application.routes.draw {
|
||||
mount Scimitar::Engine, at: '/scim'
|
||||
}
|
||||
end
|
||||
get 'Groups', to: 'groups#index'
|
||||
get 'Groups/:id', to: 'groups#show'
|
||||
post 'Groups', to: 'groups#create'
|
||||
patch 'Groups/:id', to: 'groups#update'
|
||||
end
|
||||
}
|
||||
|
|
51
plugin.rb
51
plugin.rb
|
@ -23,3 +23,54 @@ module ::DiscourseScimPlugin
|
|||
|
||||
require_relative "lib/discourse_scim_plugin/engine"
|
||||
end
|
||||
|
||||
after_initialize do
|
||||
class ::User
|
||||
def self.scim_resource_type
|
||||
Scimitar::Resources::User
|
||||
end
|
||||
|
||||
def self.scim_attributes_map
|
||||
{
|
||||
id: :id,
|
||||
userName: :username,
|
||||
displayName: :name,
|
||||
name: {
|
||||
formatted: :name
|
||||
},
|
||||
emails: [
|
||||
{
|
||||
match: "type",
|
||||
with: "work",
|
||||
using: {
|
||||
value: :email,
|
||||
primary: true
|
||||
}
|
||||
}
|
||||
],
|
||||
active: :active
|
||||
}
|
||||
end
|
||||
|
||||
def self.scim_timestamps_map
|
||||
{
|
||||
created: :created_at,
|
||||
lastModified: :updated_at
|
||||
}
|
||||
end
|
||||
|
||||
def self.scim_mutable_attributes
|
||||
nil
|
||||
end
|
||||
|
||||
def self.scim_queryable_attributes
|
||||
{
|
||||
displayName: { column: :name },
|
||||
userName: { column: :username },
|
||||
emails: { column: :emails }
|
||||
}
|
||||
end
|
||||
|
||||
include Scimitar::Resources::Mixin
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue