Api quest restrictions - no purchase/start without fulfilling eligibility requirements (#10387)
* removing duplicate translation key * fixing typos * extracting quest prerequisite check. adding check for previous quest completion, if required * fixing (undoing) static change, adding tests * more typos * correcting test failures * honoring quest prerequisites in quest invite API call. updating format of il8n string replacement arg * no longer using apiError, use translate method instead (msg key was not defined) * adding @apiError to docblock as requested in issue * removing checks on quest invite method. small window of opportunity/low risk
This commit is contained in:
committed by
Matteo Pagliazzi
parent
8fb67e7944
commit
ac90a40be5
@@ -23,7 +23,7 @@ module.exports = function buy (user, req = {}, analytics) {
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
// @TODO: Slowly remove the need for key and use type instead
|
||||
// This should evenutally be the 'factory' function with vendor classes
|
||||
// This should eventually be the 'factory' function with vendor classes
|
||||
let type = get(req, 'type');
|
||||
if (!type) type = get(req, 'params.type');
|
||||
if (!type) type = key;
|
||||
|
||||
@@ -37,10 +37,6 @@ export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation {
|
||||
let key = this.key = get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
|
||||
|
||||
if (key === 'lostMasterclasser1' && !this.userAbleToStartMasterClasser(user)) {
|
||||
throw new NotAuthorized(this.i18n('questUnlockLostMasterclasser'));
|
||||
}
|
||||
|
||||
let item = content.quests[key];
|
||||
|
||||
if (!item) throw new NotFound(errorMessage('questNotFound', {key}));
|
||||
@@ -49,9 +45,22 @@ export class BuyQuestWithGoldOperation extends AbstractGoldItemOperation {
|
||||
throw new NotAuthorized(this.i18n('questNotGoldPurchasable', {key}));
|
||||
}
|
||||
|
||||
this.checkPrerequisites(user, key);
|
||||
|
||||
this.canUserPurchase(user, item);
|
||||
}
|
||||
|
||||
checkPrerequisites (user, questKey) {
|
||||
const item = content.quests[questKey];
|
||||
if (questKey === 'lostMasterclasser1' && !this.userAbleToStartMasterClasser(user)) {
|
||||
throw new NotAuthorized(this.i18n('questUnlockLostMasterclasser'));
|
||||
}
|
||||
|
||||
if (item && item.previous && !user.achievements.quests[item.previous]) {
|
||||
throw new NotAuthorized(this.i18n('mustComplete', {quest: item.previous}));
|
||||
}
|
||||
}
|
||||
|
||||
executeChanges (user, item, req) {
|
||||
user.items.quests[item.key] = user.items.quests[item.key] || 0;
|
||||
user.items.quests[item.key] += this.quantity;
|
||||
|
||||
Reference in New Issue
Block a user