Commit 120b074ae60eda469bd5339110121855dc8f7be9
Committed by
GitHub
Exists in
master
Merge pull request #5 from lessonly/kylewerner/ch21748/scim-update-group-assignment
Allow the create endpoint to find and update users
Showing
4 changed files
with
23 additions
and
16 deletions
Show diff stats
Gemfile.lock
1 | 1 | PATH |
2 | 2 | remote: . |
3 | 3 | specs: |
4 | - scim_rails (0.1.3) | |
4 | + scim_rails (0.1.4) | |
5 | 5 | rails (~> 5.0.0) |
6 | 6 | |
7 | 7 | GEM |
... | ... | @@ -56,7 +56,7 @@ GEM |
56 | 56 | factory_bot_rails (4.11.1) |
57 | 57 | factory_bot (~> 4.11.1) |
58 | 58 | railties (>= 3.0.0) |
59 | - globalid (0.4.1) | |
59 | + globalid (0.4.2) | |
60 | 60 | activesupport (>= 4.2.0) |
61 | 61 | i18n (1.2.0) |
62 | 62 | concurrent-ruby (~> 1.0) | ... | ... |
app/controllers/scim_rails/scim_users_controller.rb
... | ... | @@ -27,7 +27,13 @@ module ScimRails |
27 | 27 | end |
28 | 28 | |
29 | 29 | def create |
30 | - user = @company.public_send(ScimRails.config.scim_users_scope).create!(permitted_user_params) | |
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) | |
31 | 37 | update_status(user) unless put_active_param.nil? |
32 | 38 | json_scim_response(object: user, status: :created) |
33 | 39 | end | ... | ... |
lib/scim_rails/version.rb
spec/controllers/scim_rails/scim_users_controller_spec.rb
... | ... | @@ -11,7 +11,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
11 | 11 | context "when unauthorized" do |
12 | 12 | it "returns scim+json content type" do |
13 | 13 | get :index |
14 | - | |
14 | + | |
15 | 15 | expect(response.content_type).to eq "application/scim+json, application/json" |
16 | 16 | end |
17 | 17 | |
... | ... | @@ -37,7 +37,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
37 | 37 | |
38 | 38 | it "returns scim+json content type" do |
39 | 39 | get :index |
40 | - | |
40 | + | |
41 | 41 | expect(response.content_type).to eq "application/scim+json, application/json" |
42 | 42 | end |
43 | 43 | |
... | ... | @@ -146,7 +146,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
146 | 146 | context "when unauthorized" do |
147 | 147 | it "returns scim+json content type" do |
148 | 148 | get :show, params: { id: 1 } |
149 | - | |
149 | + | |
150 | 150 | expect(response.content_type).to eq "application/scim+json, application/json" |
151 | 151 | end |
152 | 152 | |
... | ... | @@ -172,7 +172,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
172 | 172 | |
173 | 173 | it "returns scim+json content type" do |
174 | 174 | get :show, params: { id: 1 } |
175 | - | |
175 | + | |
176 | 176 | expect(response.content_type).to eq "application/scim+json, application/json" |
177 | 177 | end |
178 | 178 | |
... | ... | @@ -207,7 +207,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
207 | 207 | context "when unauthorized" do |
208 | 208 | it "returns scim+json content type" do |
209 | 209 | post :create |
210 | - | |
210 | + | |
211 | 211 | expect(response.content_type).to eq "application/scim+json, application/json" |
212 | 212 | end |
213 | 213 | |
... | ... | @@ -305,12 +305,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
305 | 305 | expect(company.users.count).to eq 0 |
306 | 306 | end |
307 | 307 | |
308 | - it "returns 409 if user already exists" do | |
308 | + it "returns 201 if user already exists and updates user" do | |
309 | 309 | create(:user, email: "new@example.com", company: company) |
310 | 310 | |
311 | 311 | post :create, params: { |
312 | 312 | name: { |
313 | - givenName: "New", | |
313 | + givenName: "Not New", | |
314 | 314 | familyName: "User" |
315 | 315 | }, |
316 | 316 | emails: [ |
... | ... | @@ -320,8 +320,9 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
320 | 320 | ] |
321 | 321 | } |
322 | 322 | |
323 | - expect(response.status).to eq 409 | |
323 | + expect(response.status).to eq 201 | |
324 | 324 | expect(company.users.count).to eq 1 |
325 | + expect(company.users.first.first_name).to eq "Not New" | |
325 | 326 | end |
326 | 327 | |
327 | 328 | it "creates and archives inactive user" do |
... | ... | @@ -355,7 +356,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
355 | 356 | context "when unauthorized" do |
356 | 357 | it "returns scim+json content type" do |
357 | 358 | put :put_update, params: { id: 1 } |
358 | - | |
359 | + | |
359 | 360 | expect(response.content_type).to eq "application/scim+json, application/json" |
360 | 361 | end |
361 | 362 | |
... | ... | @@ -383,7 +384,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
383 | 384 | |
384 | 385 | it "returns scim+json content type" do |
385 | 386 | put :put_update, params: put_params |
386 | - | |
387 | + | |
387 | 388 | expect(response.content_type).to eq "application/scim+json, application/json" |
388 | 389 | end |
389 | 390 | |
... | ... | @@ -450,7 +451,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
450 | 451 | context "when unauthorized" do |
451 | 452 | it "returns scim+json content type" do |
452 | 453 | patch :patch_update, params: patch_params(id: 1) |
453 | - | |
454 | + | |
454 | 455 | expect(response.content_type).to eq "application/scim+json, application/json" |
455 | 456 | end |
456 | 457 | |
... | ... | @@ -478,7 +479,7 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do |
478 | 479 | |
479 | 480 | it "returns scim+json content type" do |
480 | 481 | patch :patch_update, params: patch_params(id: 1) |
481 | - | |
482 | + | |
482 | 483 | expect(response.content_type).to eq "application/scim+json, application/json" |
483 | 484 | end |
484 | 485 | ... | ... |