Mercurial > prosody-hg
comparison plugins/mod_tombstones.lua @ 14212:55a7143a58ec
mod_tombstones: Add shell commands for listing and clearing tombstones
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 05 Jun 2026 16:24:55 +0100 |
| parents | a8ce6f45ba35 |
| children |
comparison
equal
deleted
inserted
replaced
| 14211:a8ce6f45ba35 | 14212:55a7143a58ec |
|---|---|
| 123 origin.send(st.error_reply(presence, "cancel", "gone", "User deleted")); | 123 origin.send(st.error_reply(presence, "cancel", "gone", "User deleted")); |
| 124 origin.send(st.presence({ type = "unsubscribe"; to = presence.attr.from; from = presence.attr.to })); | 124 origin.send(st.presence({ type = "unsubscribe"; to = presence.attr.from; from = presence.attr.to })); |
| 125 return true; | 125 return true; |
| 126 end | 126 end |
| 127 end, 1); | 127 end, 1); |
| 128 | |
| 129 --- shell commands | |
| 130 module:add_item("shell-command", { | |
| 131 section = "user"; | |
| 132 name = "list_deleted"; | |
| 133 desc = "List deleted user accounts (tombstones)"; | |
| 134 args = { | |
| 135 { name = "host", type = "string" }; | |
| 136 }; | |
| 137 host_selector = "host"; | |
| 138 handler = function (self, host) --luacheck: ignore 212/host | |
| 139 local c = 0; | |
| 140 for username in pairs(graveyard:get(nil)) do | |
| 141 c = c + 1; | |
| 142 self.session.print(username); | |
| 143 end | |
| 144 return true, ("Showing %d deleted accounts"):format(c); | |
| 145 end; | |
| 146 }); | |
| 147 | |
| 148 module:add_item("shell-command", { | |
| 149 section = "user"; | |
| 150 name = "forget"; | |
| 151 desc = "Forget a deleted user account (tombstone)"; | |
| 152 args = { | |
| 153 { name = "jid", type = "string" }; | |
| 154 }; | |
| 155 host_selector = "jid"; | |
| 156 handler = function (self, user_jid) --luacheck: ignore 212/self | |
| 157 local username = jid_node(user_jid); | |
| 158 if not has_tombstone(username) then | |
| 159 if require "core.usermanager".user_exists(username, module.host) then | |
| 160 return nil, "User account has not been deleted"; | |
| 161 else | |
| 162 return nil, "User account does not exist"; | |
| 163 end | |
| 164 end | |
| 165 | |
| 166 local ok, err = clear_tombstone(username); | |
| 167 if not ok then | |
| 168 return nil, ("Failed to remove tombstone: %s"):format(err); | |
| 169 end | |
| 170 | |
| 171 return true, "User account forgotten"; | |
| 172 end; | |
| 173 }); | |
| 174 |
