scim_rails 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 325745eceb9f970c505d036231d3fde95674f05d220d65e02778e346013f44c1
4
- data.tar.gz: 2703cf04051e134870be167e9119ef7041b93fa5d77a5eedffb80bae2b707aff
3
+ metadata.gz: f2fdd85f73785a5e6f541f9d5ce4948f1881391215b55235480b398d64352c52
4
+ data.tar.gz: d1003817197e93ae0669250b8cdef586447890ed79cc76ebbed71ecb77308d81
5
5
  SHA512:
6
- metadata.gz: 73975ecfb6499a9a8e155d0817d81c9f8bd1f8c96070b21172610a06a620a46e1bf446a40fcf734f065fa6a1bf17d4b74857ab7443ede69694592f622e8fb6be
7
- data.tar.gz: caaa96d37fc4a7e11077afe889b7e0ddb1e7df1518d601552ff26fd471c94e157a7b5672a3f96eb0dae5f75fc66cedbd38b4f5b09d2b5b5365d7d4388a6fc532
6
+ metadata.gz: acd22821b645cf7d3aed942cdf061b0264318474c0af65aef1787c44c304cfc477b77616f527034da2e03e4cd1d3a637ce9710ea5527578e768031662b408fd2
7
+ data.tar.gz: dddf0587bd64c1202e9088b6967378187a595e3e2abb67ef853a7b13e02ef1505775aae0dfec436b5fbf14fe696c7173dad596f9356d9d95b56186b0c3d977f6
@@ -27,13 +27,17 @@ module ScimRails
27
27
  end
28
28
 
29
29
  def create
30
- username_key = ScimRails.config.queryable_user_attributes[:userName]
31
- find_by_username = Hash.new
32
- find_by_username[username_key] = permitted_user_params[username_key]
33
- user = @company
34
- .public_send(ScimRails.config.scim_users_scope)
35
- .find_or_create_by(find_by_username)
36
- user.update!(permitted_user_params)
30
+ if ScimRails.config.scim_user_prevent_update_on_create
31
+ user = @company.public_send(ScimRails.config.scim_users_scope).create!(permitted_user_params)
32
+ else
33
+ username_key = ScimRails.config.queryable_user_attributes[:userName]
34
+ find_by_username = Hash.new
35
+ find_by_username[username_key] = permitted_user_params[username_key]
36
+ user = @company
37
+ .public_send(ScimRails.config.scim_users_scope)
38
+ .find_or_create_by(find_by_username)
39
+ user.update!(permitted_user_params)
40
+ end
37
41
  update_status(user) unless put_active_param.nil?
38
42
  json_scim_response(object: user, status: :created)
39
43
  end
@@ -18,6 +18,10 @@ ScimRails.configure do |config|
18
18
  # authenticatable model.
19
19
  config.scim_users_scope = :users
20
20
 
21
+ # Determine whether the create endpoint updates users that already exist
22
+ # or throws an error (returning 409 Conflict in accordance with SCIM spec)
23
+ config.scim_user_prevent_update_on_create = false
24
+
21
25
  # Default sort order for pagination is by id. If you
22
26
  # use non sequential ids for user records, uncomment
23
27
  # the below line and configure a determinate order.
@@ -33,7 +37,7 @@ ScimRails.configure do |config|
33
37
  # Hash of queryable attribtues on the user model. If
34
38
  # the attribute is not listed in this hash it cannot
35
39
  # be queried by this Gem. The structure of this hash
