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

View File

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

View File

@ -194,7 +194,7 @@ function createUpdateMyUsername(app) {
user, user,
body: { username } body: { username }
} = req; } = req;
if (username.toLowerCase() === user.username) { if (username === user.username) {
return res.json({ return res.json({
type: 'info', type: 'info',
message: 'Username is already associated with this account' 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) { if (exists) {
return res.json({ return res.json({
@ -218,9 +218,7 @@ function createUpdateMyUsername(app) {
}); });
} }
return user.updateAttributes( return user.updateAttribute('username', username, err => {
{ username: username.toLowerCase(), displayUsername: username },
err => {
if (err) { if (err) {
res.status(500).json(standardErrorMessage); res.status(500).json(standardErrorMessage);
return next(err); return next(err);
@ -229,8 +227,7 @@ function createUpdateMyUsername(app) {
type: 'success', type: 'success',
message: `We have updated your username to ${username}` message: `We have updated your username to ${username}`
}); });
} });
);
}; };
} }

View File

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

View File

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

View File

@ -22,7 +22,6 @@ const propTypes = {
navigate: PropTypes.func.isRequired, navigate: PropTypes.func.isRequired,
requestedUser: PropTypes.shape({ requestedUser: PropTypes.shape({
username: PropTypes.string, username: PropTypes.string,
displayUsername: PropTypes.string,
profileUI: PropTypes.object profileUI: PropTypes.object
}), }),
showLoading: PropTypes.bool showLoading: PropTypes.bool

View File

@ -48,7 +48,6 @@ const propTypes = {
files: PropTypes.array files: PropTypes.array
}) })
), ),
displayUsername: PropTypes.string,
email: PropTypes.string, email: PropTypes.string,
githubProfile: PropTypes.string, githubProfile: PropTypes.string,
is2018DataVisCert: PropTypes.bool, is2018DataVisCert: PropTypes.bool,
@ -122,7 +121,6 @@ export function ShowSettings(props) {
toggleNightMode, toggleNightMode,
user: { user: {
completedChallenges, completedChallenges,
displayUsername,
email, email,
is2018DataVisCert, is2018DataVisCert,
isApisMicroservicesCert, isApisMicroservicesCert,
@ -193,12 +191,9 @@ export function ShowSettings(props) {
</Button> </Button>
</FullWidthRow> </FullWidthRow>
<Spacer /> <Spacer />
<h1 <h1 className='text-center' style={{ overflowWrap: 'break-word' }}>
className='text-center' {`Account Settings for ${username}`}
style={{ overflowWrap: 'break-word' }} </h1>
>{`Account Settings for ${
displayUsername ? displayUsername : username
}`}</h1>
<About <About
about={about} about={about}
currentTheme={theme} currentTheme={theme}
@ -208,7 +203,7 @@ export function ShowSettings(props) {
points={points} points={points}
submitNewAbout={submitNewAbout} submitNewAbout={submitNewAbout}
toggleNightMode={toggleNightMode} toggleNightMode={toggleNightMode}
username={displayUsername ? displayUsername : username} username={username}
/> />
<Spacer /> <Spacer />
<Privacy /> <Privacy />

View File

@ -27,7 +27,6 @@ const propTypes = {
showPortfolio: PropTypes.bool, showPortfolio: PropTypes.bool,
showTimeLine: PropTypes.bool showTimeLine: PropTypes.bool
}), }),
displayUsername: PropTypes.string,
calendar: PropTypes.object, calendar: PropTypes.object,
streak: PropTypes.shape({ streak: PropTypes.shape({
current: PropTypes.number, current: PropTypes.number,
@ -122,15 +121,13 @@ function renderProfile(user) {
picture, picture,
portfolio, portfolio,
about, about,
yearsTopContributor, yearsTopContributor
displayUsername
} = user; } = user;
return ( return (
<Fragment> <Fragment>
<Camper <Camper
about={showAbout ? about : null} about={showAbout ? about : null}
displayUsername={displayUsername}
githubProfile={githubProfile} githubProfile={githubProfile}
isGithub={isGithub} isGithub={isGithub}
isLinkedIn={isLinkedIn} isLinkedIn={isLinkedIn}
@ -150,11 +147,7 @@ function renderProfile(user) {
{showCerts ? <Certifications username={username} /> : null} {showCerts ? <Certifications username={username} /> : null}
{showPortfolio ? <Portfolio portfolio={portfolio} /> : null} {showPortfolio ? <Portfolio portfolio={portfolio} /> : null}
{showTimeLine ? ( {showTimeLine ? (
<Timeline <Timeline completedMap={completedChallenges} username={username} />
completedMap={completedChallenges}
displayUsername={displayUsername}
username={username}
/>
) : null} ) : null}
<Spacer /> <Spacer />
</Fragment> </Fragment>

View File

@ -11,7 +11,6 @@ import './camper.css';
const propTypes = { const propTypes = {
about: PropTypes.string, about: PropTypes.string,
displayUsername: PropTypes.string,
githubProfile: PropTypes.string, githubProfile: PropTypes.string,
isGithub: PropTypes.bool, isGithub: PropTypes.bool,
isLinkedIn: PropTypes.bool, isLinkedIn: PropTypes.bool,
@ -49,7 +48,6 @@ function joinArray(array) {
function Camper({ function Camper({
name, name,
username, username,
displayUsername,
location, location,
points, points,
picture, picture,
@ -76,7 +74,7 @@ function Camper({
/> />
) : ( ) : (
<Image <Image
alt={displayUsername ? displayUsername : username + "'s avatar"} alt={username + "'s avatar"}
className='avatar' className='avatar'
responsive={true} responsive={true}
src={picture} src={picture}
@ -101,9 +99,7 @@ function Camper({
website={website} website={website}
/> />
<br /> <br />
<h2 className='text-center username'> <h2 className='text-center username'>@{username}</h2>
@{displayUsername ? displayUsername : username}
</h2>
{name && <p className='text-center name'>{name}</p>} {name && <p className='text-center name'>{name}</p>}
{location && <p className='text-center location'>{location}</p>} {location && <p className='text-center location'>{location}</p>}
{about && <p className='bio text-center'>{about}</p>} {about && <p className='bio text-center'>{about}</p>}

View File

@ -27,7 +27,6 @@ const propTypes = {
) )
}) })
), ),
displayUsername: PropTypes.string,
username: PropTypes.string username: PropTypes.string
}; };
@ -131,7 +130,6 @@ class TimelineInner extends Component {
render() { render() {
const { const {
completedMap, completedMap,
displayUsername,
idToNameMap, idToNameMap,
username, username,
sortedTimeline, sortedTimeline,
@ -173,9 +171,9 @@ class TimelineInner extends Component {
> >
<Modal.Header closeButton={true}> <Modal.Header closeButton={true}>
<Modal.Title id='contained-modal-title'> <Modal.Title id='contained-modal-title'>
{`${ {`${username}'s Solution to ${
displayUsername ? displayUsername : username idToNameMap.get(id).challengeTitle
}'s Solution to ${idToNameMap.get(id).challengeTitle}`} }`}
</Modal.Title> </Modal.Title>
</Modal.Header> </Modal.Header>
<Modal.Body> <Modal.Body>

View File

@ -20,7 +20,6 @@ import FullWidthRow from '../helpers/FullWidthRow';
import { isValidUsername } from '../../../../utils/validate'; import { isValidUsername } from '../../../../utils/validate';
const propTypes = { const propTypes = {
displayUsername: PropTypes.string,
isValidUsername: PropTypes.bool, isValidUsername: PropTypes.bool,
submitNewUsername: PropTypes.func.isRequired, submitNewUsername: PropTypes.func.isRequired,
username: PropTypes.string, username: PropTypes.string,
@ -55,9 +54,6 @@ class UsernameSettings extends Component {
this.state = { this.state = {
isFormPristine: true, isFormPristine: true,
formValue: props.username, formValue: props.username,
formDisplayValue: props.displayUsername
? props.displayUsername
: props.username,
characterValidation: { valid: false, error: null }, characterValidation: { valid: false, error: null },
submitClicked: false, submitClicked: false,
isUserNew: tempUserRegex.test(props.username) isUserNew: tempUserRegex.test(props.username)
@ -88,23 +84,21 @@ class UsernameSettings extends Component {
e.preventDefault(); e.preventDefault();
const { submitNewUsername } = this.props; const { submitNewUsername } = this.props;
const { const {
formDisplayValue, formValue,
characterValidation: { valid } characterValidation: { valid }
} = this.state; } = this.state;
return this.setState({ submitClicked: true }, () => return this.setState({ submitClicked: true }, () =>
valid ? submitNewUsername(formDisplayValue) : null valid ? submitNewUsername(formValue) : null
); );
} }
handleChange(e) { handleChange(e) {
e.preventDefault(); e.preventDefault();
const { username, validateUsername } = this.props; const { username, validateUsername } = this.props;
const newDisplayUsernameValue = e.target.value; const newValue = e.target.value.toLowerCase();
const newValue = newDisplayUsernameValue.toLowerCase();
return this.setState( return this.setState(
{ {
formDisplayValue: newDisplayUsernameValue,
formValue: newValue, formValue: newValue,
isFormPristine: username === newValue, isFormPristine: username === newValue,
characterValidation: this.validateFormInput(newValue), characterValidation: this.validateFormInput(newValue),
@ -166,7 +160,7 @@ class UsernameSettings extends Component {
render() { render() {
const { const {
isFormPristine, isFormPristine,
formDisplayValue, formValue,
characterValidation: { valid, error }, characterValidation: { valid, error },
submitClicked submitClicked
} = this.state; } = this.state;
@ -183,7 +177,7 @@ class UsernameSettings extends Component {
<FormControl <FormControl
name='username-settings' name='username-settings'
onChange={this.handleChange} onChange={this.handleChange}
value={formDisplayValue} value={formValue}
/> />
</FormGroup> </FormGroup>
</FullWidthRow> </FullWidthRow>

View File

@ -20,11 +20,7 @@ function* fetchSessionUser() {
} = yield call(getSessionUser); } = yield call(getSessionUser);
const appUser = user[result] || {}; const appUser = user[result] || {};
yield put( yield put(
fetchUserComplete({ fetchUserComplete({ user: appUser, username: result, sessionMeta })
user: appUser,
username: result,
sessionMeta
})
); );
} catch (e) { } catch (e) {
yield put(fetchUserError(e)); yield put(fetchUserError(e));

View File

@ -45,7 +45,6 @@ MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, function(
isBanned: false, isBanned: false,
isCheater: false, isCheater: false,
username: 'developmentuser', username: 'developmentuser',
displayUsername: 'DevelopmentUser',
about: '', about: '',
name: 'Development User', name: 'Development User',
location: '', location: '',