- Enter a user's email address and select access level to share
+ Enter a user's ORCID or email address and select access level
+ to share
setUserEmail(e.target.value)}
+ value={userIdentifier}
+ onChange={(e) => setUserIdentifier(e.target.value)}
/>
diff --git a/packages/openneuro-app/src/scripts/scss/dataset/dataset-tool.scss b/packages/openneuro-app/src/scripts/scss/dataset/dataset-tool.scss
index 9f222c3c7..6438da4de 100644
--- a/packages/openneuro-app/src/scripts/scss/dataset/dataset-tool.scss
+++ b/packages/openneuro-app/src/scripts/scss/dataset/dataset-tool.scss
@@ -54,7 +54,7 @@
}
> span {
display: block;
- min-width: 33.3333%;
+ min-width: 25%;
margin-bottom: 11px;
label {
font-weight: bold;
diff --git a/packages/openneuro-server/src/graphql/resolvers/mutation.ts b/packages/openneuro-server/src/graphql/resolvers/mutation.ts
index 04cfdd7a6..1cc46d5a3 100644
--- a/packages/openneuro-server/src/graphql/resolvers/mutation.ts
+++ b/packages/openneuro-server/src/graphql/resolvers/mutation.ts
@@ -19,7 +19,11 @@ import {
import { removeUser, setAdmin, setBlocked } from "./user.js"
import { updateSummary } from "./summary"
import { revalidate, updateValidation } from "./validation.js"
-import { removePermissions, updatePermissions } from "./permissions"
+import {
+ removePermissions,
+ updateOrcidPermissions,
+ updatePermissions,
+} from "./permissions"
import { followDataset } from "./follow.js"
import { starDataset } from "./stars.js"
import { publishDataset } from "./publish.js"
@@ -54,6 +58,7 @@ const Mutation = {
updateValidation,
updatePublic,
updatePermissions,
+ updateOrcidPermissions,
removePermissions,
removeUser,
setAdmin,
diff --git a/packages/openneuro-server/src/graphql/resolvers/permissions.ts b/packages/openneuro-server/src/graphql/resolvers/permissions.ts
index a957501b9..4b6912e37 100644
--- a/packages/openneuro-server/src/graphql/resolvers/permissions.ts
+++ b/packages/openneuro-server/src/graphql/resolvers/permissions.ts
@@ -29,20 +29,35 @@ const publishPermissions = async (datasetId) => {
const ds = { id: datasetId }
const { id, userPermissions } = await permissions(ds)
const permissionsUpdated = {
- id: datasetId,
- permissions: {
- id,
- userPermissions: await Promise.all(
- userPermissions.map(async (userPermission) => ({
- ...userPermission,
- user: await user(ds, { id: userPermission.userId }),
- })),
- ),
- },
+ id,
+ userPermissions: await Promise.all(
+ userPermissions.map(async (userPermission) => ({
+ ...userPermission,
+ user: await user(ds, { id: userPermission.userId }),
+ })),
+ ),
}
return permissionsUpdated
}
+async function updateUsers(datasetId: string, level: string, users) {
+ for (const user of users) {
+ await Permission.updateOne(
+ {
+ datasetId: datasetId,
+ userId: user.id,
+ },
+ {
+ datasetId: datasetId,
+ userId: user.id,
+ level: level,
+ },
+ { upsert: true },
+ ).exec()
+ }
+ return publishPermissions(datasetId)
+}
+
/**
* Update user permissions on a dataset
*/
@@ -57,28 +72,29 @@ export const updatePermissions = async (obj, args, { user, userInfo }) => {
throw new Error("A user with that email address does not exist")
}
- const userPromises = users.map((user) => {
- return new Promise
((resolve, reject) => {
- Permission.updateOne(
- {
- datasetId: args.datasetId,
- userId: user.id,
- },
- {
- datasetId: args.datasetId,
- userId: user.id,
- level: args.level,
- },
- { upsert: true },
- )
- .exec()
- .then(() => resolve())
- .catch((err) => reject(err))
- })
+ return updateUsers(args.datasetId, args.level, users)
+}
+
+/**
+ * ORCID variant of updatePermissions
+ */
+export const updateOrcidPermissions = async (obj, args, { user, userInfo }) => {
+ await checkDatasetAdmin(args.datasetId, user, userInfo)
+ // Get all users associated with the ORCID provided
+ const users = await User.find({
+ "$or": [{ "orcid": args.userOrcid }, {
+ "providerId": args.userOrcid,
+ "provider": "orcid",
+ }],
})
- return Promise.all(userPromises).then(() =>
- publishPermissions(args.datasetId)
- )
+ .collation({ locale: "en", strength: 2 })
+ .exec()
+
+ if (!users.length) {
+ throw new Error("A user with that ORCID does not exist")
+ }
+
+ return updateUsers(args.datasetId, args.level, users)
}
/**
diff --git a/packages/openneuro-server/src/graphql/schema.ts b/packages/openneuro-server/src/graphql/schema.ts
index 787f13241..ee5078edc 100644
--- a/packages/openneuro-server/src/graphql/schema.ts
+++ b/packages/openneuro-server/src/graphql/schema.ts
@@ -121,7 +121,9 @@ export const typeDefs = `
# Update a draft with validation results
updateValidation(validation: ValidationInput!): Boolean
# Update a users's permissions on a dataset
- updatePermissions(datasetId: ID!, userEmail: String!, level: String): User
+ updatePermissions(datasetId: ID!, userEmail: String!, level: String!): DatasetPermissions
+ # Update a users's permissions for a given ORCID
+ updateOrcidPermissions(datasetId: ID!, userOrcid: String!, level: String!): DatasetPermissions
# Remove a users's permissions on a dataset
removePermissions(datasetId: ID!, userId: String!): Boolean
# Remove a user