|
1 | | -//! Validated admin inputs, and the admin API's bodies built from stored records. |
| 1 | +//! Validated admin inputs. |
2 | 2 |
|
3 | 3 | use super::AdminError; |
4 | 4 | use chrono::Duration; |
5 | | -use piquel_admin_api::{ |
6 | | - Administrator, Client, Consent, Email, Identity, Invitation, Passkey, Session, User, |
7 | | -}; |
8 | | -use piquel_auth_protocol::oauth::ClientAuthMethod; |
9 | | -use piquel_repository::{ |
10 | | - StoredAdministrator, StoredConsent, StoredEmail, StoredExternalIdentity, StoredInvitation, |
11 | | - StoredOidcClient, StoredPasskey, StoredSession, StoredUser, |
12 | | -}; |
13 | 5 | use std::str::FromStr; |
14 | 6 | use thiserror::Error; |
15 | 7 |
|
@@ -97,120 +89,6 @@ impl Reason { |
97 | 89 | } |
98 | 90 | } |
99 | 91 |
|
100 | | -/// Builds the admin API body that shows a stored record. A trait, since both |
101 | | -/// types belong to other crates. |
102 | | -pub(super) trait View<T> { |
103 | | - /// The body showing `self`. |
104 | | - fn view(self) -> T; |
105 | | -} |
106 | | - |
107 | | -impl View<User> for StoredUser { |
108 | | - fn view(self) -> User { |
109 | | - User { |
110 | | - id: self.id, |
111 | | - username: self.username, |
112 | | - display_name: self.display_name, |
113 | | - status: self.status, |
114 | | - created_at: self.created_at, |
115 | | - } |
116 | | - } |
117 | | -} |
118 | | - |
119 | | -impl View<Email> for StoredEmail { |
120 | | - fn view(self) -> Email { |
121 | | - Email { |
122 | | - address: self.normalized_email, |
123 | | - verified_at: self.verified_at, |
124 | | - primary: self.is_primary, |
125 | | - } |
126 | | - } |
127 | | -} |
128 | | - |
129 | | -impl View<Passkey> for StoredPasskey { |
130 | | - /// Shows the label only, never the credential. |
131 | | - fn view(self) -> Passkey { |
132 | | - Passkey { |
133 | | - id: self.id, |
134 | | - name: self.friendly_name, |
135 | | - } |
136 | | - } |
137 | | -} |
138 | | - |
139 | | -impl View<Identity> for StoredExternalIdentity { |
140 | | - fn view(self) -> Identity { |
141 | | - Identity { |
142 | | - provider: self.provider, |
143 | | - email: self.linked_email, |
144 | | - } |
145 | | - } |
146 | | -} |
147 | | - |
148 | | -impl View<Session> for StoredSession { |
149 | | - fn view(self) -> Session { |
150 | | - Session { |
151 | | - id: self.id, |
152 | | - methods: self.authentication_methods, |
153 | | - authenticated_at: self.authenticated_at, |
154 | | - passkey_confirmed_at: self.passkey_confirmed_at, |
155 | | - last_seen_at: self.last_seen_at, |
156 | | - expires_at: self.expires_at, |
157 | | - } |
158 | | - } |
159 | | -} |
160 | | - |
161 | | -impl View<Consent> for StoredConsent { |
162 | | - fn view(self) -> Consent { |
163 | | - Consent { |
164 | | - client_id: self.client_id, |
165 | | - audience: self.audience, |
166 | | - scopes: self.scopes, |
167 | | - } |
168 | | - } |
169 | | -} |
170 | | - |
171 | | -impl View<Invitation> for StoredInvitation { |
172 | | - fn view(self) -> Invitation { |
173 | | - Invitation { |
174 | | - id: self.id, |
175 | | - created_at: self.created_at, |
176 | | - expires_at: self.expires_at, |
177 | | - redeemed_at: self.redeemed_at, |
178 | | - revoked_at: self.revoked_at, |
179 | | - } |
180 | | - } |
181 | | -} |
182 | | - |
183 | | -impl View<Client> for StoredOidcClient { |
184 | | - /// Replaces the secret digest with the authentication method it implies. |
185 | | - fn view(self) -> Client { |
186 | | - Client { |
187 | | - token_endpoint_auth_method: match self.client_secret_hash { |
188 | | - Some(_) => ClientAuthMethod::ClientSecretBasic, |
189 | | - None => ClientAuthMethod::None, |
190 | | - }, |
191 | | - id: self.id, |
192 | | - display_name: self.display_name, |
193 | | - redirect_uris: self.redirect_uris, |
194 | | - post_logout_uris: self.post_logout_uris, |
195 | | - allowed_scopes: self.allowed_scopes, |
196 | | - allowed_audiences: self.allowed_audiences, |
197 | | - allow_refresh: self.allow_refresh, |
198 | | - enabled: self.enabled, |
199 | | - trusted: self.trusted, |
200 | | - } |
201 | | - } |
202 | | -} |
203 | | - |
204 | | -impl View<Administrator> for StoredAdministrator { |
205 | | - fn view(self) -> Administrator { |
206 | | - Administrator { |
207 | | - user_id: self.user_id, |
208 | | - username: self.username, |
209 | | - granted_at: self.granted_at, |
210 | | - } |
211 | | - } |
212 | | -} |
213 | | - |
214 | 92 | #[cfg(test)] |
215 | 93 | mod tests { |
216 | 94 | //! Invitation lifetime parsing and reason bounds. |
|
0 commit comments