Skip to content

Fix an admin bug on users route#228

Open
kaysiz wants to merge 2 commits intomasterfrom
ks-admin-users-bug
Open

Fix an admin bug on users route#228
kaysiz wants to merge 2 commits intomasterfrom
ks-admin-users-bug

Conversation

@kaysiz
Copy link
Member

@kaysiz kaysiz commented Mar 20, 2026

Purpose

closes: Add github issue that originated this PR

Approach

Open Questions and Pre-Merge TODOs

Learning

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

Reviewer, please remember our guidelines:

  • Be humble in the language and feedback you give, ask don't tell.
  • Consider using positive language as opposed to neutral when offering feedback. This is to avoid the negative bias that can occur with neutral language appearing negative.
  • Offer suggestions on how to improve code e.g. simplification or expanding clarity.
  • Ensure you give reasons for the changes you are proposing.

@kaysiz kaysiz self-assigned this Mar 20, 2026
@kaysiz kaysiz requested a review from Copilot March 20, 2026 22:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the admin users index view to better handle ORCID tokens when the token expiration timestamp is missing, preventing errors on the admin users route.

Changes:

  • Add a “No expiration” display state when user.orcid_expires_at is nil.
  • Guard the “delete token” action rendering with a presence check and parse orcid_expires_at before comparing to Time.zone.now.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

<span class="title pull-left"><%= link_to_if user.claims_count > 0, pluralize(user.claims_count, "Claim"), admin_claims_path(source: params[:source], state: params[:state], user_id: user.uid) %></span>
<div class="btn-toolbar">
<% if can?(:manage, user) && Time.zone.now < user.orcid_expires_at %>
<% if can?(:manage, user) && user.orcid_expires_at.present? && Time.zone.now < DateTime.parse(user.orcid_expires_at) %>
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

can?(:manage, user) is checked twice: the whole footer is already inside <% if can?(:manage, user) %>, so repeating the same authorization check in the nested condition adds noise and makes future edits easier to get wrong. You can simplify the inner conditional to only the ORCID expiry/token logic.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +146 to 148
<% if user.orcid_expires_at.present? && Time.zone.now < DateTime.parse(user.orcid_expires_at) %>
<div class="btn-group btn-group-sm pull-right">
<%= link_to 'delete token', admin_user_path(user.uid, user: { orcid_token: nil, orcid_expires_at: Time.zone.now }), { method: :put, remote: true, class: 'btn btn-sm btn-warning btn-fill' } %>
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The "delete token" button is now gated on user.orcid_expires_at.present?, which means admins can no longer delete tokens that exist but have a nil expiration (the UI even shows "No expiration" above). Consider changing the condition to allow deletion whenever a token is present, and only use the expiration timestamp to decide whether to label it expired (rather than hiding the action entirely).

Copilot uses AI. Check for mistakes.
Comment on lines +134 to 138
<% elsif user.orcid_expires_at.nil? %>
No expiration
<% elsif DateTime.parse(user.orcid_expires_at) < Time.zone.now %>
Expired
<% else %>
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

DateTime.parse(user.orcid_expires_at) is now being called in multiple branches (and again in the footer condition). To reduce repeated parsing and avoid type-mismatch surprises when comparing with Time.zone.now, consider parsing once into a local variable (preferably using Time.zone.parse/Time.iso8601 depending on the stored format) and reusing it for both comparisons and formatting.

Copilot uses AI. Check for mistakes.
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