revert : Added displayUsername and username update functionality

removes implemenation from #35699
This reverts commit e154f38118.
This commit is contained in:
Mrugesh Mohapatra
2019-12-13 00:52:36 +05:30
committed by mrugesh
parent 0efaa4c3d7
commit fdb17223ec
13 changed files with 37 additions and 87 deletions

View File

@ -127,9 +127,6 @@ function nextTick(fn) {
const getRandomNumber = () => Math.random();
function populateRequiredFields(user) {
// by default, the displayUsername will have
// the same value as the username
user.displayUsername = user.username;
user.username = user.username.trim().toLowerCase();
user.email =
typeof user.email === 'string'
@ -350,7 +347,6 @@ export default function(User) {
if (!username && (!email || !isEmail(email))) {
return Promise.resolve(false);
}
username = username.toLowerCase();
log('checking existence');
// check to see if username is on blacklist
@ -399,7 +395,6 @@ export default function(User) {
cb(null, {});
});
}
username = username.toLowerCase();
return User.findOne({ where: { username } }, (err, user) => {
if (err) {
return cb(err);
@ -729,13 +724,13 @@ export default function(User) {
User.prototype.updateMyUsername = function updateMyUsername(newUsername) {
return Observable.defer(() => {
const isOwnUsername = isTheSame(newUsername.toLowerCase(), this.username);
const isOwnUsername = isTheSame(newUsername, this.username);
if (isOwnUsername) {
return Observable.of(dedent`
${newUsername} is already associated with this account.
`);
}
return Observable.fromPromise(User.doesExist(newUsername.toLowerCase()));
return Observable.fromPromise(User.doesExist(newUsername));
}).flatMap(boolOrMessage => {
if (typeof boolOrMessage === 'string') {
return Observable.of(boolOrMessage);
@ -746,20 +741,14 @@ export default function(User) {
`);
}
const usernameUpdate = new Promise((resolve, reject) => {
this.updateAttributes(
{
username: newUsername.toLowerCase(),
displayUsername: newUsername
},
err => {
if (err) {
return reject(err);
}
return resolve();
const usernameUpdate = new Promise((resolve, reject) =>
this.updateAttribute('username', newUsername, err => {
if (err) {
return reject(err);
}
);
});
return resolve();
})
);
return Observable.fromPromise(usernameUpdate).map(
() => dedent`

View File

@ -74,10 +74,6 @@
},
"require": true
},
"displayUsername": {
"type": "string",
"default":""
},
"about": {
"type": "string",
"default": ""

View File

@ -194,7 +194,7 @@ function createUpdateMyUsername(app) {
user,
body: { username }
} = req;
if (username.toLowerCase() === user.username) {
if (username === user.username) {
return res.json({
type: 'info',
message: 'Username is already associated with this account'
@ -209,7 +209,7 @@ function createUpdateMyUsername(app) {
});
}
const exists = await User.doesExist(username.toLowerCase());
const exists = await User.doesExist(username);
if (exists) {
return res.json({
@ -218,19 +218,16 @@ function createUpdateMyUsername(app) {
});
}
return user.updateAttributes(
{ username: username.toLowerCase(), displayUsername: username },
err => {
if (err) {
res.status(500).json(standardErrorMessage);
return next(err);
}
return res.status(200).json({
type: 'success',
message: `We have updated your username to ${username}`
});
return user.updateAttribute('username', username, err => {
if (err) {
res.status(500).json(standardErrorMessage);
return next(err);
}
);
return res.status(200).json({
type: 'success',
message: `We have updated your username to ${username}`
});
});
};
}

View File

@ -37,7 +37,6 @@ function createProfileAttributesFromGithub(profile) {
return {
name,
username: username.toLowerCase(),
displayUsername: username,
location,
bio,
website,

View File

@ -11,7 +11,6 @@ export const publicUserProps = [
'about',
'calendar',
'completedChallenges',
'displayUsername',
'githubProfile',
'isApisMicroservicesCert',
'isBackEndCert',