mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix(cron): fix score down breaking during middleware
This commit is contained in:
@@ -246,14 +246,15 @@ export default function scoreTask (options = {}, req = {}, analytics) {
|
|||||||
|
|
||||||
if (oldLeveledUp) user._tmp.leveledUp = oldLeveledUp;
|
if (oldLeveledUp) user._tmp.leveledUp = oldLeveledUp;
|
||||||
|
|
||||||
// If they're trying to purchase a too-expensive reward, don't allow them to do that.
|
|
||||||
if (task.value > user.stats.gp && task.type === 'reward') throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
|
||||||
// Thanks to open group tasks, userId is not guaranteed. Don't allow scoring inaccessible tasks
|
// Thanks to open group tasks, userId is not guaranteed. Don't allow scoring inaccessible tasks
|
||||||
if (task.userId && task.userId !== user._id) {
|
if (task.userId && task.userId !== user._id) {
|
||||||
throw new BadRequest('Cannot score task belonging to another user.');
|
throw new BadRequest('Cannot score task belonging to another user.');
|
||||||
} else if (user.guilds.indexOf(task.group.id) === -1 && user.party._id !== task.group.id) {
|
} else if (task.group.id && user.guilds.indexOf(task.group.id) === -1
|
||||||
|
&& user.party._id !== task.group.id) {
|
||||||
throw new BadRequest('Cannot score task belonging to another user.');
|
throw new BadRequest('Cannot score task belonging to another user.');
|
||||||
}
|
}
|
||||||
|
// If they're trying to purchase a too-expensive reward, don't allow them to do that.
|
||||||
|
if (task.value > user.stats.gp && task.type === 'reward') throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
||||||
|
|
||||||
if (task.type === 'habit') {
|
if (task.type === 'habit') {
|
||||||
delta += _changeTaskValue(user, task, direction, times, cron);
|
delta += _changeTaskValue(user, task, direction, times, cron);
|
||||||
|
|||||||
Reference in New Issue
Block a user