Module: HasHelpers::Concerns::RestrictionsParseable
- Included in:
- UserRestrictions
- Defined in:
- lib/has_helpers/concerns/restrictions_parseable.rb
Overview
Shared parsing logic for the restrictions_hash stored on user_organizations.
The field arrives as a single-encoded JSON string: hqadmin stores it via
RestrictionsAndPermissions#restrictions which does .to_json, and that
string is what the data sync delivers (hqadmin's own serialize unwraps the
extra layer before sending). So a single JSON.parse is enough — this mirrors
how readygop consumes it (user_resource.rb: JSON.parse(restrictions_hash || "{}")).
We also accept a Hash as-is in case the column is jsonb.
The .to_json at the source is the real defect (the field should hold an
object); fixing it there is tracked in a separate ticket. Until then we just
parse the string once.
Canonical format is a JSON object keyed by resource name:
{"Client" => {...}, "Team" => {...}}
(The Array form handled by normalize_restrictions is a deprecated/bad-data
shape — confirmed not a supported format — kept only as fail-closed defense.)