JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Alternate solution for raising `JSONAPI::Exceptions::InvalidFieldValue` in `replace_fields`?
还没有人认领这个 Issue。
- 主要语言
- Ruby
- 星标
- 2.3k
- 派生
- 546
- PR 合并指标
- 30 天内没有已合并 PR
描述
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?
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先沿着 _replace_fields 和 JSONAPI::Exceptions::InvalidFieldValue 跟踪 enum 验证路径,然后检查 V1::BaseResource 中的保存回调以及 ApplicationController 中的 verify_policy_authorized。该 issue 提议了一个通用的 exception hook,但没有定义 hook 的行为,也没有定义具体的完成测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rails, ruby
- 领域
- api, backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100