JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Alternate solution for raising `JSONAPI::Exceptions::InvalidFieldValue` in `replace_fields`?
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Ruby
- Star
- 2.3k
- Fork
- 546
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách lần theo luồng xác thực enum qua _replace_fields và JSONAPI::Exceptions::InvalidFieldValue, sau đó xem xét callback lưu trong V1::BaseResource và verify_policy_authorized trong ApplicationController. Issue đề xuất một exception hook tổng quát, nhưng không định nghĩa hành vi của hook hoặc một completion test cụ thể.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- rails, ruby
- Lĩnh vực
- api, backend
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100