scimaenaga 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,
@@ -48,4 +50,11 @@ class User < ApplicationRecord
48
50
  write_attribute(:archived_at, nil)
49
51
  save!
50
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
51
60
  end
@@ -12,6 +12,9 @@ ScimRails.configure do |config|
12
12
  config.signing_algorithm = "HS256"
13
13
  config.signing_secret = "2d6806dd11c2fece2e81b8ca76dcb0062f5b08e28e3264e8ba1c44bbd3578b70"
14
14
 
15
+ config.user_destroy_method = :destroy!
16
+ config.group_destroy_method = :destroy!
17
+
15
18
  config.mutable_user_attributes = [
16
19
  :first_name,
17
20
  :last_name,
Binary file
@@ -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: 2022_01_17_095407) 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
@@ -46,6 +46,7 @@ ActiveRecord::Schema.define(version: 2022_01_17_095407) do
46
46
  t.datetime "created_at", null: false
47
47
  t.datetime "updated_at", null: false
48
48
  t.string "country"
49
+ t.boolean "deletable"
49
50
  end
50
51
 
51
52
  add_foreign_key "group_users", "groups"
@@ -9,11 +9,20 @@ group = Group.create(
9
9
  name: 'Test Group'
10
10
  )
11
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
+
12
20
  1.upto(1000) do |n|
13
21
  User.create(
14
22
  company: company,
15
23
  first_name: "Test#{n}",
16
24
  last_name: "User#{n}",
17
- email: "#{n}@example.com"
25
+ email: "#{n}@example.com",
26
+ deletable: true
18
27
  )
19
28
  end
Binary file
File without changes