hide private lists from list index if config.hidePrivate is true
diff --git a/site/api/preferences.lua b/site/api/preferences.lua
index 630ec27..45462c6 100644
--- a/site/api/preferences.lua
+++ b/site/api/preferences.lua
@@ -23,6 +23,7 @@
local cross = require 'lib/cross'
local smtp = require 'socket.smtp'
local config = require 'lib/config'
+local aaa = require 'lib/aaa'
function handle(r)
local now = r:clock()
@@ -182,6 +183,7 @@
}
}
+
for x,y in pairs (doc.aggregations.from.buckets) do
local list, domain = y.key:match("^<?(.-)%.(.-)>?$")
if domain and domain:match("^[-_a-z0-9.]+$") and list:match("^[-_a-z0-9.]+$") then
@@ -196,7 +198,60 @@
lists[domain][list] = y.doc_count
end
end
- r:ivm_set("pm_lists_cache_" ..r.hostname .."-" .. nowish, JSON.encode(lists))
+
+ -- hide private lists?
+ -- this invalidates any cache there is and forces a check for
+ -- private emails inside lists. If found and the current user
+ -- does not have access, the list is hidden
+ if config.hidePrivate then
+ local pdoc = elastic.raw {
+ aggs = {
+ from = {
+ terms = {
+ field = "list_raw",
+ size = 500000
+ }
+ }
+ },
+ query = {
+ bool = {
+ must = {
+ {
+ range = {
+ date = { gte = "now-90d" }
+ },
+ },
+ {
+ term = {
+ private = true
+ }
+ }
+ }
+ }
+ }
+ }
+ local rights = {}
+ if account then
+ rights = aaa.rights(r, account)
+ end
+ for x,y in pairs (pdoc.aggregations.from.buckets) do
+ local canAccess = false
+ local list, domain = y.key:match("^<?(.-)%.(.-)>?$")
+ local flid = list .. "." .. domain
+ for k, v in pairs(rights) do
+ if v == "*" or v == domain or v == flid then
+ canAccess = true
+ break
+ end
+ end
+ if not canAccess then
+ lists[domain] = lists[domain] or {}
+ lists[domain][list] = nil
+ end
+ end
+ else
+ r:ivm_set("pm_lists_cache_" ..r.hostname .."-" .. nowish, JSON.encode(lists))
+ end
end
-- Get notifs