scimaenaga 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -0
  3. data/README.md +2 -14
  4. data/app/controllers/concerns/scim_rails/exception_handler.rb +43 -1
  5. data/app/controllers/scim_rails/scim_groups_controller.rb +64 -40
  6. data/app/controllers/scim_rails/scim_users_controller.rb +39 -65
  7. data/app/libraries/scim_patch.rb +15 -10
  8. data/app/libraries/scim_patch_operation.rb +127 -24
  9. data/app/models/scim_rails/scim_query_parser.rb +5 -3
  10. data/config/routes.rb +2 -0
  11. data/lib/generators/scim_rails/templates/initializer.rb +0 -6
  12. data/lib/scim_rails/config.rb +1 -2
  13. data/lib/scim_rails/version.rb +1 -1
  14. data/spec/controllers/scim_rails/scim_groups_controller_spec.rb +249 -136
  15. data/spec/controllers/scim_rails/scim_users_controller_spec.rb +413 -203
  16. data/spec/dummy/app/models/user.rb +21 -0
  17. data/spec/dummy/bin/setup +2 -0
  18. data/spec/dummy/config/initializers/scim_rails_config.rb +6 -4
  19. data/spec/dummy/db/development.sqlite3 +0 -0
  20. data/spec/dummy/db/migrate/20220117095407_add_country_to_users.rb +5 -0
  21. data/spec/dummy/db/migrate/20220131090107_add_deletable_to_users.rb +5 -0
  22. data/spec/dummy/db/schema.rb +7 -5
  23. data/spec/dummy/db/seeds.rb +15 -1
  24. data/spec/dummy/db/test.sqlite3 +0 -0
  25. data/spec/dummy/log/development.log +0 -0
  26. data/spec/dummy/log/test.log +5770 -0
  27. data/spec/dummy/put_group.http +5 -0
  28. data/spec/dummy/tmp/restart.txt +0 -0
  29. data/spec/factories/user.rb +2 -0
  30. data/spec/libraries/scim_patch_operation_spec.rb +61 -31
  31. data/spec/libraries/scim_patch_spec.rb +38 -29
  32. data/spec/models/scim_query_parser_spec.rb +30 -0
  33. metadata +83 -67
  34. data/spec/support/scim_rails_config.rb +0 -59
@@ -3,6 +3,8 @@ class User < ApplicationRecord
3
3
  has_many :group_users
4
4
  has_many :groups, through: :group_users
5
5
 
6
+ before_destroy :check_deletable
7
+
6
8
  validates \
7
9
  :first_name,
8
10
  :last_name,
@@ -15,6 +17,18 @@ class User < ApplicationRecord
15
17
  case_insensitive: true
16
18
  }
17
19
 
20
+ def active
21
+ return active?
22
+ end
23
+
24
+ def active=(active)
25
+ if active
26
+ self.archived_at = nil
27
+ else
28
+ self.archived_at ||= Time.now
29
+ end
30
+ end
31
+
18
32
  def active?
19
33
  archived_at.blank?
20
34
  end
@@ -36,4 +50,11 @@ class User < ApplicationRecord
36
50
  write_attribute(:archived_at, nil)
37
51
  save!
38
52
  end
53
+
54
+ def check_deletable
55
+ return if deletable
56
+
57
+ errors.add(:base, 'The specified user could not be deleted.')
58
+ throw :abort
59
+ end
39
60
  end
data/spec/dummy/bin/setup CHANGED
@@ -22,6 +22,8 @@ chdir APP_ROOT do
22
22
  # unless File.exist?('config/database.yml')
23
23
  # cp 'config/database.yml.sample', 'config/database.yml'
24
24
  # end
25
+ puts "\n== Reset migration =="
26
+ system! 'bin/rails db:migrate:reset'
25
27
 
26
28
  puts "\n== Preparing database =="
27
29
  system! 'bin/rails db:setup'
