Skip to content

Fix card grant settings action visibility - #14686

Open
code2344 wants to merge 8 commits into
hackclub:mainfrom
code2344:main
Open

Fix card grant settings action visibility#14686
code2344 wants to merge 8 commits into
hackclub:mainfrom
code2344:main

Conversation

@code2344

Copy link
Copy Markdown

Summary of the problem

initial help thread where i discovered it: slack thread
Card grant pages show a "View Grant Settings" button to all members of the organisation, regardless of if the user has the permission to edit grants.
Screenshot 2026-08-20 at 2 15 30鈥痯m
If you are a member of the organisation but don't have permission to manage the grant, and you click on the button, you get
Uncaught Error: Missing target element "toggle" for "menu" controller in the console, and no clear error notification.

Describe your changes

I updated the card grant header so the settings action only appears for users who can actually access the grant settings UI. Previously, any organisation member could see the View grant settings button, even if they lacked edit_overview? permission, which led to a broken interaction.

Before:
Screenshot 2026-08-20 at 2 24 59鈥痯m

After:
Screenshot 2026-08-20 at 2 24 39鈥痯m

@code2344
code2344 requested a review from a team August 20, 2026 04:37
@code2344

Copy link
Copy Markdown
Author

(pulled the latest changes)

@Luke-Oldenburg

Copy link
Copy Markdown
Contributor

Hi, this button was meant to be accessible to members so they could see the settings forms in a disabled state. I think this worked in the past but I just checked to confirm it is broken. Could you please update this PR so it still renders the button but then fix the button so it opens the settings form with the fields disabled?

@code2344

Copy link
Copy Markdown
Author

Alright, I'll update it.


def edit_overview
authorize @card_grant
authorize @card_grant, :show?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Show allows the cardholder to access this. I think we should update the edit policy to be auditor_or_member? and then alias the other edit policies to show.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, i agree.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i'll update that

Comment on lines +25 to +28
<section class="modal modal--scroll modal--wide bg-snow" data-behavior="modal" role="dialog" id="edit_card_grant">
<%= modal_header(policy(card_grant).edit? ? "Manage grant" : "Grant settings") %>
<%= turbo_frame_tag "edit_#{card_grant.id}", src: edit_overview_event_card_grant_path(card_grant) %>
</section>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should still be wrapped in an if but the link_to that points to it also needs an if. The reason this bug popped up was because we weren't rendering the modal but were rendering the button to access it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yep, I see now where that's wrong. I'll fix that

Comment on lines +9 to +23
describe "read-only grant settings" do
it "allows members to view, but not edit, grant settings" do
member = create(:user)
event = create(:event, :with_positive_balance, plan_type: Event::Plan::HackClubAffiliate)
create(:organizer_position, user: member, event:, role: :member)
card_grant = create(:card_grant, event:)
create_session(member, verified: true)

get(:edit_purpose, params: { event_id: event.friendly_id, id: card_grant.hashid })

expect(response).to have_http_status(:ok)
expect(response.parsed_body.at_css("[name='card_grant[purpose]']")["disabled"]).to eq("disabled")
expect(response.parsed_body.at_css("[value='Save']")["disabled"]).to eq("disabled")
end
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a good test of the UI but it may be more verbose to also test calling update as a member and ensuring that it fails.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Got it.

@code2344

Copy link
Copy Markdown
Author

@code2344

Copy link
Copy Markdown
Author

very small thing that fixed the tooltip, now if you can view grant settings the tooltip shows view settings as opposed to manage card grant.
Before:
Screenshot 2026-08-21 at 12 09 03鈥痯m
After:
Screenshot 2026-08-21 at 12 06 58鈥痯m

@code2344

Copy link
Copy Markdown
Author

(update branch again)

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