Skip to content

Reinstate recentchanges_view POST handler#11897

Merged
mekarpeles merged 2 commits intointernetarchive:masterfrom
jimchamp:reinstate-recentchanges-handler
Feb 18, 2026
Merged

Reinstate recentchanges_view POST handler#11897
mekarpeles merged 2 commits intointernetarchive:masterfrom
jimchamp:reinstate-recentchanges-handler

Conversation

@jimchamp
Copy link
Collaborator

Closes #11894

Restores the recentchanges_view POST handler, which was thought to be unused. Authentication is now required for this endpoint. Usage is restricted to admins and super-librarians.

Technical

Testing

Screenshot

Stakeholders

Adds auth checks to handler.  Use is restricted
to admins and super-librarians
Copilot AI review requested due to automatic review settings February 18, 2026 23:48
@github-actions github-actions bot added the Priority: 0 Fix now: Issue prevents users from using the site or active data corruption. [managed] label Feb 18, 2026
Copy link
Contributor

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

Restores the recentchanges_view POST handler used by the Recent Changes UI to “Undo All” (e.g., undoing merges), adding authentication and restricting access to admins and super-librarians.

Changes:

  • Add recentchanges_view.POST handler to perform an undo and redirect back to the change page
  • Require a logged-in user and membership in admin/super-librarians usergroups for this endpoint
  • Gate undo behind the undo feature flag

@@ -16,6 +16,7 @@
render_template,
safeint,
) # TODO: unused import?
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The inline comment # TODO: unused import? is inaccurate here: safeint is used later in this module (e.g., for limit/offset parsing). Please remove or update the comment to avoid misleading future cleanup.

Suggested change
) # TODO: unused import?
)

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +191
allowed_usergroups = ['/usergroup/admin', '/usergroup/super-librarians']
if not (user := get_current_user()) or not (
user.is_member_of_any(allowed_usergroups)
):
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Consider moving allowed_usergroups to a module-level constant (e.g., ALLOWED_USERGROUPS: list[str] = [...]) like other handlers do. This avoids recreating the list per request and makes the authorization policy easier to locate/reuse.

Copilot uses AI. Check for mistakes.
)

id = int(id)
change = web.ctx.site.get_change(id)
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

change = web.ctx.site.get_change(id) can return None (as handled in GET), and not all changesets are undoable (can_undo() may be false, e.g. an already-undone merge or an undo changeset). Calling change._undo() unconditionally can raise an exception or allow unintended repeat/invalid undos. Please add the same not-found handling as GET and gate _undo() behind change.can_undo() (returning an appropriate 4xx / permission-denied response when it’s not undoable).

Suggested change
change = web.ctx.site.get_change(id)
change = web.ctx.site.get_change(id)
if not change:
web.ctx.status = "404 Not Found"
return render.notfound(web.ctx.path)
if not change.can_undo():
return render_template(
"permission_denied",
web.ctx.path,
"Permission denied to undo this change.",
)

Copilot uses AI. Check for mistakes.
@mekarpeles mekarpeles merged commit cb0b369 into internetarchive:master Feb 18, 2026
3 checks passed
@jimchamp jimchamp added the Patch Deployed This PR has been deployed to production independently, outside of the regular deploy cycle. label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Patch Deployed This PR has been deployed to production independently, outside of the regular deploy cycle. Priority: 0 Fix now: Issue prevents users from using the site or active data corruption. [managed]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"method not allowed" on undo author merge attempt

3 participants