generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-154980 - Milo advanced page publishing (#2846)
* sidekick publish button state * bulk publish publish config errors * dial in functionality add custom messages and denylist * publish permission in bulk pub testing * test permissions and utils coverage * remove extra variable assignment * add no signin message * put back timout for init sidekick pub button decoration * fix edge case where sk event isnt fired on refresh * fix unit tests * put back var assignment * dial in user can publish funtion * move publish utility to tools dir * Update tools/utils/utils.js Co-authored-by: Ryan Parrish <churchofslidin@gmail.com> --------- Co-authored-by: Ryan Parrish <churchofslidin@gmail.com>
- Loading branch information
1 parent
a7c31b7
commit 8fd5925
Showing
9 changed files
with
183 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getCustomConfig } from '../../../tools/utils/utils.js'; | ||
|
||
const userCanPublishPage = async (detail, isBulk = true) => { | ||
if (!detail) return false; | ||
const { live, profile, webPath } = detail; | ||
let canPublish = isBulk ? live?.permissions?.includes('write') : true; | ||
let message = 'Publishing is currently disabled for this page'; | ||
const config = await getCustomConfig('/.milo/publish-permissions-config.json'); | ||
const item = config?.urls?.data?.find(({ url }) => ( | ||
url.endsWith('**') ? webPath.includes(url.slice(0, -2)) : url === webPath | ||
)); | ||
if (item) { | ||
canPublish = false; | ||
if (item.message) message = item.message; | ||
const group = config[item.group]; | ||
if (group && profile?.email) { | ||
let isDeny; | ||
const user = group.data?.find(({ allow, deny }) => { | ||
if (deny) { | ||
/* c8 ignore next 3 */ | ||
isDeny = true; | ||
return deny === profile.email; | ||
} | ||
return allow === profile.email; | ||
}); | ||
canPublish = isDeny ? !user : !!user; | ||
} | ||
} | ||
return { canPublish, message }; | ||
}; | ||
|
||
export default userCanPublishPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/blocks/bulk-publish-v2/mocks/response/permissions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"urls": { | ||
"total": 4, | ||
"offset": 0, | ||
"limit": 4, | ||
"data": [ | ||
{ | ||
"url": "/not/a/valid/path", | ||
"group": "gwp-test", | ||
"message": "Publishing disabled until the test is over" | ||
} | ||
] | ||
}, | ||
"gwp-test": { | ||
"total": 2, | ||
"offset": 0, | ||
"limit": 2, | ||
"data": [ | ||
{ "allow": "testuser@adobe.com" }, | ||
{ "allow": "testuser1@adobe.com" } | ||
] | ||
}, | ||
":version": 3, | ||
":names": ["urls", "gwp-US", "no-publish", "gwp-FR"], | ||
":type": "multi-sheet" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters