Skip to content

Commit dc7823f

Browse files
authored
BE-241: Fix system account archiving for Invitation entities (#8190)
1 parent 23c0283 commit dc7823f

File tree

2 files changed

+45
-26
lines changed
  • libs/@local/graph
    • postgres-store/src/store/postgres/knowledge/entity
    • store/src/entity

2 files changed

+45
-26
lines changed

libs/@local/graph/postgres-store/src/store/postgres/knowledge/entity/mod.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,32 +1849,34 @@ where
18491849
])
18501850
.change_context(UpdateError)?;
18511851

1852-
match policy_set
1853-
.evaluate(
1854-
&Request {
1855-
actor: policy_components.actor_id(),
1856-
action: ActionName::UpdateEntity,
1857-
resource: &ResourceId::Entity(params.entity_id.entity_uuid),
1858-
context: RequestContext::default(),
1859-
},
1860-
policy_components.context(),
1861-
)
1862-
.change_context(UpdateError)?
1863-
{
1864-
Authorized::Always => {}
1865-
Authorized::Never => {
1866-
return Err(Report::new(UpdateError)
1867-
.attach_opaque(StatusCode::PermissionDenied)
1868-
.attach("The actor does not have permission to update the entity")
1869-
.attach(
1870-
previous_entity
1871-
.metadata
1872-
.entity_type_ids
1873-
.iter()
1874-
.map(VersionedUrl::to_string)
1875-
.collect::<Vec<_>>()
1876-
.join(", "),
1877-
));
1852+
if params.is_update() {
1853+
match policy_set
1854+
.evaluate(
1855+
&Request {
1856+
actor: policy_components.actor_id(),
1857+
action: ActionName::UpdateEntity,
1858+
resource: &ResourceId::Entity(params.entity_id.entity_uuid),
1859+
context: RequestContext::default(),
1860+
},
1861+
policy_components.context(),
1862+
)
1863+
.change_context(UpdateError)?
1864+
{
1865+
Authorized::Always => {}
1866+
Authorized::Never => {
1867+
return Err(Report::new(UpdateError)
1868+
.attach_opaque(StatusCode::PermissionDenied)
1869+
.attach("The actor does not have permission to update the entity")
1870+
.attach(
1871+
previous_entity
1872+
.metadata
1873+
.entity_type_ids
1874+
.iter()
1875+
.map(VersionedUrl::to_string)
1876+
.collect::<Vec<_>>()
1877+
.join(", "),
1878+
));
1879+
}
18781880
}
18791881
}
18801882

libs/@local/graph/store/src/entity/store.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,23 @@ pub struct PatchEntityParams {
457457
pub provenance: ProvidedEntityEditionProvenance,
458458
}
459459

460+
impl PatchEntityParams {
461+
/// Returns `true` if the parameters represents an update.
462+
///
463+
/// An update is defined as any change to the entity's type IDs, properties, or draft status. If
464+
/// only the confidence is updated without changing the archive-state, this is also considered
465+
/// an update. On the counterary, if only the confidence is updated along with an archive-state
466+
/// change, the confidence is used for the new entity edition.
467+
// TODO(BE-224): Fix edge-case that the confidence could be updated by archiving/unarchiving.
468+
#[must_use]
469+
pub fn is_update(&self) -> bool {
470+
!self.entity_type_ids.is_empty()
471+
|| !self.properties.is_empty()
472+
|| self.draft.is_some()
473+
|| (self.archived.is_none() && self.confidence.is_some())
474+
}
475+
}
476+
460477
#[derive(Debug, Deserialize)]
461478
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
462479
#[serde(rename_all = "camelCase", deny_unknown_fields)]

0 commit comments

Comments
 (0)