Skip to content

Commit c252cfd

Browse files
Merge pull request #1594 from research-software-directory/1580-admin-orcid-search
Search for ORCID in admin user overview
2 parents b4ef6ef + 7aa4d1a commit c252cfd

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

frontend/components/admin/rsd-users/apiRsdUsers.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import logger from '~/utils/logger'
1212
import {paginationUrlParams} from '~/utils/postgrestUrl'
1313
import {RsdAccountInfo} from './useRsdAccounts'
1414
import {LockAccountProps} from './LockUserModal'
15+
import {orcidRegex} from '~/utils/getORCID'
1516

1617
type getLoginApiParams = {
1718
token: string,
@@ -36,13 +37,16 @@ export async function getRsdAccounts({page,rows,token,searchFor,adminsOnly,locke
3637
}
3738
// search
3839
if (searchFor) {
39-
if (searchFor.match(/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i) !== null) {
40-
// if searchFor is uuid we search by account id
40+
if (/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(searchFor)) {
41+
// if searchFor is a UUID we search by account ID
4142
query += `&id=eq.${searchFor}`
42-
} else {
43-
// else we search by name, email or organisation
44-
query+=`&login_for_account_text_filter.or=(name.ilike."*${searchFor}*",email.ilike."*${searchFor}*",home_organisation.ilike."*${searchFor}*")`
45-
}
43+
} else if (orcidRegex.test(searchFor)) {
44+
// else if searchFor is an ORCID we search on login_for_account sub
45+
query += `&login_for_account_text_filter.sub=eq.${searchFor}&login_for_account_text_filter.provider=eq.orcid`
46+
} else {
47+
// else we search by name, email or organisation
48+
query += `&login_for_account_text_filter.or=(name.ilike."*${searchFor}*",email.ilike."*${searchFor}*",home_organisation.ilike."*${searchFor}*")`
49+
}
4650
}
4751
// complete url
4852
const url = `${getBaseUrl()}/account?${query}`
@@ -168,7 +172,7 @@ export async function lockRsdAcount({
168172

169173
let resp
170174

171-
if (account.lock_account===true){
175+
if (account.lock_account){
172176
resp = await fetch(url, {
173177
method: 'PUT',
174178
headers: {

frontend/components/admin/rsd-users/useRsdAccounts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type RsdAccountLockedInfo = {
3434

3535
export default function useRsdAccounts(token: string, adminsOnly: boolean, lockedOnly: boolean, inactiveDays: number) {
3636
const {showErrorMessage}=useSnackbar()
37-
const {searchFor, page, rows, setCount} = usePaginationWithSearch('Find user by account id, name, email or affiliation')
37+
const {searchFor, page, rows, setCount} = usePaginationWithSearch('Find by account ID, name, email, ORCID or affiliation')
3838
const [accounts, setAccounts] = useState<RsdAccountInfo[]>([])
3939
// show loading only on initial load
4040
const [loading, setLoading] = useState(true)

frontend/utils/getORCID.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all)
22
// SPDX-FileCopyrightText: 2022 - 2023 dv4all
3+
// SPDX-FileCopyrightText: 2022 - 2025 Ewan Cahen (Netherlands eScience Center) <[email protected]>
34
// SPDX-FileCopyrightText: 2022 - 2025 Netherlands eScience Center
4-
// SPDX-FileCopyrightText: 2022 Ewan Cahen (Netherlands eScience Center) <[email protected]>
55
// SPDX-FileCopyrightText: 2024 - 2025 Dusan Mijatovic (Netherlands eScience Center)
66
//
77
// SPDX-License-Identifier: Apache-2.0
@@ -24,7 +24,7 @@ type OrcidExpandedSearchResponse = {
2424
}
2525

2626
const baseUrl = 'https://pub.orcid.org/v3.0/expanded-search/'
27-
const orcidRegex = /^\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$/
27+
export const orcidRegex = /^\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$/
2828

2929
export function isOrcid(stringToCheck: string): boolean {
3030
return stringToCheck.match(orcidRegex) !== null

0 commit comments

Comments
 (0)