Skip to content

Conversation

@fbuys
Copy link
Contributor

@fbuys fbuys commented Jan 29, 2026

IIRR-30(auth): Enforce user token check on all controllers

Add a before_action in ApplicationController to check for the presence
of a user token in the session, rendering the login page if missing.
Remove redundant token check from PuzzlesController. Allow
SessionsController to skip this check for authentication purposes.

IIRR-31(puzzles): Add clone action for puzzles

Implement a clone action in Puzzles::ClonesController to duplicate
existing puzzles. Add a "Clone" button to the archived puzzles table.
Include tests for cloning functionality and authentication checks.

QA Notes

  • Ensure that you are logged out
  • Confirm that you cannot access puzzles at all (You cannot view: /puzzles/3/edit for example)
  • Log in
  • Clone an archived puzzle
  • Ensure you can proceed to then approve a cloned puzzle

Jira

@fbuys fbuys force-pushed the IIRR-30-and-IIRR-31 branch from 3f377f8 to 529a964 Compare January 29, 2026 22:17
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
before_action :check_session_expiry
before_action :check_user_token
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensure user is authenticated in all controllers that inherit from ApplicationController

@@ -42,6 +42,7 @@
<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'btn pending-btn' %>
<% elsif actions == :archived %>
<%= button_to 'Un-Archive', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'btn pending-btn' %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to keep the Un-Archive button?

Choose a reason for hiding this comment

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

I think we should since clone is being added, so we do not have to use un-archive.

def create
original_puzzle = Puzzle.find(params[:puzzle_id])
attributes = original_puzzle.attributes.slice("question", "answer", "explanation", "link", "suggested_by")
cloned_puzzle = Puzzle.new(attributes.merge(state: params.fetch(:state, "pending")))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can clone and assign any state, defaults to pending.

<%= button_to 'Pending', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'btn pending-btn' %>
<% elsif actions == :archived %>
<%= button_to 'Un-Archive', puzzle_state_path(puzzle, state: :pending), method: :patch, form_class: 'inline-form', class: 'btn pending-btn' %>
<%= button_to 'Clone', puzzle_clone_path(puzzle, state: :pending), method: :post, form_class: 'inline-form', class: 'btn pending-btn' %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cloned puzzled state can be set here.

fbuys added 2 commits January 30, 2026 00:24
Add a before_action in ApplicationController to check for the presence
of a user token in the session, rendering the login page if missing.
Remove redundant token check from PuzzlesController. Allow
SessionsController to skip this check for authentication purposes.

Ref: https://ombulabs.atlassian.net/browse/IIRR-30
Implement a clone action in Puzzles::ClonesController to duplicate
existing puzzles. Add a "Clone" button to the archived puzzles table.
Include tests for cloning functionality and authentication checks.

Ref: https://ombulabs.atlassian.net/browse/IIRR-31
@fbuys fbuys force-pushed the IIRR-30-and-IIRR-31 branch from 529a964 to d8bf90d Compare January 29, 2026 22:24
user_email = auth.info.email

domain_allowlist = ENV.fetch("DOMAIN_ALLOWLIST").split(",").map(&:strip)
domain_allowlist = ENV.fetch("DOMAIN_ALLOWLIST", "").split(",").map(&:strip)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix a CI failure where DOMAIN_ALLOWLIST is not defined.

Copy link

@rishijain rishijain left a comment

Choose a reason for hiding this comment

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

The changes LGTM 🚀 . If you do decide to remove the un-archive in this PR itself, lemme know and I can take a look again once you do. Otherwise this PR is good to go.

fbuys added 2 commits January 30, 2026 15:35
Added skip_before_action :check_user_token to Slack::ApplicationController
to bypass user token verification for Slack requests. This ensures that
Slack webhooks and interactions are not blocked by user authentication
requirements.

Ref: https://ombulabs.atlassian.net/browse/IIRR-30
@fbuys fbuys force-pushed the IIRR-30-and-IIRR-31 branch from 3f56c9e to 38ceffe Compare January 30, 2026 13:35
@@ -1,5 +1,7 @@
class Slack::ApplicationController < ApplicationController
skip_before_action :verify_authenticity_token
skip_before_action :check_user_token
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slack controllers don't relay on omniauth credentials.

autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
brakeman (7.1.0)
brakeman (8.0.1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For CI to pass

Added original_puzzle association to Puzzle model and migration to
support tracking the source of cloned puzzles. Updated clone controller
and tests to set and verify original_puzzle_id on clone creation.

Will be handy when we want to calculate how many people got it right or
wrong, if we ever want to show stats for the puzzles.

Ref: https://ombulabs.atlassian.net/browse/IIRR-31
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.

3 participants