| 1 | //! Shared invite links: before registration opened, one link staff handed |
| 2 | //! to a group (a conference's judges, a post, a community), made in sudo. |
| 3 | //! |
| 4 | //! None are made or used any more: anyone may register, and a shared |
| 5 | //! link's code is now an unknown code that sign-up ignores. The tables |
| 6 | //! (`shared_invites`, `shared_invite_uses`) keep what they recorded, so |
| 7 | //! sudo still shows "Joined through <label>" for an account made with one. |
| 8 | |
| 9 | use g1t_contracts::identity::SharedInviteSource; |
| 10 | use serde::Deserialize; |
| 11 | use worker::Result; |
| 12 | |
| 13 | use crate::Identity; |
| 14 | |
| 15 | impl Identity { |
| 16 | /// The shared link an account was made with, if it was. |
| 17 | pub(crate) async fn shared_source(&self, user_id: &str) -> Result<Option<SharedInviteSource>> { |
| 18 | #[derive(Deserialize)] |
| 19 | struct Row { |
| 20 | id: String, |
| 21 | label: String, |
| 22 | } |
| 23 | Ok(self |
| 24 | .db |
| 25 | .prepare( |
| 26 | "SELECT s.id, s.label FROM shared_invite_uses u JOIN shared_invites s ON s.id = u.shared_invite_id |
| 27 | WHERE u.user_id = ?", |
| 28 | ) |
| 29 | .bind(&[user_id.into()])? |
| 30 | .first::<Row>(None) |
| 31 | .await? |
| 32 | .map(|row| SharedInviteSource { id: row.id, label: row.label })) |
| 33 | } |
| 34 | } |