Comparison

mod_http_muc_log/mod_http_muc_log.lua @ 3059:14d8f2a9d5f4

mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
author Kim Alvefur <zash@zash.se>
date Mon, 28 May 2018 20:11:37 +0200
parent 3058:4d46658b6998
child 3060:982668000163
comparison
equal deleted inserted replaced
3058:4d46658b6998 3059:14d8f2a9d5f4
46 link.path = url.build_path(path); 46 link.path = url.build_path(path);
47 return url.build(link); 47 return url.build(link);
48 end 48 end
49 end 49 end
50 50
51 local function public_room(room) -- : boolean 51 -- Whether room can be joined by anyone
52 local function open_room(room) -- : boolean
52 if type(room) == "string" then 53 if type(room) == "string" then
53 room = get_room(room); 54 room = get_room(room);
54 end 55 end
55 if not room then 56 if not room then
56 return nil; 57 return nil;
57 end 58 end
58 59
59 if (room.get_hidden or room.is_hidden)(room) then
60 return nil;
61 end
62
63 if (room.get_members_only or room.is_members_only)(room) then 60 if (room.get_members_only or room.is_members_only)(room) then
61 return false;
62 end
63
64 if room:get_password() then
64 return false; 65 return false;
65 end 66 end
66 67
67 return true; 68 return true;
68 end 69 end
95 -- Produce the calendar view 96 -- Produce the calendar view
96 local function years_page(event, path) 97 local function years_page(event, path)
97 local response = event.response; 98 local response = event.response;
98 99
99 local room = nodeprep(path:match("^(.*)/$")); 100 local room = nodeprep(path:match("^(.*)/$"));
100 if not room or not public_room(room) then return end 101 local is_open = open_room(room);
102 if is_open == nil then
103 return -- implicit 404
104 elseif is_open == false then
105 return 403;
106 end
101 107
102 -- Collect each date that has messages 108 -- Collect each date that has messages
103 -- convert it to a year / month / day tree 109 -- convert it to a year / month / day tree
104 local date_list = archive.dates and archive:dates(room); 110 local date_list = archive.dates and archive:dates(room);
105 local dates = mt.new(); 111 local dates = mt.new();
198 local room, date = path:match("^(.-)/(%d%d%d%d%-%d%d%-%d%d)$"); 204 local room, date = path:match("^(.-)/(%d%d%d%d%-%d%d%-%d%d)$");
199 room = nodeprep(room); 205 room = nodeprep(room);
200 if not room then 206 if not room then
201 return years_page(event, path); 207 return years_page(event, path);
202 end 208 end
203 if not public_room(room) then return end 209 local is_open = open_room(room);
210 if is_open == nil then
211 return -- implicit 404
212 elseif is_open == false then
213 return 403;
214 end
204 local day_start = datetime.parse(date.."T00:00:00Z"); 215 local day_start = datetime.parse(date.."T00:00:00Z");
205 216
206 local logs, i = {}, 1; 217 local logs, i = {}, 1;
207 local iter, err = archive:find(room, { 218 local iter, err = archive:find(room, {
208 ["start"] = day_start; 219 ["start"] = day_start;