Do not offer a guest a provider link the controller refuses

JA
2mo ago
+37-1

Fixes #3655.

The method selector decides whether to render a provider's link with

<% next unless Current.user&.admin? || config[:member_connectable] %>

while ConnectorAuthorizable#require_connector_create! admits the request only on

connector_item_class&.member_connectable? && Current.user&.member?

role is guest/member/admin/super_admin, so a guest satisfies the first and fails the second: the link is offered and the submit is refused. Nothing gates a guest out of the page either — AccountableResource has no role check on new — so it is reachable rather than theoretical.

The comment already sitting above that line states the rule the controller enforces:

Admins may connect anything; a member may only connect providers whose credential is scoped to the single connection they authenticate (see ProviderItemOwnable).

So the change is the guard catching up with its own comment. The controller's rule is taken as correct; nothing in ConnectorAuthorizable, ProviderItemOwnable or the providers' declared scopes moves.

Test

One user, one family, and a single variable — the role changes between the two requests and nothing else does, so any difference in what renders can only be the role. A member must be offered the link; the same user as a guest must not be.

Watched failing against the current guard: 1 link rendered where 0 were expected.

Verification

886 tests across the accountable controllers and the provider suites pass; erb_lint and rubocop clean.

Fork pre-flight: jaysbeekay/sure#211. Same branch, same commit (up/member-connectable-guest-links at 4faba9525). Its CI and review history live there.

Rebased onto main (6 Oct)

Rebased onto main at eb34c06f0; the commits carry the same changes, under new SHAs. SHAs elsewhere in this description refer to the commits as they were before.

  • 4faba9525 → a2dd019fa Do not offer a guest a provider link the controller refuses

Conflicts: none.

bin/rails test on a2dd019fa: 10,566 runs, 44,982 assertions, 0 failures, 0 errors, 33 skips. bin/rubocop on the changed files: no offenses.

Summary by CodeRabbit

  • Bug Fixes
    • Provider connection links are now shown only to admins and members when the provider allows member connections. Guests and other users no longer see these links.