|
|
@@ -1,5 +1,6 @@
|
|
|
const mongoose = require('mongoose');
|
|
|
const nodePath = require('path');
|
|
|
+const { pathUtils } = require('growi-commons');
|
|
|
|
|
|
/**
|
|
|
* parent schema for GlobalNotificationSetting model
|
|
|
@@ -10,7 +11,9 @@ const globalNotificationSettingSchema = new mongoose.Schema({
|
|
|
triggerEvents: { type: [String] },
|
|
|
});
|
|
|
|
|
|
-
|
|
|
+/*
|
|
|
+* e.g. "/a/b/c" => ["/a/b/c", "/a/b", "/a", "/"]
|
|
|
+*/
|
|
|
const generatePathsOnTree = (path, pathList) => {
|
|
|
pathList.push(path);
|
|
|
|
|
|
@@ -23,11 +26,16 @@ const generatePathsOnTree = (path, pathList) => {
|
|
|
return generatePathsOnTree(newPath, pathList);
|
|
|
};
|
|
|
|
|
|
+/*
|
|
|
+* e.g. "/a/b/c" => ["/a/b/c", "/a/b", "/a", "/"]
|
|
|
+*/
|
|
|
const generatePathsToMatch = (originalPath) => {
|
|
|
const pathList = generatePathsOnTree(originalPath, []);
|
|
|
return pathList.map((path) => {
|
|
|
+ // except for the original trigger path ("/a/b/c"), append "*" to find all matches
|
|
|
+ // e.g. ["/a/b/c", "/a/b", "/a", "/"] => ["/a/b/c", "/a/b/*", "/a/*", "/*"]
|
|
|
if (path !== originalPath) {
|
|
|
- return `${path}/*`;
|
|
|
+ return `${pathUtils.addTrailingSlash(path)}*`;
|
|
|
}
|
|
|
|
|
|
return path;
|