Node.js based forum software built for the modern web
feat: new search hooks
Barış Soner Uşaklıb5d38bc696f6
diff --git a/src/controllers/search.js b/src/controllers/search.jsindex 82aed2b308..238c167709 100644--- a/src/controllers/search.js+++ b/src/controllers/search.js@@ -29,11 +29,15 @@ searchController.search = async function (req, res, next) {'search:tags': privileges.global.can('search:tags', req.uid),});req.query.in = req.query.in || meta.config.searchDefaultIn || 'titlesposts';- const allowed = (req.query.in === 'users' && userPrivileges['search:users']) ||+ let allowed = (req.query.in === 'users' && userPrivileges['search:users']) ||(req.query.in === 'tags' && userPrivileges['search:tags']) ||(req.query.in === 'categories') ||(['titles', 'titlesposts', 'posts'].includes(req.query.in) && userPrivileges['search:content']);-+ ({ allowed } = await plugins.hooks.fire('filter:search.isAllowed', {+ uid: req.uid,+ query: req.query,+ allowed,+ }));if (!allowed) {return helpers.notAllowed(req, res);}diff --git a/src/search.js b/src/search.jsindex a46934ff2f..c1463486d2 100644--- a/src/search.js+++ b/src/search.js@@ -27,6 +27,10 @@ search.search = async function (data) {result = await categories.search(data);} else if (data.searchIn === 'tags') {result = await topics.searchAndLoadTags(data);+ } else if (data.searchIn) {+ result = await plugins.hooks.fire('filter:search.searchIn', {+ data,+ });} else {throw new Error('[[error:unknown-search-filter]]');}@@ -108,6 +112,7 @@ async function searchInContent(data) {returnData.posts = await posts.getPostSummaryByPids(metadata.pids, data.uid, {});await plugins.hooks.fire('filter:search.contentGetResult', { result: returnData, data: data });delete metadata.pids;+ delete metadata.data;return Object.assign(returnData, metadata);}