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

Veteran Pet ladder award for users affected by username changes #10765

Merged
merged 3 commits into from Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 91 additions & 0 deletions migrations/users/20181019_veteran_pet_ladder.js
@@ -0,0 +1,91 @@
/* eslint-disable no-console */
import { model as User } from '../website/server/models/user';

function processUsers (lastId) {
let query = {
'flags.verifiedUsername': true,
};

let fields = {
'items.pets': 1,
};

if (lastId) {
query._id = {
$gt: lastId,
};
}

return User.find(query)
.limit(250)
.sort({_id: 1})
.select(fields)
.then(updateUsers)
.catch((err) => {
console.log(err);
return exiting(1, `ERROR! ${err}`);
});
}

let progressCount = 1000;
let count = 0;

function updateUsers (users) {
if (!users || users.length === 0) {
console.warn('All appropriate users found and modified.');
displayData();
return;
}

let userPromises = users.map(updateUser);
let lastUser = users[users.length - 1];

return Promise.all(userPromises)
.then(() => {
processUsers(lastUser._id);
});
}

function updateUser (user) {
count++;

let set = {};

if (user.items.pets['Bear-Veteran']) {
set['items.pets.Fox-Veteran'] = 5;
} else if (user.items.pets['Lion-Veteran']) {
set['items.pets.Bear-Veteran'] = 5;
} else if (user.items.pets['Tiger-Veteran']) {
set['items.pets.Lion-Veteran'] = 5;
} else if (user.items.pets['Wolf-Veteran']) {
set['items.pets.Tiger-Veteran'] = 5;
} else {
set['items.pets.Wolf-Veteran'] = 5;
}

if (count % progressCount === 0) console.warn(`${count} ${user._id}`);

return User.update({_id: user._id}, {$set: set}).exec();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super important but here you should be able to use 'user.update()' directly as we have an User instance

}

function displayData () {
console.warn(`\n${count} users processed\n`);
return exiting(0);
}

function exiting (code, msg) {
code = code || 0; // 0 = success
if (code && !msg) {
msg = 'ERROR!';
}
if (msg) {
if (code) {
console.error(msg);
} else {
console.log(msg);
}
}
process.exit(code);
}

module.exports = processUsers;
1 change: 1 addition & 0 deletions website/common/locales/en/pets.json
Expand Up @@ -19,6 +19,7 @@
"veteranTiger": "Veteran Tiger",
"veteranLion": "Veteran Lion",
"veteranBear": "Veteran Bear",
"veteranFox": "Veteran Fox",
"cerberusPup": "Cerberus Pup",
"hydra": "Hydra",
"mantisShrimp": "Mantis Shrimp",
Expand Down
1 change: 1 addition & 0 deletions website/common/script/content/stable.js
Expand Up @@ -71,6 +71,7 @@ let specialPets = {
'Orca-Base': 'orca',
'Bear-Veteran': 'veteranBear',
'Hippogriff-Hopeful': 'hopefulHippogriffPet',
'Fox-Veteran': 'veteranFox',
};

let specialMounts = {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion website/server/controllers/api-v4/auth.js
Expand Up @@ -62,7 +62,20 @@ api.updateUsername = {
// save username
user.auth.local.lowerCaseUsername = newUsername.toLowerCase();
user.auth.local.username = newUsername;
user.flags.verifiedUsername = true;
if (!user.flags.verifiedUsername) {
user.flags.verifiedUsername = true;
if (user.items.pets['Bear-Veteran']) {
user.items.pets['Fox-Veteran'] = 5;
} else if (user.items.pets['Lion-Veteran']) {
user.items.pets['Bear-Veteran'] = 5;
} else if (user.items.pets['Tiger-Veteran']) {
user.items.pets['Lion-Veteran'] = 5;
} else if (user.items.pets['Wolf-Veteran']) {
user.items.pets['Tiger-Veteran'] = 5;
} else {
user.items.pets['Wolf-Veteran'] = 5;
}
}
await user.save();

res.respond(200, { username: req.body.username });
Expand Down
1 change: 1 addition & 0 deletions website/server/models/user/hooks.js
Expand Up @@ -125,6 +125,7 @@ function _setUpNewUser (user) {
let iterableFlags = user.flags.toObject();

user.items.quests.dustbunnies = 1;
user.items.pets['Wolf-Veteran'] = 5; // Thank-you for users joining during username upheaval
user.purchased.background.violet = true;
user.preferences.background = 'violet';

Expand Down