mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
use cron middleware
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import validator from 'validator';
|
import validator from 'validator';
|
||||||
import passport from 'passport';
|
import passport from 'passport';
|
||||||
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
||||||
|
import cron from '../../middlewares/api-v3/cron';
|
||||||
import {
|
import {
|
||||||
NotAuthorized,
|
NotAuthorized,
|
||||||
} from '../../libs/api-v3/errors';
|
} from '../../libs/api-v3/errors';
|
||||||
@@ -138,6 +139,7 @@ function _loginRes (user, req, res, next) {
|
|||||||
api.loginLocal = {
|
api.loginLocal = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/user/auth/local/login',
|
url: '/user/auth/local/login',
|
||||||
|
middlewares: [cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
req.checkBody({
|
req.checkBody({
|
||||||
username: {
|
username: {
|
||||||
@@ -182,6 +184,7 @@ api.loginLocal = {
|
|||||||
api.loginSocial = {
|
api.loginSocial = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/user/auth/social', // this isn't the most appropriate url but must be the same as v2
|
url: '/user/auth/social', // this isn't the most appropriate url but must be the same as v2
|
||||||
|
middlewares: [cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let accessToken = req.body.authResponse.access_token;
|
let accessToken = req.body.authResponse.access_token;
|
||||||
let network = req.body.network;
|
let network = req.body.network;
|
||||||
@@ -247,7 +250,7 @@ api.loginSocial = {
|
|||||||
api.deleteSocial = {
|
api.deleteSocial = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: '/user/auth/social/:network',
|
url: '/user/auth/social/:network',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
let network = req.params.network;
|
let network = req.params.network;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
||||||
|
import cron from '../../middlewares/api-v3/cron';
|
||||||
import { model as Tag } from '../../models/tag';
|
import { model as Tag } from '../../models/tag';
|
||||||
import {
|
import {
|
||||||
NotFound,
|
NotFound,
|
||||||
@@ -18,7 +19,7 @@ let api = {};
|
|||||||
api.createTag = {
|
api.createTag = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tags',
|
url: '/tags',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ api.createTag = {
|
|||||||
api.getTags = {
|
api.getTags = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/tags',
|
url: '/tags',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res) {
|
handler (req, res) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
res.respond(200, user.tags);
|
res.respond(200, user.tags);
|
||||||
@@ -65,7 +66,7 @@ api.getTags = {
|
|||||||
api.getTag = {
|
api.getTag = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/tags/:tagId',
|
url: '/tags/:tagId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ api.getTag = {
|
|||||||
api.updateTag = {
|
api.updateTag = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: '/tags/:tagId',
|
url: '/tags/:tagId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -129,7 +130,7 @@ api.updateTag = {
|
|||||||
api.deleteTag = {
|
api.deleteTag = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: '/tags/:tagId',
|
url: '/tags/:tagId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
||||||
|
import cron from '../../middlewares/api-v3/cron';
|
||||||
import { sendTaskWebhook } from '../../libs/api-v3/webhook';
|
import { sendTaskWebhook } from '../../libs/api-v3/webhook';
|
||||||
import * as Tasks from '../../models/task';
|
import * as Tasks from '../../models/task';
|
||||||
import {
|
import {
|
||||||
@@ -26,7 +27,7 @@ let api = {};
|
|||||||
api.createTask = {
|
api.createTask = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tasks',
|
url: '/tasks',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
req.checkBody('type', res.t('invalidTaskType')).notEmpty().isIn(Tasks.tasksTypes);
|
req.checkBody('type', res.t('invalidTaskType')).notEmpty().isIn(Tasks.tasksTypes);
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ api.createTask = {
|
|||||||
api.getTasks = {
|
api.getTasks = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/tasks',
|
url: '/tasks',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
req.checkQuery('type', res.t('invalidTaskType')).optional().isIn(Tasks.tasksTypes);
|
req.checkQuery('type', res.t('invalidTaskType')).optional().isIn(Tasks.tasksTypes);
|
||||||
|
|
||||||
@@ -120,7 +121,7 @@ api.getTasks = {
|
|||||||
api.getTask = {
|
api.getTask = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/tasks/:taskId',
|
url: '/tasks/:taskId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ api.getTask = {
|
|||||||
api.updateTask = {
|
api.updateTask = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: '/tasks/:taskId',
|
url: '/tasks/:taskId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -236,7 +237,7 @@ function _generateWebhookTaskData (task, direction, delta, stats, user) {
|
|||||||
api.scoreTask = {
|
api.scoreTask = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tasks/:taskId/score/:direction',
|
url: '/tasks/:taskId/score/:direction',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
|
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
|
||||||
req.checkParams('direction', res.t('directionUpDown')).notEmpty().isIn(['up', 'down']); // TODO what about rewards? maybe separate route?
|
req.checkParams('direction', res.t('directionUpDown')).notEmpty().isIn(['up', 'down']); // TODO what about rewards? maybe separate route?
|
||||||
@@ -297,7 +298,7 @@ api.scoreTask = {
|
|||||||
api.moveTask = {
|
api.moveTask = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tasks/move/:taskId/to/:position',
|
url: '/tasks/move/:taskId/to/:position',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
|
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
|
||||||
req.checkParams('position', res.t('positionRequired')).notEmpty().isNumeric();
|
req.checkParams('position', res.t('positionRequired')).notEmpty().isNumeric();
|
||||||
@@ -349,7 +350,7 @@ api.moveTask = {
|
|||||||
api.addChecklistItem = {
|
api.addChecklistItem = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tasks/:taskId/checklist',
|
url: '/tasks/:taskId/checklist',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -389,7 +390,7 @@ api.addChecklistItem = {
|
|||||||
api.scoreCheckListItem = {
|
api.scoreCheckListItem = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tasks/:taskId/checklist/:itemId/score',
|
url: '/tasks/:taskId/checklist/:itemId/score',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -432,7 +433,7 @@ api.scoreCheckListItem = {
|
|||||||
api.updateChecklistItem = {
|
api.updateChecklistItem = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: '/tasks/:taskId/checklist/:itemId',
|
url: '/tasks/:taskId/checklist/:itemId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -476,7 +477,7 @@ api.updateChecklistItem = {
|
|||||||
api.removeChecklistItem = {
|
api.removeChecklistItem = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: '/tasks/:taskId/checklist/:itemId',
|
url: '/tasks/:taskId/checklist/:itemId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -519,7 +520,7 @@ api.removeChecklistItem = {
|
|||||||
api.addTagToTask = {
|
api.addTagToTask = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: '/tasks/:taskId/tags/:tagId',
|
url: '/tasks/:taskId/tags/:tagId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -563,7 +564,7 @@ api.addTagToTask = {
|
|||||||
api.removeTagFromTask = {
|
api.removeTagFromTask = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: '/tasks/:taskId/tags/:tagId',
|
url: '/tasks/:taskId/tags/:tagId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
@@ -620,7 +621,7 @@ function _removeTaskTasksOrder (user, taskId) {
|
|||||||
api.deleteTask = {
|
api.deleteTask = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: '/tasks/:taskId',
|
url: '/tasks/:taskId',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
||||||
|
import cron from '../../middlewares/api-v3/cron';
|
||||||
import common from '../../../../common';
|
import common from '../../../../common';
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
@@ -13,7 +14,7 @@ let api = {};
|
|||||||
*/
|
*/
|
||||||
api.getUser = {
|
api.getUser = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
middlewares: [authWithHeaders()],
|
middlewares: [authWithHeaders(), cron],
|
||||||
url: '/user',
|
url: '/user',
|
||||||
handler (req, res) {
|
handler (req, res) {
|
||||||
let user = res.locals.user.toJSON();
|
let user = res.locals.user.toJSON();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import common from '../../../../common';
|
|||||||
import Task from '../../models/task';
|
import Task from '../../models/task';
|
||||||
// import Group from '../../models/group';
|
// import Group from '../../models/group';
|
||||||
|
|
||||||
|
// TODO check that it's usef everywhere
|
||||||
export default function cronMiddleware (req, res, next) {
|
export default function cronMiddleware (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
let analytics = res.analytics;
|
let analytics = res.analytics;
|
||||||
|
|||||||
Reference in New Issue
Block a user