Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

What is the goal of this PR and why is this important?

ActionPolicy gem was added but incompletely applied to the Resource model. Missing authorization checks on controller actions and incomplete policy rules created potential security gaps.

How did you approach the change?

Controller Authorization

  • Added authorize! to new and search actions (previously missing)
  • All 9 ResourcesController actions now properly authorize

Policy Rules

  • Added create?, search?, stories? rules
  • Aliased related actions: create?/search? → new?, stories? → index?
  • Rules enforce: public (index, stories, download), admin-only (new, create, search, filter_published), owner-or-admin (update, edit, destroy), conditional (show: admins or published resources)
  • Relation scope filters resources by user role (admins see all, users see published)

Draper Integration

  • ActionPolicy::Draper module in lib/action_policy/draper.rb unwraps decorators before policy checks
  • Prepended in ApplicationController

Testing

  • 152 test cases covering all policy rules and scopes
  • Tests verify admin, owner, regular user permissions
  • ActionPolicy RSpec DSL configured in spec/support/action_policy.rb

Anything else to add?

Views already use allowed_to? helper correctly. ApplicationController has proper error handling via rescue_from ActionPolicy::Unauthorized.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add authorization checks to all controller actions (new, search)
- Add missing policy rules (create?, search?, stories?)
- Write comprehensive policy tests covering all rules and scopes
- Add ActionPolicy RSpec support
- Verify Draper decorator integration is working

Co-authored-by: maebeale <7607813+maebeale@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ActionPolicy gem and apply it to resources Complete ActionPolicy implementation for Resource model Jan 19, 2026
Copilot AI requested a review from maebeale January 19, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants