|
|
@@ -854,26 +854,34 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.error('Parameters body and path are required.'));
|
|
|
}
|
|
|
|
|
|
+ let createdPage = undefined;
|
|
|
const ignoreNotFound = true;
|
|
|
Page.findPage(pagePath, req.user, null, ignoreNotFound)
|
|
|
- .then(function(data) {
|
|
|
- if (data !== null) {
|
|
|
- throw new Error('Page exists');
|
|
|
- }
|
|
|
+ .then(function(data) {
|
|
|
+ if (data !== null) {
|
|
|
+ throw new Error('Page exists');
|
|
|
+ }
|
|
|
|
|
|
- return Page.create(pagePath, body, req.user, { grant: grant, grantUserGroupId: grantUserGroupId});
|
|
|
- }).then(function(data) {
|
|
|
- if (!data) {
|
|
|
- throw new Error('Failed to create page.');
|
|
|
- }
|
|
|
- const result = { page: data.toObject() };
|
|
|
+ return Page.create(pagePath, body, req.user, { grant: grant, grantUserGroupId: grantUserGroupId});
|
|
|
+ })
|
|
|
+ .then(function(data) {
|
|
|
+ if (!data) {
|
|
|
+ throw new Error('Failed to create page.');
|
|
|
+ }
|
|
|
+ createdPage = data.toObject();
|
|
|
+ const result = { page: createdPage };
|
|
|
|
|
|
- result.page.lastUpdateUser = User.filterToPublicFields(data.lastUpdateUser);
|
|
|
- result.page.creator = User.filterToPublicFields(data.creator);
|
|
|
- return res.json(ApiResponse.success(result));
|
|
|
- }).catch(function(err) {
|
|
|
- return res.json(ApiResponse.error(err));
|
|
|
- });
|
|
|
+ result.page.lastUpdateUser = User.filterToPublicFields(data.lastUpdateUser);
|
|
|
+ result.page.creator = User.filterToPublicFields(data.creator);
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ // global notification
|
|
|
+ globalNotificationService.notifyPageCreate(createdPage);
|
|
|
+ });
|
|
|
|
|
|
};
|
|
|
|
|
|
@@ -902,30 +910,37 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.error('page_id and body are required.'));
|
|
|
}
|
|
|
|
|
|
+ let updatedPage = undefined;
|
|
|
Page.findPageByIdAndGrantedUser(pageId, req.user)
|
|
|
- .then(function(pageData) {
|
|
|
- if (pageData && revisionId !== null && !pageData.isUpdatable(revisionId)) {
|
|
|
- throw new Error('Revision error.');
|
|
|
- }
|
|
|
+ .then(function(pageData) {
|
|
|
+ if (pageData && revisionId !== null && !pageData.isUpdatable(revisionId)) {
|
|
|
+ throw new Error('Revision error.');
|
|
|
+ }
|
|
|
|
|
|
- const grantOption = {};
|
|
|
- if (grant != null) {
|
|
|
- grantOption.grant = grant;
|
|
|
- }
|
|
|
- if (grantUserGroupId != null) {
|
|
|
- grantOption.grantUserGroupId = grantUserGroupId;
|
|
|
- }
|
|
|
- return Page.updatePage(pageData, pageBody, req.user, grantOption);
|
|
|
- }).then(function(pageData) {
|
|
|
- const result = {
|
|
|
- page: pageData.toObject(),
|
|
|
- };
|
|
|
- result.page.lastUpdateUser = User.filterToPublicFields(result.page.lastUpdateUser);
|
|
|
- return res.json(ApiResponse.success(result));
|
|
|
- }).catch(function(err) {
|
|
|
- debug('error on _api/pages.update', err);
|
|
|
- return res.json(ApiResponse.error(err));
|
|
|
- });
|
|
|
+ const grantOption = {};
|
|
|
+ if (grant != null) {
|
|
|
+ grantOption.grant = grant;
|
|
|
+ }
|
|
|
+ if (grantUserGroupId != null) {
|
|
|
+ grantOption.grantUserGroupId = grantUserGroupId;
|
|
|
+ }
|
|
|
+ return Page.updatePage(pageData, pageBody, req.user, grantOption);
|
|
|
+ })
|
|
|
+ .then(function(pageData) {
|
|
|
+ updatedPage = pageData.toObject();
|
|
|
+ const result = { page: updatedPage };
|
|
|
+
|
|
|
+ result.page.lastUpdateUser = User.filterToPublicFields(result.page.lastUpdateUser);
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ })
|
|
|
+ .catch(function(err) {
|
|
|
+ debug('error on _api/pages.update', err);
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ // global notification
|
|
|
+ globalNotificationService.notifyPageEdit(updatedPage);
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
/**
|