JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Alternate solution for raising `JSONAPI::Exceptions::InvalidFieldValue` in `replace_fields`?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I'm currently using a callback before save to handle authorization.
module V1
class BaseResource < JSONAPI::Resource
# ...
set_callback :save, :before, :authorize
# ...
end
end
I verify that authorization has been performed on each action in the ApplicationController:
class ApplicationController < JSONAPI::ResourceController
# ...
after_action :verify_policy_authorized, except: [:index]
def verify_policy_authorized
raise PolicyAuthorizationNotPerformedError unless policy_authorized?
end
# ...
end
Unfortunately, if an invalid value is submitted for an enum attribute the before save callback never happens because a JSONAPI::Exceptions::InvalidFieldValue is raised in _replace_fields. This causes verify_policy_authorized to not be called which raises the PolicyAuthorizationNotPerformedError.
I could obviously hack in a fix, but I wondered if this was a sign that a more general approach would be better. For example, should we provide a hook into exceptions raised and rescued which would allow the user of jsonapi-resources to handle things like bypassing policy authorization?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den Enum-Validierungspfad durch _replace_fields und JSONAPI::Exceptions::InvalidFieldValue nachzuverfolgen, und prüfe anschließend den Save-Callback in V1::BaseResource sowie verify_policy_authorized in ApplicationController. Der Issue schlägt einen allgemeinen Exception-Hook vor, definiert jedoch weder das Verhalten des Hooks noch einen konkreten Completion-Test.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rails, ruby
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100