|
|
@@ -1,5 +1,7 @@
|
|
|
// TODO remove this setting after implemented all
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
+import { SupportedAction } from '~/interfaces/activity';
|
|
|
+import { generateAddActivityMiddleware } from '~/server/middlewares/add-activity';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
|
|
|
@@ -28,9 +30,13 @@ module.exports = (crowi) => {
|
|
|
const loginRequired = require('../../middlewares/login-required')(crowi);
|
|
|
const adminRequired = require('../../middlewares/admin-required')(crowi);
|
|
|
const csrf = require('../../middlewares/csrf')(crowi);
|
|
|
+ const addActivity = generateAddActivityMiddleware(crowi);
|
|
|
+
|
|
|
const ShareLink = crowi.model('ShareLink');
|
|
|
const Page = crowi.model('Page');
|
|
|
|
|
|
+ const activityEvent = crowi.event('activity');
|
|
|
+
|
|
|
/**
|
|
|
* middleware to limit link sharing
|
|
|
*/
|
|
|
@@ -129,7 +135,7 @@ module.exports = (crowi) => {
|
|
|
* description: Succeeded to create one share link
|
|
|
*/
|
|
|
|
|
|
- router.post('/', loginRequired, linkSharingRequired, csrf, validator.shareLinkStatus, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.post('/', loginRequired, linkSharingRequired, csrf, addActivity, validator.shareLinkStatus, apiV3FormValidator, async(req, res) => {
|
|
|
const { relatedPage, expiredAt, description } = req.body;
|
|
|
|
|
|
const page = await Page.findByIdAndViewer(relatedPage, req.user);
|
|
|
@@ -144,6 +150,9 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
const postedShareLink = await ShareLink.create({ relatedPage, expiredAt, description });
|
|
|
+
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_SHARE_LINK_CREATE });
|
|
|
+
|
|
|
return res.apiv3(postedShareLink, 201);
|
|
|
}
|
|
|
catch (err) {
|
|
|
@@ -178,7 +187,7 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to delete o all share links related one page
|
|
|
*/
|
|
|
- router.delete('/', loginRequired, csrf, validator.deleteShareLinks, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.delete('/', loginRequired, csrf, addActivity, validator.deleteShareLinks, apiV3FormValidator, async(req, res) => {
|
|
|
const { relatedPage } = req.query;
|
|
|
|
|
|
const page = await Page.findByIdAndViewer(relatedPage, req.user);
|
|
|
@@ -191,6 +200,9 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
const deletedShareLink = await ShareLink.remove({ relatedPage });
|
|
|
+
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_SHARE_LINK_DELETE_BY_PAGE });
|
|
|
+
|
|
|
return res.apiv3(deletedShareLink);
|
|
|
}
|
|
|
catch (err) {
|
|
|
@@ -211,11 +223,14 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to remove all share links
|
|
|
*/
|
|
|
- router.delete('/all', loginRequired, adminRequired, csrf, async(req, res) => {
|
|
|
+ router.delete('/all', loginRequired, adminRequired, csrf, addActivity, async(req, res) => {
|
|
|
|
|
|
try {
|
|
|
const deletedShareLink = await ShareLink.deleteMany({});
|
|
|
const { deletedCount } = deletedShareLink;
|
|
|
+
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_SHARE_LINK_ALL_DELETE });
|
|
|
+
|
|
|
return res.apiv3({ deletedCount });
|
|
|
}
|
|
|
catch (err) {
|
|
|
@@ -247,7 +262,7 @@ module.exports = (crowi) => {
|
|
|
* 200:
|
|
|
* description: Succeeded to delete one share link
|
|
|
*/
|
|
|
- router.delete('/:id', loginRequired, csrf, validator.deleteShareLink, apiV3FormValidator, async(req, res) => {
|
|
|
+ router.delete('/:id', loginRequired, csrf, addActivity, validator.deleteShareLink, apiV3FormValidator, async(req, res) => {
|
|
|
const { id } = req.params;
|
|
|
const { user } = req;
|
|
|
|
|
|
@@ -267,6 +282,9 @@ module.exports = (crowi) => {
|
|
|
|
|
|
// remove
|
|
|
await shareLinkToDelete.remove();
|
|
|
+
|
|
|
+ activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_SHARE_LINK_DELETE });
|
|
|
+
|
|
|
return res.apiv3({ deletedShareLink: shareLinkToDelete });
|
|
|
}
|
|
|
catch (err) {
|