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

Allow empty slug when user update profile #330

Merged
merged 2 commits into from
Jan 7, 2024
Merged
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
10 changes: 8 additions & 2 deletions src/graphql/mutations/UpdateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import client from 'util/client';
import User from 'graphql/models/User';
import { omit, omitBy } from 'lodash';
import { AvatarTypes } from 'util/user';
import { errors } from 'graphql/models/SlugErrorEnum';

import { assertSlugIsValid } from 'graphql/queries/ValidateSlug';
import AvatarTypeEnum from 'graphql/models/AvatarTypeEnum';
Expand Down Expand Up @@ -38,11 +39,16 @@ export default {
throw new Error(`There's nothing to update`);

// Ensure uniqueness of slug
if (slug !== undefined) {
if (slug !== undefined && slug !== null) {
try {
await assertSlugIsValid(slug, userId);
} catch (e) {
throw new Error(`Invalid slug: ${e}`);
if (e === errors.EMPTY) {
// allow user to update slug to empty
doc.slug = '';
} else {
throw new Error(`Invalid slug: ${e}`);
}
}
}

Expand Down
Loading