Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions engine/app/controllers/coplan/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ def signed_in?
end

def authenticate_coplan_user!
if request.get? && agent_request?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve API guidance for unauthenticated non-GET agents

When an unauthenticated curl or agent sends POST/PATCH/DELETE to a web route, this GET-only branch is skipped. Previously, the unless @current_coplan_user agent branch returned the Markdown API instructions for every method; after this change, a host with sign_in_path instead returns a 302 to the human sign-in page (or a bare 401 without one), so these clients lose the guidance to use the REST API. Keep the unauthenticated-agent fallback while exempting only authenticated non-GET requests.

AGENTS.md reference: AGENTS.md:L3-L5

Useful? React with 👍 / 👎.

render plain: agent_redirect_instructions, content_type: "text/markdown", status: :unauthorized
return
end

@current_coplan_user = CoPlan::Authentication.user_from_request(request)
unless @current_coplan_user
if agent_request?
render plain: agent_redirect_instructions, content_type: "text/markdown", status: :unauthorized
elsif CoPlan.configuration.sign_in_path
if CoPlan.configuration.sign_in_path
redirect_to CoPlan.configuration.sign_in_path, alert: "Please sign in."
else
head :unauthorized
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/browse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def revise(plan, content, actor: author)
expect(response).to have_http_status(:ok)
expect(versioned.slug).to eq("pricing-v1-2")
end

it "directs an authenticated non-browser client to the API instructions" do
get "/hampton/liveorder/q3/cart-roadmap", headers: {
"Accept" => "text/markdown",
"User-Agent" => "curl/8.11.0"
}

expect(response).to have_http_status(:unauthorized)
expect(response.media_type).to eq("text/markdown")
expect(response.body).to include("# CoPlan API")
expect(response.body).to include("/agent-instructions")
end
end

describe "the owner's own library" do
Expand Down
Loading