@@ -12,13 +12,14 @@ ScimRails.configure do |config|
12
12
  config.signing_algorithm = "HS256"
13
13
  config.signing_secret = "2d6806dd11c2fece2e81b8ca76dcb0062f5b08e28e3264e8ba1c44bbd3578b70"
14
14
 
15
- config.user_deprovision_method = :archive!
16
- config.user_reprovision_method = :unarchive!
15
+ config.user_destroy_method = :destroy!
16
+ config.group_destroy_method = :destroy!
17
17
 
18
18
  config.mutable_user_attributes = [
19
19
  :first_name,
20
20
  :last_name,
21
- :email
21
+ :email,
22
+ :active
22
23
  ]
23
24
 
24
25
  config.queryable_user_attributes = {
@@ -37,7 +38,8 @@ ScimRails.configure do |config|
37
38
  {
38
39
  value: :email
39
40
  }
40
- ]
41
+ ],
42
+ active: :active
41
43
  }
42
44
 
43
45
  config.user_schema = {
Binary file
@@ -0,0 +1,5 @@
1
+ class AddCountryToUsers < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :users, :country, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddDeletableToUsers < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :users, :deletable, :boolean
4
+ end
5
+ end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2021_04_23_075950) do
13
+ ActiveRecord::Schema.define(version: 2022_01_31_090107) do
14
14
 
15
15
  create_table "companies", force: :cascade do |t|
16
16
  t.string "name", null: false
@@ -23,8 +23,8 @@ ActiveRecord::Schema.define(version: 2021_04_23_075950) do
23
23
  create_table "group_users", force: :cascade do |t|
24
24
  t.integer "group_id", null: false
25
25
  t.integer "user_id", null: false
26
- t.datetime "created_at", precision: 6, null: false
27
- t.datetime "updated_at", precision: 6, null: false
26
+ t.datetime "created_at", null: false
27
+ t.datetime "updated_at", null: false
28
28
  t.index ["group_id"], name: "index_group_users_on_group_id"
29
29
  t.index ["user_id"], name: "index_group_users_on_user_id"
30
30
  end
@@ -32,8 +32,8 @@ ActiveRecord::Schema.define(version: 2021_04_23_075950) do
32
32
  create_table "groups", force: :cascade do |t|
33
33
  t.string "name", null: false
34
34
  t.integer "company_id", null: false
35
- t.datetime "created_at", precision: 6, null: false
36
- t.datetime "updated_at", precision: 6, null: false
35
+ t.datetime "created_at", null: false
36
+ t.datetime "updated_at", null: false
37
37
  t.index ["company_id"], name: "index_groups_on_company_id"
38
38
  end
39
39
 
@@ -45,6 +45,8 @@ ActiveRecord::Schema.define(version: 2021_04_23_075950) do
45
45
  t.datetime "archived_at"
46
46
  t.datetime "created_at", null: false
47
47
  t.datetime "updated_at", null: false
48
+ t.string "country"
49
+ t.boolean "deletable"
48
50
  end
49
51
 
50
52
  add_foreign_key "group_users", "groups"
@@ -4,11 +4,25 @@ company = Company.create(
4
4
  api_token: 1
5
5
  )
6
6
 
7
+ group = Group.create(
8
+ company: company,
9
+ name: 'Test Group'
10
+ )
11
+
12
+ User.create(
13
+ company: company,
14
+ first_name: 'scim',
15
+ last_name: 'owner',
16
+ email: 'owner@example.com',
17
+ deletable: false
18
+ )
19
+
7
20
  1.upto(1000) do |n|
8
21
  User.create(
9
22
  company: company,
10
23
  first_name: "Test#{n}",
11
24
  last_name: "User#{n}",
12
- email: "#{n}@example.com"
25
+ email: "#{n}@example.com",
26
+ deletable: true
13
27
  )
14
28
  end
Binary file
File without changes