Software /
code /
prosody
Annotate
tools/form2table.lua @ 12658:7ca5645f46cd
usermanager: Remove concept of global authz provider
Rationale:
- Removes a bunch of code!
- We don't have many cases where an actor is not bound to one of our hosts
- A notable exception is the admin shell, but if we ever attempt to lock those
sessions down, there is a load of other work that also has to be done. And
it's not clear if we would need a global authz provider for that anyway.
- Removes an extra edge case from the necessary mental model for operators
- Sessions that aren't bound to a host generally are anonymous or have an
alternative auth model (such as by IP addres).
- With the encapsulation now provided by util.roles, ad-hoc "detached roles"
can still be created anyway by code that needs them.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 12 Aug 2022 16:21:57 +0100 |
parent | 11194:9d1ce6f28401 |
child | 13142:879a6a33c21b |
rev | line source |
---|---|
11194
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Read an XML dataform and spit out a serialized Lua table of it |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local function from_stanza(stanza) |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local layout = { |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 title = stanza:get_child_text("title"); |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 instructions = stanza:get_child_text("instructions"); |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 }; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 for tag in stanza:childtags("field") do |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local field = { |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 name = tag.attr.var; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 type = tag.attr.type; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 label = tag.attr.label; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 desc = tag:get_child_text("desc"); |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 required = tag:get_child("required") and true or nil; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 value = tag:get_child_text("value"); |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 options = nil; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 }; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 if field.type == "list-single" or field.type == "list-multi" then |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local options = {}; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 for option in tag:childtags("option") do |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 options[#options+1] = { label = option.attr.label, value = option:get_child_text("value") }; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 field.options = options; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if field.type == "jid-multi" or field.type == "list-multi" or field.type == "text-multi" then |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 local values = {}; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 for value in tag:childtags("value") do |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 values[#values+1] = value:get_text(); |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 if field.type == "text-multi" then |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 values = table.concat(values, "\n"); |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 field.value = values; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 if field.type == "boolean" then |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 field.value = field.value == "true" or field.value == "1"; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 layout[#layout+1] = field; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 return layout; |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
9d1ce6f28401
tools/form2table: Convert XEP-0004 dataform from XML to util.dataforms Lua format
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 print("dataforms.new " .. require "util.serialization".serialize(from_stanza(require "util.xml".parse(io.read("*a"))), { unquoted = true })) |