Skip to content

Fix: Allow redirected authors in validation#11393

Open
SAYAN02-DEV wants to merge 2 commits intointernetarchive:masterfrom
SAYAN02-DEV:fix-author-redirect-validation
Open

Fix: Allow redirected authors in validation#11393
SAYAN02-DEV wants to merge 2 commits intointernetarchive:masterfrom
SAYAN02-DEV:fix-author-redirect-validation

Conversation

@SAYAN02-DEV
Copy link
Contributor

@SAYAN02-DEV SAYAN02-DEV commented Oct 30, 2025

Closes #11387

Fix: Resolves validation error when editing books containing redirected author references.

Technical

Here the code checks(Line 109 and Line 121) for /type/author and if not so it doesnt proceed, which restricts editing of books that have merged authors:

if page.key.startswith('/a/') or page.key.startswith('/authors/'):
if page.type.key == '/type/author':
return
books = web.ctx.site.things({'type': '/type/edition', 'authors': page.key})
books = books or web.ctx.site.things(
{'type': '/type/work', 'authors': {'author': {'key': page.key}}}
)
if page.type.key == '/type/delete' and books:
raise ValidationException(
'This Author page cannot be deleted as %d record(s) still reference this id. Please remove or reassign before trying again. Referenced by: %s'
% (len(books), books)
)
elif page.type.key != '/type/author' and books:
raise ValidationException(
'Changing type of author pages is not allowed.'
)

If we allow /type/redirect when validating author page types. This allows edits to proceed on records that reference merged authors, while still preventing malicious type changes.
Line 109 should be
if page.type.key in ('/type/author', '/type/redirect'):
Line 121 should be
elif page.type.key not in ['/type/author', '/type/redirect'] and books:

Testing

Steps to reproduce the original issue:

  1. Find or create a work with duplicate author entries where one author has been merged (is now a redirect)
  2. Attempt to edit the work to remove the duplicate author
  3. Observe the validation error

Steps to verify the fix:

  1. Apply this PR
  2. Edit a work/book containing a redirected author reference
  3. Verify the edit succeeds without validation errors
  4. Confirm that removing duplicate authors now works correctly

Screenshot

N/A - This is a backend validation fix with no UI changes

Stakeholders

Copilot AI review requested due to automatic review settings October 30, 2025 07:16
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

This PR updates the author page validation logic to allow redirect types alongside author types. Previously, the validation would reject redirect operations on author pages, but redirects are a legitimate type used when merging duplicate authors.

  • Added /type/redirect as an allowed type for author pages in validation checks
  • Updated both the early return condition and the type-changing validation to handle redirect types

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

@github-project-automation github-project-automation bot moved this to Waiting Review/Merge from Staff in Ray's Project Nov 3, 2025
@RayBB
Copy link
Collaborator

RayBB commented Nov 5, 2025

@mekarpeles @cdrini I don't feel confident in reviewing this one. Could one of you take it on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting Review/Merge from Staff

Development

Successfully merging this pull request may close these issues.

Cannot remove author from work

2 participants