36
- # is { queryable_scim_attribute => user_attribute }.
40
+ # is { queryable_scim_attribute => user_attribute }.
37
41
  config.queryable_user_attributes = {
38
42
  userName: :email,
39
43
  givenName: :first_name,
@@ -54,7 +58,7 @@ ScimRails.configure do |config|
54
58
  # for this Gem to figure out where to look in a SCIM
55
59
  # response for mutable values. This object should
56
60
  # include all attributes listed in
57
- # config.mutable_user_attributes.
61
+ # config.mutable_user_attributes.
58
62
  config.mutable_user_attributes_schema = {
59
63
  name: {
60
64
  givenName: :first_name,
@@ -20,11 +20,12 @@ module ScimRails
20
20
  :scim_users_list_order,
21
21
  :scim_users_model,
22
22
  :scim_users_scope,
23
+ :scim_user_prevent_update_on_create,
23
24
  :user_attributes,
24
25
  :user_deprovision_method,
25
26
  :user_reprovision_method,
26
27
  :user_schema
27
-
28
+
28
29
  def initialize
29
30
  @basic_auth_model = "Company"
30
31
  @scim_users_list_order = :id
@@ -1,3 +1,3 @@
1
1
  module ScimRails
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -325,6 +325,26 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
325
325
  expect(company.users.first.first_name).to eq "Not New"
326
326
  end
327
327
 
328
+ it "returns 409 if user already exists and config.scim_user_prevent_update_on_create is set to true" do
329
+ allow(ScimRails.config).to receive(:scim_user_prevent_update_on_create).and_return(true)
330
+ create(:user, email: "new@example.com", company: company)
331
+
332
+ post :create, params: {
333
+ name: {
334
+ givenName: "Not New",
335
+ familyName: "User"
336
+ },
337
+ emails: [
338
+ {
339
+ value: "new@example.com"
340
+ }
341
+ ]
342
+ }
343
+
344
+ expect(response.status).to eq 409
345
+ expect(company.users.count).to eq 1
346
+ end
347
+
328
348
  it "creates and archives inactive user" do
329
349
  post :create, params: {
330
350
  id: 1,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scim_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spencer Alan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-09 00:00:00.000000000 Z
11
+ date: 2019-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -178,14 +178,10 @@ files:
178
178
  - spec/dummy/config/routes.rb
179
179
  - spec/dummy/config/secrets.yml
180
180
  - spec/dummy/config/spring.rb
181
- - spec/dummy/db/development.sqlite3
182
181
  - spec/dummy/db/migrate/20181206184304_create_users.rb
183
182
  - spec/dummy/db/migrate/20181206184313_create_companies.rb
184
183
  - spec/dummy/db/schema.rb
185
184
  - spec/dummy/db/seeds.rb
186
- - spec/dummy/db/test.sqlite3
187
- - spec/dummy/log/development.log
188
- - spec/dummy/log/test.log
189
185
  - spec/dummy/public/404.html
190
186
  - spec/dummy/public/422.html
191
187
  - spec/dummy/public/500.html
@@ -278,12 +274,8 @@ test_files:
278
274
  - spec/dummy/public/apple-touch-icon-precomposed.png
279
275
  - spec/dummy/db/schema.rb
280
276
  - spec/dummy/db/seeds.rb
281
- - spec/dummy/db/test.sqlite3
282
277
  - spec/dummy/db/migrate/20181206184304_create_users.rb
283
278
  - spec/dummy/db/migrate/20181206184313_create_companies.rb
284
- - spec/dummy/db/development.sqlite3
285
- - spec/dummy/log/test.log
286
- - spec/dummy/log/development.log
287
279
  - spec/support/factory_bot.rb
288
280
  - spec/support/auth_helper.rb
289
281
  - spec/support/scim_rails_config.rb
Binary file
Binary file
@@ -1,37 +0,0 @@
1
-  (1.5ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "subdomain" varchar NOT NULL, "api_token" varchar NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
2
-  (0.9ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar NOT NULL, "last_name" varchar NOT NULL, "email" varchar NOT NULL, "company_id" integer, "archived_at" datetime, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
3
-  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
4
-  (0.1ms) SELECT version FROM "schema_migrations"
5
-  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES (20181206184313)
6
-  (0.1ms) select sqlite_version(*)
7
-  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES
8
- (20181206184304);
9
-
10
- 
11
-  (1.0ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
12
- ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
13
-  (0.0ms) begin transaction
14
- SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", "2019-04-04 18:34:57.670031"], ["updated_at", "2019-04-04 18:34:57.670031"]]
15
-  (0.7ms) commit transaction
16
- ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
17
-  (0.0ms) begin transaction
18
-  (0.0ms) commit transaction
19
-  (0.9ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL, "subdomain" varchar NOT NULL, "api_token" varchar NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
20
-  (1.0ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "first_name" varchar NOT NULL, "last_name" varchar NOT NULL, "email" varchar NOT NULL, "company_id" integer, "archived_at" datetime, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
21
-  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
22
-  (0.1ms) SELECT version FROM "schema_migrations"
23
-  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES (20181206184313)
24
-  (0.0ms) select sqlite_version(*)
25
-  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES
26
- (20181206184304);
27
-
28
- 
29
-  (0.9ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
30
- ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
31
-  (0.0ms) begin transaction
32
- SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", "2019-04-04 18:34:57.684014"], ["updated_at", "2019-04-04 18:34:57.684014"]]
33
-  (0.6ms) commit transaction
34
- ActiveRecord::InternalMetadata Load (0.1ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
35
-  (0.0ms) begin transaction
36
- SQL (0.2ms) UPDATE "ar_internal_metadata" SET "value" = ?, "updated_at" = ? WHERE "ar_internal_metadata"."key" = ? [["value", "test"], ["updated_at", "2019-04-04 18:34:57.686570"], ["key", "environment"]]
37
-  (0.6ms) commit transaction