scufflecloud_core_cedar/models/
users.rs

1use core_db_types::models::{NewUserEmailRequest, User, UserEmail, UserGoogleAccount};
2use ext_traits::OptionExt;
3
4use crate::macros::{cedar_entity, cedar_entity_id};
5use crate::{CedarIdentifiable, EntityTypeName, JsonEntityUid, entity_type_name};
6
7cedar_entity_id!(User);
8
9impl crate::CedarEntity for User {
10    async fn parents(
11        &self,
12        global: &impl core_traits::Global,
13    ) -> Result<impl IntoIterator<Item = JsonEntityUid>, tonic::Status> {
14        Ok(global
15            .organization_member_by_user_id_loader()
16            .load(self.id)
17            .await
18            .ok()
19            .into_tonic_internal_err("failed to query organization members")?
20            .into_iter()
21            .flatten()
22            .map(|m| m.organization_id)
23            .map(|id| id.entity_uid()))
24    }
25}
26
27impl crate::CedarIdentifiable for UserEmail {
28    const ENTITY_TYPE: EntityTypeName = entity_type_name!("UserEmail");
29
30    fn entity_id(&self) -> cedar_policy::EntityId {
31        cedar_policy::EntityId::new(&self.email)
32    }
33}
34
35impl crate::CedarEntity for UserEmail {}
36
37cedar_entity!(NewUserEmailRequest);
38
39impl crate::CedarIdentifiable for UserGoogleAccount {
40    const ENTITY_TYPE: EntityTypeName = entity_type_name!("UserGoogleAccount");
41
42    fn entity_id(&self) -> cedar_policy::EntityId {
43        cedar_policy::EntityId::new(&self.sub)
44    }
45}
46
47impl crate::CedarEntity for UserGoogleAccount {}