Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug preventing org. admins to add new users #963

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. The format

### Fixed

- Fixed a bug that made organization admins unable to add new users.
- Improved error reporting from backup and restore Cloud Functions.

### Security
Expand Down
37 changes: 14 additions & 23 deletions src/db/User/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,20 @@ export const getAllUserIds = () =>
export const getUserFromId = (id) => collectionReference.doc(id).get();

export const create = async (user) => {
try {
if (!user.email) {
throw new Error('Invalid email');
}

const { exists } = await collectionReference.doc(user.id).get();
if (exists) {
throw new Error(`User ${user.id} already exists!`);
}

await collectionReference.doc(user.id).set({
...user,
superAdmin: false,
admin: [],
preferences,
});

return true;
} catch (error) {
throw new Error(`Could not add user ${user.id}`);
if (!user.email) {
throw new Error('Invalid email');
}

const { exists } = await collectionReference.doc(user.id).get();
if (exists) {
throw new Error(`User ${user.id} already exists!`);
}

await collectionReference.doc(user.id).set({
...user,
admin: [],
preferences,
});
};

export const remove = async (user) => {
Expand Down Expand Up @@ -66,9 +59,7 @@ export const addUsers = async (userList) => {
if (!userList || !userList.length) {
throw new Error('Invalid data');
}
const promises = userList
.map((email) => ({ id: email, email, superAdmin: false, admin: [] }))
.map(create);
const promises = userList.map((email) => ({ id: email, email })).map(create);

try {
return Promise.all(promises);
Expand Down
Loading