Class: TwoPercent::ScimController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- TwoPercent::ScimController
- Defined in:
- app/controllers/two_percent/scim_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/two_percent/scim_controller.rb', line 5 def create log_scim_operation("create", "start") # Persist to two_percent tables first (validates SCIM schema) record = persist_scim_record(scim_params) # Reload with associations for domain event and response record = reload_with_members(record) # Publish domain event (not SCIM-specific) publish_created_event(record) log_scim_operation("create", "complete", record.scim_id) # RFC 7644: 201 Created with Location header and resource body response.headers["Location"] = scim_resource_url(record) render json: record.to_scim_representation, status: :created end |
#destroy ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/two_percent/scim_controller.rb', line 85 def destroy log_scim_operation("delete", "start") # Find and destroy record record = find_scim_record(params[:id]) scim_id = record.scim_id # Destroy record if user_resource? TwoPercent::ScimUser.destroy_by_scim_id(scim_id) else TwoPercent::ScimGroup.destroy_by_scim_id(scim_id) end # Publish domain delete event publish_deleted_event(scim_id) log_scim_operation("delete", "complete", scim_id) # RFC 7644: 204 No Content head :no_content end |
#replace ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/two_percent/scim_controller.rb', line 51 def replace log_scim_operation("replace", "start") # Upsert record (create or replace) was_new = if user_resource? !TwoPercent::ScimUser.exists_by_scim_id?(params[:id]) else !TwoPercent::ScimGroup.exists_by_scim_id?(params[:id]) end record = upsert_scim_record(params[:id], scim_params) # Reload with associations for domain event and response record = reload_with_members(record) # Publish appropriate domain event if was_new publish_created_event(record) else publish_updated_event(record) end log_scim_operation("replace", "complete", record.scim_id) # RFC 7644: 201 Created (if new) or 200 OK (if replaced) if was_new response.headers["Location"] = scim_resource_url(record) render json: record.to_scim_representation, status: :created else render json: record.to_scim_representation, status: :ok end end |
#update ⇒ Object
24 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 |
# File 'app/controllers/two_percent/scim_controller.rb', line 24 def update log_scim_operation("update", "start") # Find existing record record = find_scim_record(params[:id]) # Apply SCIM PATCH operations (RFC 7644 compliance) processor = TwoPercent::Scim::PatchProcessor.new(scim_params) current_scim_data = record.scim_data || {} patched_data = processor.apply_to_hash(current_scim_data) # Persist patched data patched_data["id"] = params[:id] # Ensure ID is present updated_record = persist_scim_record(patched_data) # Reload with associations for domain event and response updated_record = reload_with_members(updated_record) # Publish domain event with final state publish_updated_event(updated_record) log_scim_operation("update", "complete", record.scim_id) # RFC 7644: 200 OK with updated resource body render json: updated_record.to_scim_representation, status: :ok end |