Skip to content

Commit

Permalink
check for duplicates before updating acr
Browse files Browse the repository at this point in the history
  • Loading branch information
garciafdezpatricia committed Apr 22, 2024
1 parent 53c0c25 commit 071d6fe
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/acp/control.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { ThingPersisted, Url, UrlString } from "../interfaces";
import { getSourceUrl } from "../resource/resource";
import { internal_cloneResource } from "../resource/resource.internal";
import { addIri } from "../thing/add";
import { getIriAll } from "../thing/get";
import { getIriAll, getUrlAll } from "../thing/get";
import { removeAll, removeIri } from "../thing/remove";
import { setIri } from "../thing/set";
import {
Expand Down Expand Up @@ -165,7 +165,12 @@ export function internal_setControl<ResourceExt extends WithAccessibleAcr>(
let updatedAcr = setThing(acr, control);
const acrSubj = getThing(updatedAcr, getSourceUrl(acr));
// If the ACR has an anchor node, link the Access Control.
if (acrSubj !== null) {
if (
acrSubj !== null &&
getUrlAll(acrSubj, acp.accessControl).every(
(object) => object.toString() !== asIri(control, getSourceUrl(acr)),
)
) {
updatedAcr = setThing(
updatedAcr,
addIri(acrSubj, acp.accessControl, asIri(control, getSourceUrl(acr))),
Expand Down

0 comments on commit 071d6fe

Please sign in to comment.