im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! The administrator area: users, invitations, services and clients, mail, message, policy settings, signing |
| 2 | //! keys, the audit log and health. |
| 3 | //! |
| 4 | //! Every page and every form here calls [`require_admin`] (or [`require_admin_csrf`] for a form). A member, or |
| 5 | //! anyone signed out, gets the styled 404 before anything else happens, so the area does not reveal itself. |
| 6 | //! A form also checks its CSRF token before any side effect, and answers 403 when the token is wrong. |
| 7 | //! |
| 8 | //! Writes redirect (Post/Redirect/Get) with a short code in the query string: `?notice=<code>` for success, |
| 9 | //! `?error=<code>` for a refusal. The codes map to translated text in [`notice_text`] and [`error_text`]. A |
| 10 | //! write that changes what an admin page shows calls [`changed`], which wakes the page's live stream |
| 11 | //! (`/admin/events`). A write that changes what a person sees of their own account also bumps that account's |
| 12 | //! topic, so their open pages refresh. |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | use Deserialize; |
| 28 | use Result; |
| 29 | use ; |
| 30 | use ; |
| 31 | use Response; |
| 32 | use route; |
| 33 | use ; |
| 34 | |
| 35 | use craterequire_admin; |
| 36 | use crateLang; |
| 37 | use crate; |
| 38 | use crate; |
| 39 | use crate; |
| 40 | use crateAppState; |
| 41 | use crate; |
| 42 | |
| 43 | /// Rows per page of the long lists (users, mail, audit log). |
| 44 | pub const PAGE_SIZE: u32 = 50; |
| 45 | |
| 46 | /// The query of every admin list and of the redirects after a write. |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | /// The tabs of the administrator area. |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | /// The tab bar, with the current tab marked. |
| 72 | |
| 73 | pub async |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | /// The CSS class of one tab: the current one is marked for the screen reader and the style. |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | /// Notifies the admin pages that something they show has changed. Call it after the write commits. |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | /// The text of a success code, or `None` for an unknown code (which is then ignored). |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | /// The text of a refusal code, or `None` for an unknown code. |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | /// `path?error=<code>`, the redirect of a refused write. |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | /// `path?notice=<code>`, the redirect of a successful write. |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | /// The viewer's info and language for an admin page, after the admin check. |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | /// `GET /admin`: the first tab. Non-administrators get 404. |
| 179 | |
| 180 | async |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | /// `GET /admin/events`: the live stream of the admin pages. It sends one `changed` event for each admin |
| 186 | /// write, and the page fetches itself again. Non-administrators get 404. |
| 187 | /// |
| 188 | /// The session and the administrator role are checked again on every wake, before an event is sent. A |
| 189 | /// session that ended, or an account that lost the role or was disabled, ends the stream. |
| 190 | |
| 191 | async |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | /// A form with one button, and the CSRF token. `on` is sent as a hidden field; it is empty for most actions. |
| 221 | |
| 222 | pub async |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | /// The success notice and the alert of an admin page, drawn above its content. |
| 239 | |
| 240 | pub async |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 |