Class: TwoPercent::ScimController
Instance Method Summary
collapse
#validate_patch_operations!
#authenticate
Instance Method Details
#create ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/two_percent/scim_controller.rb', line 7
def create
record = with_scim_logging("create") do
record = persist_scim_record(scim_params)
record = reload_with_members(record)
publish_created_event(record)
record
end
render json: record.to_scim_representation, status: :created, location: scim_resource_url(record)
end
|
#destroy ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/controllers/two_percent/scim_controller.rb', line 90
def destroy
scim_id = with_scim_logging("delete") do
record = find_scim_record(params[:id])
scim_id = record.scim_id
model_class.destroy_by_scim_id(scim_id)
publish_deleted_event(scim_id)
scim_id
end
head :no_content
end
|
#index ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'app/controllers/two_percent/scim_controller.rb', line 124
def index
validate_resource_type!
log_scim_operation("list", "start")
scope = build_query_scope
total_count = scope.count
paginated_scope = (scope)
records = load_records_with_associations(paginated_scope)
list_response = build_list_response(records, total_count)
log_scim_operation("list", "complete")
render json: list_response, status: :ok
end
|
#replace ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/two_percent/scim_controller.rb', line 62
def replace
was_new = !model_class.exists_by_scim_id?(params[:id])
record = with_scim_logging("replace") do
record = upsert_scim_record(params[:id], scim_params)
record = reload_with_members(record)
if was_new
publish_created_event(record)
else
publish_updated_event(record)
end
record
end
if was_new
render json: record.to_scim_representation, status: :created, location: scim_resource_url(record)
else
render json: record.to_scim_representation, status: :ok
end
end
|
#show ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/controllers/two_percent/scim_controller.rb', line 109
def show
validate_resource_type!
record = with_scim_logging("get") do
record = find_scim_record(params[:id])
reload_with_members(record)
end
render json: record.to_scim_representation, status: :ok
end
|
#update ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/two_percent/scim_controller.rb', line 25
def update
record = with_scim_logging("update") do
record = find_scim_record(params[:id])
record.scim_data["members"] = record.members_for_patch if group_resource?
validate_patch_operations!(params[:resource_type], scim_params) if user_resource?
processor = TwoPercent::Scim::PatchProcessor.new(scim_params)
current_scim_data = record.scim_data || {}
patched_data = processor.apply_to_hash(current_scim_data)
patched_data["id"] = params[:id] updated_record = persist_scim_record(patched_data)
updated_record = reload_with_members(updated_record) if user_resource? || should_reload_members?(updated_record)
publish_updated_event(updated_record)
updated_record
end
render json: record.to_scim_representation, status: :ok
end
|