Skip to content

Commit

Permalink
move publish utility to tools dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Sartxi committed Sep 11, 2024
1 parent 62426d4 commit 35788f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion libs/blocks/bulk-publish-v2/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { userCanPublishPage } from '../../utils/utils.js';
import userCanPublishPage from '../../tools/utils/publish.js';
import {
PROCESS_TYPES,
getErrorText,
Expand Down
32 changes: 32 additions & 0 deletions libs/tools/utils/publish.js
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;
2 changes: 1 addition & 1 deletion libs/utils/sidekick-decorate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { userCanPublishPage } from './utils.js';
import userCanPublishPage from '../tools/utils/publish.js';

const PUBLISH_BTN = '.publish.plugin button';
const BACKUP_PROFILE = '.profile-email';
Expand Down
31 changes: 0 additions & 31 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-console */

import { getCustomConfig } from '../../tools/utils/utils.js';

const MILO_TEMPLATES = [
'404',
'featured-story',
Expand Down Expand Up @@ -1297,32 +1295,3 @@ export function loadLana(options = {}) {
}

export const reloadPage = () => window.location.reload();

export 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 };
};

0 comments on commit 35788f9

Please sign in to comment.