(
&self,
request: Request<()>,
)
| 158 | } |
| 159 | |
| 160 | async fn profile( |
| 161 | &self, |
| 162 | request: Request<()>, |
| 163 | ) -> Result<Response<api::ProfileResponse>, Status> { |
| 164 | self.validator |
| 165 | .validate(request.extensions(), validator::ValidateActiveUser::new()) |
| 166 | .await?; |
| 167 | |
| 168 | let auth_id = request.extensions().get::<AuthID>().unwrap(); |
| 169 | let id = match auth_id { |
| 170 | AuthID::User(id) => id, |
| 171 | _ => { |
| 172 | return Err(Status::internal("no user id")); |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | let u = user::get(id).await.map_err(|e| e.status())?; |
| 177 | let tenants = tenant::get_tenant_users_for_user(id) |
| 178 | .await |
| 179 | .map_err(|e| e.status())?; |
| 180 | let device_profiles = tenant::get_tenant_user_device_profiles_for_user(*id) |
| 181 | .await |
| 182 | .map_err(|e| e.status())?; |
| 183 | let applications = tenant::get_tenant_user_applications_for_user(*id) |
| 184 | .await |
| 185 | .map_err(|e| e.status())?; |
| 186 | |
| 187 | Ok(Response::new(api::ProfileResponse { |
| 188 | user: Some(api::User { |
| 189 | id: u.id.to_string(), |
| 190 | email: u.email, |
| 191 | is_active: u.is_active, |
| 192 | is_admin: u.is_admin, |
| 193 | note: u.note, |
| 194 | }), |
| 195 | tenants: tenants |
| 196 | .iter() |
| 197 | .map(|i| api::UserTenantLink { |
| 198 | created_at: Some(helpers::datetime_to_prost_timestamp(&i.created_at)), |
| 199 | updated_at: Some(helpers::datetime_to_prost_timestamp(&i.updated_at)), |
| 200 | tenant_id: i.tenant_id.to_string(), |
| 201 | is_admin: i.is_admin, |
| 202 | is_device_admin: i.is_device_admin, |
| 203 | is_gateway_admin: i.is_gateway_admin, |
| 204 | }) |
| 205 | .collect(), |
| 206 | device_profiles: device_profiles |
| 207 | .iter() |
| 208 | .map(|dp| api::UserDeviceProfileLink { |
| 209 | created_at: Some(helpers::datetime_to_prost_timestamp(&dp.created_at)), |
| 210 | device_profile_id: dp.device_profile_id.to_string(), |
| 211 | }) |
| 212 | .collect(), |
| 213 | applications: applications |
| 214 | .iter() |
| 215 | .map(|a| api::UserApplicationLink { |
| 216 | created_at: Some(helpers::datetime_to_prost_timestamp(&a.created_at)), |
| 217 | application_id: a.application_id.to_string(), |
no test coverage detected