Skip to content

Commit

Permalink
add org_policy_id
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan0xC committed Dec 31, 2024
1 parent 86a0d61 commit c5748d4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/api/core/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/db/models/event.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -29,7 +29,7 @@ db_object! {
pub device_type: Option<i32>,
pub ip_address: Option<String>,
pub event_date: NaiveDateTime,
pub policy_uuid: Option<String>,
pub policy_uuid: Option<OrgPolicyId>,
pub provider_uuid: Option<String>,
pub provider_user_uuid: Option<String>,
pub provider_org_uuid: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/db/models/org_policy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use derive_more::{AsRef, From};
use serde::Deserialize;
use serde_json::Value;

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -349,3 +350,6 @@ impl OrgPolicy {
false
}
}

#[derive(Clone, Debug, AsRef, DieselNewType, From, FromForm, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct OrgPolicyId(String);

0 comments on commit c5748d4

Please sign in to comment.