Skip to content

Use authorized_scope within controllers#851

Merged
jmilljr24 merged 17 commits intomainfrom
additonal-policy-stuff
Feb 7, 2026
Merged

Use authorized_scope within controllers#851
jmilljr24 merged 17 commits intomainfrom
additonal-policy-stuff

Conversation

@jmilljr24
Copy link
Collaborator

  • This work Closes [link an issue]

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

Relation scopes were set up in policies. This uses them in the controllers.

How did you approach the change?

Anything else to add?

@jmilljr24 jmilljr24 changed the title Use authorized_scope withing controllers Use authorized_scope within controllers Feb 5, 2026
if current_user.super_user?
WorkshopLog.all
else
WorkshopLog.where(created_by_id: current_user.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this filter get lost? i don't think it's in the policy

Copy link
Collaborator Author

@jmilljr24 jmilljr24 Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going off the policy and comment I left off the by project_id since we need have the table change coming and there are a bunch more scope this policy will need to filter the search filters if we filter on org as well.

  relation_scope do |relation|
    next relation if admin?
    relation.where(user: user) # TODO - maybe also allow users to see peers' within same organization
  end

I do notice now that the scope for user should be on created_by_id.

It looks like WorkshopLog has user_id on it not created_by_id so the relation_scope was correct.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha re project!

the report/workshop_log models are actually still user_id. so we must've never tested as non-admin.


it "populates workshops dropdown with only workshops from visible logs" do
# TODO use action policy to filter
xit "populates workshops dropdown with only workshops from visible logs" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was wrong w this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to scope all the dropdowns. I think it should be its own separate PR. We are disabling workshop logs for this phase right? So this can be lower priority?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workshop_logs are in scope. it's the workshop_idea he wants us to hide for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OoOOOOH ok. I will open a separate issue for the scoped filters.

@@ -20,7 +20,7 @@ def manage?
# Define shared methods useful for most policies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i found note somewhere of adding scope_matcher :relation, ActiveRecord::Relation to ApplicationPolicy and after_action :verify_authorized, except: :index to validate that the indexes are using the scopes. not sure if you'd want to do that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ApplicationController I have verify_authorized commented out and ready to go once we think we have every policy done and and proper. That makes sure every controller action has a policy checked going forward.

I'll have to look into the scope stuff and see if/what makes sense for us. Thanks for pointing it out.

@jmilljr24 jmilljr24 force-pushed the additonal-policy-stuff branch from f90c40b to 04e8f5f Compare February 7, 2026 01:13
@jmilljr24 jmilljr24 merged commit fef0845 into main Feb 7, 2026
3 checks passed
@jmilljr24 jmilljr24 deleted the additonal-policy-stuff branch February 7, 2026 13:03
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