Skip to content

Commit

Permalink
reuse updateDoap method
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Nov 14, 2024
1 parent 3a469de commit 3fd1ff6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,7 @@ final case class PermissionsResponder(
updatedPermission.asInstanceOf[AdministrativePermissionADM],
)
case _: DefaultObjectAccessPermissionADM =>
for {
doap <- doapService
.findById(permissionIri)
.someOrFail(NotFoundException(s"DOAP ${permissionIri.value} not found."))
groupIri <- checkGroupExists(groupIri.value)
newDoap <- doapService.save(doap.copy(forWhat = Group(groupIri)))
} yield DefaultObjectAccessPermissionGetResponseADM(
doapService.asDefaultObjectAccessPermissionADM(newDoap),
)
updateDoap(permissionIri, ChangeDoapRequest(forGroup = Some(groupIri.value)), apiRequestID)
}
} yield response

Expand Down Expand Up @@ -876,20 +868,9 @@ final case class PermissionsResponder(
} yield AdministrativePermissionGetResponseADM(
updatedPermission.asInstanceOf[AdministrativePermissionADM],
)
case doap: DefaultObjectAccessPermissionADM =>
// No. It is a default object access permission.
for {
verifiedPermissions <- verifyHasPermissionsDOAP(newHasPermissions.toSet)
formattedPermissions <-
ZIO.attempt(
PermissionUtilADM.formatPermissionADMs(verifiedPermissions, PermissionType.OAP),
)
_ <-
updatePermission(permissionIri = doap.iri, maybeHasPermissions = Some(formattedPermissions))
updatedPermission <- verifyUpdateOfHasPermissions(verifiedPermissions)
} yield DefaultObjectAccessPermissionGetResponseADM(
updatedPermission.asInstanceOf[DefaultObjectAccessPermissionADM],
)
case _: DefaultObjectAccessPermissionADM =>
val request = ChangeDoapRequest(hasPermissions = Some(newHasPermissions.toSet))
updateDoap(permissionIri, request, apiRequestID)
case _ =>
throw UpdateNotPerformedException(
s"Permission ${permissionIri.value} was not updated. Please report this as a bug.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import org.knora.webapi.slice.common.api.BaseEndpoints

object PermissionEndpointsRequests {
final case class ChangeDoapRequest(
forGroup: Option[String],
forResourceClass: Option[String],
forProperty: Option[String],
hasPermissions: Option[Set[PermissionADM]],
forGroup: Option[String] = None,
forResourceClass: Option[String] = None,
forProperty: Option[String] = None,
hasPermissions: Option[Set[PermissionADM]] = None,
) {
def isEmpty: Boolean =
forGroup.isEmpty &&
Expand Down

0 comments on commit 3fd1ff6

Please sign in to comment.