Skip to content

Commit 32bebf2

Browse files
committed
fix: redirect to /edit for admins
1 parent 51ccd9f commit 32bebf2

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

web/src/contributions/view-page.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ function ViewApp({ doi }) {
139139
if (doi) { loadData(); fetchHistory(); }
140140
}, [doi]);
141141

142+
// After an ORCID login kicked off by "Edit", the backend returns the user
143+
// here with `do=edit`. Re-run the edit routing now that we know who they are
144+
// (and, crucially, whether they're an admin), then strip the marker.
145+
useEffect(() => {
146+
const params = new URLSearchParams(window.location.search);
147+
if (params.get('do') !== 'edit') return;
148+
params.delete('do');
149+
const qs = params.toString();
150+
history.replaceState(null, '', qs ? `?${qs}` : window.location.pathname);
151+
onEdit();
152+
}, []);
153+
142154
useEffect(() => {
143155
if (previewRef.current && authors.length > 0) {
144156
createPreview(previewRef.current, authors);
@@ -151,17 +163,26 @@ function ViewApp({ doi }) {
151163
loadData(commit);
152164
}
153165

154-
// Edit: send the user to the add/review page for their own record. They must
155-
// log in with ORCID first; the add page then matches them to their existing
156-
// row by ORCID and opens the full editor. No invite token is needed.
166+
// Edit: admins get the full editor (/edit); everyone else gets the
167+
// self-service add/review wizard (/add), which matches them to their own row
168+
// by ORCID. All routes require an ORCID login first.
169+
//
170+
// Admin status is only known after login, so when the user isn't logged in we
171+
// send them back to this view page with `do=edit`; the effect above re-runs
172+
// this handler once they return authenticated and then routes correctly.
157173
async function onEdit() {
158-
const addUrl = `${window.location.origin}/contributions/add?project=${encodeURIComponent(doi)}`;
159174
const me = await getCurrentUser();
160-
if (me) {
161-
window.location.assign(addUrl);
162-
} else {
163-
loginWithOrcid(addUrl);
175+
if (!me) {
176+
const back = `${window.location.origin}${window.location.pathname}`
177+
+ `?doi=${encodeURIComponent(doi)}&do=edit`;
178+
loginWithOrcid(back);
179+
return;
164180
}
181+
// The edit page reads `?doi=`; the add wizard reads `?project=`.
182+
const url = me.is_admin
183+
? `/contributions/edit?doi=${encodeURIComponent(doi)}`
184+
: `/contributions/add?project=${encodeURIComponent(doi)}`;
185+
window.location.assign(`${window.location.origin}${url}`);
165186
}
166187

167188
if (!doi) {

0 commit comments

Comments
 (0)