|
@@ -2,12 +2,14 @@ import {
|
|
|
pagePathUtils, AllSubscriptionStatusType, SubscriptionStatusType, ErrorV3,
|
|
pagePathUtils, AllSubscriptionStatusType, SubscriptionStatusType, ErrorV3,
|
|
|
} from '@growi/core';
|
|
} from '@growi/core';
|
|
|
|
|
|
|
|
|
|
+import ExternalUserGroup from '~/features/external-user-group/server/models/external-user-group';
|
|
|
import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
|
|
import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
|
|
|
import { generateAddActivityMiddleware } from '~/server/middlewares/add-activity';
|
|
import { generateAddActivityMiddleware } from '~/server/middlewares/add-activity';
|
|
|
import { apiV3FormValidator } from '~/server/middlewares/apiv3-form-validator';
|
|
import { apiV3FormValidator } from '~/server/middlewares/apiv3-form-validator';
|
|
|
import { excludeReadOnlyUser } from '~/server/middlewares/exclude-read-only-user';
|
|
import { excludeReadOnlyUser } from '~/server/middlewares/exclude-read-only-user';
|
|
|
import Subscription from '~/server/models/subscription';
|
|
import Subscription from '~/server/models/subscription';
|
|
|
import UserGroup from '~/server/models/user-group';
|
|
import UserGroup from '~/server/models/user-group';
|
|
|
|
|
+import { divideByType } from '~/server/util/granted-group';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:routes:apiv3:page'); // eslint-disable-line no-unused-vars
|
|
const logger = loggerFactory('growi:routes:apiv3:page'); // eslint-disable-line no-unused-vars
|
|
@@ -194,7 +196,7 @@ module.exports = (crowi) => {
|
|
|
updateGrant: [
|
|
updateGrant: [
|
|
|
param('pageId').isMongoId().withMessage('pageId is required'),
|
|
param('pageId').isMongoId().withMessage('pageId is required'),
|
|
|
body('grant').isInt().withMessage('grant is required'),
|
|
body('grant').isInt().withMessage('grant is required'),
|
|
|
- body('grantedGroup').optional().isMongoId().withMessage('grantedGroup must be a mongo id'),
|
|
|
|
|
|
|
+ body('grantedGroups').optional().isArray().withMessage('grantedGroups must be an array'),
|
|
|
],
|
|
],
|
|
|
export: [
|
|
export: [
|
|
|
query('format').isString().isIn(['md', 'pdf']),
|
|
query('format').isString().isIn(['md', 'pdf']),
|
|
@@ -454,27 +456,32 @@ module.exports = (crowi) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
- path, grant, grantedUsers, grantedGroup,
|
|
|
|
|
|
|
+ path, grant, grantedUsers, grantedGroups,
|
|
|
} = page;
|
|
} = page;
|
|
|
|
|
|
|
|
let isGrantNormalized;
|
|
let isGrantNormalized;
|
|
|
try {
|
|
try {
|
|
|
- isGrantNormalized = await crowi.pageGrantService.isGrantNormalized(req.user, path, grant, grantedUsers, grantedGroup, false, false);
|
|
|
|
|
|
|
+ isGrantNormalized = await crowi.pageGrantService.isGrantNormalized(req.user, path, grant, grantedUsers, grantedGroups, false, false);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error('Error occurred while processing isGrantNormalized.', err);
|
|
logger.error('Error occurred while processing isGrantNormalized.', err);
|
|
|
return res.apiv3Err(err, 500);
|
|
return res.apiv3Err(err, 500);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const currentPageUserGroup = await UserGroup.findOne({ _id: grantedGroup });
|
|
|
|
|
|
|
+ const { grantedUserGroups, grantedExternalUserGroups } = divideByType(grantedGroups);
|
|
|
|
|
+ const currentPageUserGroups = await UserGroup.find({ _id: { $in: grantedUserGroups } });
|
|
|
|
|
+ const currentPageExternalUserGroups = await ExternalUserGroup.find({ _id: { $in: grantedExternalUserGroups } });
|
|
|
|
|
+ currentPageUserGroups.map((group) => {
|
|
|
|
|
+ return { id: group._id, name: group.name };
|
|
|
|
|
+ });
|
|
|
const currentPageGrant = {
|
|
const currentPageGrant = {
|
|
|
grant,
|
|
grant,
|
|
|
- grantedGroup: currentPageUserGroup != null
|
|
|
|
|
- ? {
|
|
|
|
|
- id: currentPageUserGroup._id,
|
|
|
|
|
- name: currentPageUserGroup.name,
|
|
|
|
|
- }
|
|
|
|
|
- : null,
|
|
|
|
|
|
|
+ grantedUserGroups: currentPageUserGroups.map((group) => {
|
|
|
|
|
+ return { id: group._id, name: group.name };
|
|
|
|
|
+ }),
|
|
|
|
|
+ grantedExternalUserGroups: currentPageExternalUserGroups.map((group) => {
|
|
|
|
|
+ return { id: group._id, name: group.name };
|
|
|
|
|
+ }),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// page doesn't have parent page
|
|
// page doesn't have parent page
|
|
@@ -499,15 +506,20 @@ module.exports = (crowi) => {
|
|
|
return res.apiv3({ isGrantNormalized, grantData });
|
|
return res.apiv3({ isGrantNormalized, grantData });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const parentPageUserGroup = await UserGroup.findOne({ _id: parentPage.grantedGroup });
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ grantedUserGroups: parentGrantedUserGroupIds,
|
|
|
|
|
+ grantedExternalUserGroups: parentGrantedExternalUserGroupIds,
|
|
|
|
|
+ } = divideByType(parentPage.grantedGroup);
|
|
|
|
|
+ const parentPageUserGroups = await UserGroup.find({ _id: { $in: parentGrantedUserGroupIds } });
|
|
|
|
|
+ const parentPageExternalUserGroups = await ExternalUserGroup.find({ _id: { $in: parentGrantedExternalUserGroupIds } });
|
|
|
const parentPageGrant = {
|
|
const parentPageGrant = {
|
|
|
grant: parentPage.grant,
|
|
grant: parentPage.grant,
|
|
|
- grantedGroup: parentPageUserGroup != null
|
|
|
|
|
- ? {
|
|
|
|
|
- id: parentPageUserGroup._id,
|
|
|
|
|
- name: parentPageUserGroup.name,
|
|
|
|
|
- }
|
|
|
|
|
- : null,
|
|
|
|
|
|
|
+ grantedUserGroups: parentPageUserGroups.map((group) => {
|
|
|
|
|
+ return { id: group._id, name: group.name };
|
|
|
|
|
+ }),
|
|
|
|
|
+ grantedExternalUserGroups: parentPageExternalUserGroups.map((group) => {
|
|
|
|
|
+ return { id: group._id, name: group.name };
|
|
|
|
|
+ }),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const grantData = {
|
|
const grantData = {
|
|
@@ -544,7 +556,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
router.put('/:pageId/grant', loginRequiredStrictly, excludeReadOnlyUser, validator.updateGrant, apiV3FormValidator, async(req, res) => {
|
|
router.put('/:pageId/grant', loginRequiredStrictly, excludeReadOnlyUser, validator.updateGrant, apiV3FormValidator, async(req, res) => {
|
|
|
const { pageId } = req.params;
|
|
const { pageId } = req.params;
|
|
|
- const { grant, grantedGroup } = req.body;
|
|
|
|
|
|
|
+ const { grant, grantedGroups } = req.body;
|
|
|
|
|
|
|
|
const Page = crowi.model('Page');
|
|
const Page = crowi.model('Page');
|
|
|
|
|
|
|
@@ -558,7 +570,7 @@ module.exports = (crowi) => {
|
|
|
let data;
|
|
let data;
|
|
|
try {
|
|
try {
|
|
|
const shouldUseV4Process = false;
|
|
const shouldUseV4Process = false;
|
|
|
- const grantData = { grant, grantedGroup };
|
|
|
|
|
|
|
+ const grantData = { grant, grantedGroups };
|
|
|
data = await this.crowi.pageService.updateGrant(page, req.user, grantData, shouldUseV4Process);
|
|
data = await this.crowi.pageService.updateGrant(page, req.user, grantData, shouldUseV4Process);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|