Class: Lyra::PrivacyController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lyra/privacy_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#petri_flow_available?, #user_tracking_configured?

Instance Method Details

#data_lineage ⇒ Object

GET /lyra/privacy/data_lineage/:field_name



80
81
82
83
84
85
86
87
88
# File 'app/controllers/lyra/privacy_controller.rb', line 80

def data_lineage
  field_name = params[:field_name]
  model_class = params[:model_class]

  flow = EventFlow.new
  lineage = flow.data_lineage(field_name, model_class)

  render json: lineage
end

#gdpr_report ⇒ Object

GET /lyra/privacy/gdpr_report/:subject_type/:subject_id



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/lyra/privacy_controller.rb', line 23

def gdpr_report
  subject_type = params[:subject_type]
  subject_id = params[:subject_id]

  compliance = Privacy::GDPRCompliance.new(
    subject_id: subject_id,
    subject_type: subject_type
  )

  render json: {
    subject: { type: subject_type, id: subject_id },
    right_to_access: compliance.data_export,
    right_to_be_forgotten: compliance.right_to_be_forgotten_report,
    rectification_history: compliance.rectification_history,
    processing_activities: compliance.processing_activities,
    retention_compliance: compliance.retention_compliance_check,
    consent_audit: compliance.consent_audit
  }
end

#pii_detection ⇒ Object

GET /lyra/privacy/pii_detection



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/lyra/privacy_controller.rb', line 99

def pii_detection
  # Detect PII across all events
  events = Lyra.config.event_store.read.to_a
  @pii_inventory = extract_pii_from_events(events)

  @total_events = events.count
  @events_with_pii = events.count { |e| Privacy::PIIDetector.detect(event_attributes(e)).any? }
  @pii_categories = @pii_inventory.keys
  @sensitive_pii = @pii_inventory.select { |k, _|
    [:ssn, :credit_card, :health, :biometric].include?(k)
  }.keys
  @contact_pii = @pii_inventory.select { |k, _|
    [:email, :phone, :address].include?(k)
  }.keys

  respond_to do |format|
    format.html
    format.json do
      render json: {
        total_events: @total_events,
        events_with_pii: @events_with_pii,
        pii_categories: @pii_categories,
        pii_inventory: @pii_inventory,
        summary: {
          sensitive_pii: @sensitive_pii,
          contact_pii: @contact_pii
        }
      }
    end
  end
end

#pii_inventory ⇒ Object

GET /lyra/privacy/pii_inventory/:subject_type/:subject_id



69
70
71
72
73
74
75
76
77
# File 'app/controllers/lyra/privacy_controller.rb', line 69

def pii_inventory
  subject_type = params[:subject_type]
  subject_id = params[:subject_id]

  flow = EventFlow.new(subject_id: subject_id, subject_type: subject_type)
  data = flow.privacy_impact_analysis

  render json: data
end

#policy ⇒ Object

GET /lyra/privacy/policy



91
92
93
94
95
96
# File 'app/controllers/lyra/privacy_controller.rb', line 91

def policy
  @pam_dsl_available = pam_dsl_available?
  @policies = @pam_dsl_available && PamDsl.respond_to?(:registry) ? PamDsl.registry.policies : {}
  @default_policy_name = Rails.application.config.respond_to?(:pam_dsl) ?
    Rails.application.config.pam_dsl.default_policy : nil
end

#portable_export ⇒ Object

GET /lyra/privacy/portable_export/:subject_type/:subject_id



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/lyra/privacy_controller.rb', line 44

def portable_export
  subject_type = params[:subject_type]
  subject_id = params[:subject_id]
  format = params[:format]&.to_sym || :json

  compliance = Privacy::GDPRCompliance.new(
    subject_id: subject_id,
    subject_type: subject_type
  )

  data = compliance.portable_export(format: format)

  case format
  when :json
    render json: data
  when :csv
    send_data data, filename: "data_export_#{subject_id}.csv", type: 'text/csv'
  when :xml
    send_data data, filename: "data_export_#{subject_id}.xml", type: 'application/xml'
  else
    render json: { error: "Unsupported format" }, status: :bad_request
  end
end

#subject_data ⇒ Object

GET /lyra/privacy/subject/:subject_type/:subject_id



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/lyra/privacy_controller.rb', line 6

def subject_data
  subject_type = params[:subject_type]
  subject_id = params[:subject_id]

  compliance = Privacy::GDPRCompliance.new(
    subject_id: subject_id,
    subject_type: subject_type
  )

  render json: {
    subject: { type: subject_type, id: subject_id },
    data_export: compliance.data_export,
    generated_at: Time.current
  }
end