diff --git a/src/api/core/events.rs b/src/api/core/events.rs index 9427d0045e8..11ae66c7ebe 100644 --- a/src/api/core/events.rs +++ b/src/api/core/events.rs @@ -312,7 +312,7 @@ async fn _log_event( // 1600..=1699 Are organizational events, and they do not need the source_uuid // Policy Events 1700..=1799 => { - event.policy_uuid = Some(String::from(source_uuid)); + event.policy_uuid = Some(source_uuid.to_string().into()); } // Ignore others _ => {} diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 28eef5e0352..6244f6b4aa7 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -1886,7 +1886,7 @@ async fn put_policy( log_event( EventType::PolicyUpdated as i32, - &policy.uuid, + policy.uuid.as_ref(), &org_id, &headers.user.uuid, headers.device.atype, diff --git a/src/db/models/event.rs b/src/db/models/event.rs index 9f853f938e6..a7987cdb7ba 100644 --- a/src/db/models/event.rs +++ b/src/db/models/event.rs @@ -1,7 +1,7 @@ use crate::db::DbConn; use serde_json::Value; -use super::{CipherId, CollectionId, GroupId, MembershipId, OrganizationId, UserId}; +use super::{CipherId, CollectionId, GroupId, MembershipId, OrgPolicyId, OrganizationId, UserId}; use crate::{api::EmptyResult, error::MapResult, CONFIG}; use chrono::{NaiveDateTime, TimeDelta, Utc}; @@ -29,7 +29,7 @@ db_object! { pub device_type: Option, pub ip_address: Option, pub event_date: NaiveDateTime, - pub policy_uuid: Option, + pub policy_uuid: Option, pub provider_uuid: Option, pub provider_user_uuid: Option, pub provider_org_uuid: Option, diff --git a/src/db/models/mod.rs b/src/db/models/mod.rs index a78c4a9ab2c..90d17313b72 100644 --- a/src/db/models/mod.rs +++ b/src/db/models/mod.rs @@ -26,7 +26,7 @@ pub use self::event::{Event, EventType}; pub use self::favorite::Favorite; pub use self::folder::{Folder, FolderCipher, FolderId}; pub use self::group::{CollectionGroup, Group, GroupId, GroupUser}; -pub use self::org_policy::{OrgPolicy, OrgPolicyErr, OrgPolicyType}; +pub use self::org_policy::{OrgPolicy, OrgPolicyErr, OrgPolicyId, OrgPolicyType}; pub use self::organization::{ Membership, MembershipId, MembershipStatus, MembershipType, OrgApiKeyId, Organization, OrganizationApiKey, OrganizationId, diff --git a/src/db/models/org_policy.rs b/src/db/models/org_policy.rs index 78cf99731e7..304b37422a3 100644 --- a/src/db/models/org_policy.rs +++ b/src/db/models/org_policy.rs @@ -1,3 +1,4 @@ +use derive_more::{AsRef, From}; use serde::Deserialize; use serde_json::Value; @@ -12,7 +13,7 @@ db_object! { #[diesel(table_name = org_policies)] #[diesel(primary_key(uuid))] pub struct OrgPolicy { - pub uuid: String, + pub uuid: OrgPolicyId, pub org_uuid: OrganizationId, pub atype: i32, pub enabled: bool, @@ -64,7 +65,7 @@ pub enum OrgPolicyErr { impl OrgPolicy { pub fn new(org_uuid: OrganizationId, atype: OrgPolicyType, data: String) -> Self { Self { - uuid: crate::util::get_uuid(), + uuid: OrgPolicyId(crate::util::get_uuid()), org_uuid, atype: atype as i32, enabled: false, @@ -349,3 +350,6 @@ impl OrgPolicy { false } } + +#[derive(Clone, Debug, AsRef, DieselNewType, From, FromForm, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct OrgPolicyId(String);