annotate mod_alias/mod_alias.lua @ 5418:f2c7bb3af600

mod_http_oauth2: Add role selector to consent page List includes all roles available to the user, if more than one. Defaults to either the first role in the scope string or the users primary role. Earlier draft listed all roles, but having options that can't be selected is bad UX and the entire list of all roles on the server could be long, and perhaps even sensitive. Allows e.g. picking a role with fewer permissions than what might otherwise have been selected. UX wise, doing this with more checkboxes or possibly radio buttons would have been confusion and/or looked messier. Fixes the previous situation where unselecting a role would default to the primary role, which could be more permissions than requested.
author Kim Alvefur <zash@zash.se>
date Fri, 05 May 2023 01:23:13 +0200
parents 65082d91950e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1953
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
1 -- Copyright (C) 2015 Travis Burtrum
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
2 -- This file is MIT/X11 licensed.
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
3
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
4 -- set like so in prosody config, works on full or bare jids, or hosts:
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
5 --aliases = {
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
6 -- ["old@example.net"] = "new@example.net";
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
7 -- ["you@example.com"] = "you@example.net";
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
8 -- ["conference.example.com"] = "conference.example.net";
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
9 --}
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
10
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
11 local aliases = module:get_option("aliases", {});
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
12 local alias_response = module:get_option("alias_response", "User $alias can be contacted at $target");
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
13
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
14 local st = require "util.stanza";
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
15
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
16 function handle_alias(event)
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
17
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
18 if event.stanza.attr.type ~= "error" then
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
19 local alias = event.stanza.attr.to;
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
20 local target = aliases[alias];
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
21 if target then
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
22 local replacements = {
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
23 alias = alias,
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
24 target = target
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
25 };
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
26 local error_message = alias_response:gsub("%$([%w_]+)", function (v)
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
27 return replacements[v] or nil;
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
28 end);
2887
65082d91950e Many modules: Simplify st.message(…):tag("body"):text(…):up() into st.message(…, …)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 1953
diff changeset
29 local message = st.message({ type = "chat", from = alias, to = event.stanza.attr.from }, error_message);
1953
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
30 module:send(message);
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
31 return event.origin.send(st.error_reply(event.stanza, "cancel", "gone", error_message));
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
32 end
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
33 end
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
34
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
35 end
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
36
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
37 module:hook("message/bare", handle_alias, 300);
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
38 module:hook("message/full", handle_alias, 300);
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
39 module:hook("message/host", handle_alias, 300);
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
40
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
41 module:hook("presence/bare", handle_alias, 300);
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
42 module:hook("presence/full", handle_alias, 300);
0c3ba5ff7a3b mod_alias: New alias module
moparisthebest <admin@moparisthebest.com>
parents:
diff changeset
43 module:hook("presence/host", handle_alias, 300);