Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Introduce administrative permission service #3172

Merged
merged 29 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1dfa7f4
refactor: Rename PermissionResponder and add AdministrativePermission…
seakayone Apr 4, 2024
7f1d222
Integrate AdministrativePermissionService into PermissionsResponder a…
seakayone Apr 4, 2024
c97b28d
disable login for builtIn users
seakayone Apr 4, 2024
81962ae
fmt
seakayone Apr 5, 2024
665e1fb
refactor: make org.knora.webapi.responders.admin.PermissionsResponder…
seakayone Apr 5, 2024
fa414e7
simplify
seakayone Apr 5, 2024
853d63c
rename getPermissionData
seakayone Apr 5, 2024
023fd87
cleanup spec
seakayone Apr 5, 2024
01a92a8
cleanup GroupService
seakayone Apr 5, 2024
0c75589
header
seakayone Apr 5, 2024
bbe4779
Use ZIO.foreach (simplify)
seakayone Apr 8, 2024
f993963
Use ZIO.foreach (simplify)
seakayone Apr 8, 2024
c60b915
cleanup
seakayone Apr 8, 2024
f086ef2
remove unused tuple part
seakayone Apr 8, 2024
2a12b16
simplify
seakayone Apr 8, 2024
2ff0400
simplify
seakayone Apr 8, 2024
58966b5
simplify
seakayone Apr 8, 2024
53a26ac
simplify
seakayone Apr 8, 2024
7619126
fmt
seakayone Apr 8, 2024
73ff423
cleanup
seakayone Apr 8, 2024
e3714d9
add types
seakayone Apr 8, 2024
c717468
fmt
seakayone Apr 8, 2024
3c79e8c
move code to KnoraUserToUserConverter
seakayone Apr 8, 2024
e90b109
improve type safety internally
seakayone Apr 8, 2024
c1a2d25
migrate KnoraUserToUserConverterSpec to zio-test E2EZSpec
seakayone Apr 8, 2024
8f17f68
header
seakayone Apr 8, 2024
c23672f
cleanup
seakayone Apr 8, 2024
aeb6126
cleanup
seakayone Apr 8, 2024
9085f84
align naming findByIds
seakayone Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ object LayersTest {
ApiRoutes & AdminApiEndpoints & ApiV2Endpoints & AppRouter & AssetPermissionsResponder & Authenticator &
AuthorizationRestService & CacheServiceRequestMessageHandler & CardinalityHandler & ConstructResponseUtilV2 &
DspIngestClient & GravsearchTypeInspectionRunner & GroupsResponderADM & GroupsRestService & GroupService &
HttpServer & IIIFRequestMessageHandler & InferenceOptimizationService & IriConverter & ListsResponder &
HttpServer & IIIFRequestMessageHandler & InferenceOptimizationService & IriConverter & KnoraUserToUserConverter & ListsResponder &
ListsResponderV2 & MessageRelay & OntologyCache & OntologyHelpers & OntologyInferencer & OntologyRepo &
OntologyResponderV2 & PermissionUtilADM & PermissionsResponderADM & PermissionsRestService & ProjectExportService &
OntologyResponderV2 & PermissionUtilADM & PermissionsResponder & PermissionsRestService & ProjectExportService &
ProjectExportStorageService & ProjectImportService & ProjectService & ProjectRestService & QueryTraverser &
RepositoryUpdater & ResourceUtilV2 & ResourcesResponderV2 & RestCardinalityService & SearchApiRoutes &
SearchResponderV2 & StandoffResponderV2 & StandoffTagUtilV2 & State & TestClientService & TriplestoreService &
Comment on lines 88 to 96
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: could we put those on one line each? Scalafmt doesn't do it automatically, but it doesn't undo it either, I think. And the diffs would be less nasty.

Expand Down Expand Up @@ -134,7 +134,7 @@ object LayersTest {
OntologyRepoLive.layer,
OntologyResponderV2Live.layer,
PermissionUtilADMLive.layer,
PermissionsResponderADMLive.layer,
PermissionsResponder.layer,
PredicateObjectMapper.layer,
PredicateRepositoryLive.layer,
ProjectExportServiceLive.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.UUID
import dsp.errors.BadRequestException
import dsp.errors.ForbiddenException
import org.knora.webapi.CoreSpec
import org.knora.webapi.responders.admin.PermissionsResponderADM
import org.knora.webapi.responders.admin.PermissionsResponder
import org.knora.webapi.routing.UnsafeZioRun
import org.knora.webapi.sharedtestdata.SharedOntologyTestDataADM._
import org.knora.webapi.sharedtestdata.SharedTestDataADM2._
Expand Down Expand Up @@ -40,29 +40,6 @@ class PermissionsMessagesADMSpec extends CoreSpec {
)
assert(caught.getMessage === s"Invalid permission IRI: $permissionIri.")
}

"return 'BadRequest' if the supplied project IRI for AdministrativePermissionForProjectGroupGetADM is not valid" in {
val projectIri = "invalid-project-IRI"
val caught = intercept[BadRequestException](
AdministrativePermissionForProjectGroupGetADM(
projectIri = projectIri,
groupIri = KnoraGroupRepo.builtIn.ProjectMember.id.value,
requestingUser = SharedTestDataADM.imagesUser01,
),
)
assert(caught.getMessage === s"Invalid project IRI $projectIri")
}

"return 'ForbiddenException' if the user requesting AdministrativePermissionForProjectGroupGetADM is not system or project Admin" in {
val caught = intercept[ForbiddenException](
AdministrativePermissionForProjectGroupGetADM(
projectIri = SharedTestDataADM.imagesProjectIri,
groupIri = KnoraGroupRepo.builtIn.ProjectMember.id.value,
requestingUser = SharedTestDataADM.imagesUser02,
),
)
assert(caught.getMessage === "Administrative permission can only be queried by system and project admin.")
}
}

"Administrative Permission Create Requests" should {
Expand Down Expand Up @@ -488,7 +465,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
),
)
val exit =
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions)))
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponder](_.verifyHasPermissionsDOAP(hasPermissions)))
assertFailsWithA[BadRequestException](
exit,
"Invalid value for name parameter of hasPermissions: invalid, it should be one of " +
Expand All @@ -507,7 +484,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
)

val exit =
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions)))
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponder](_.verifyHasPermissionsDOAP(hasPermissions)))
assertFailsWithA[BadRequestException](
exit,
s"Invalid value for permissionCode parameter of hasPermissions: $invalidCode, it should be one of " +
Expand All @@ -525,7 +502,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
)

val exit =
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions)))
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponder](_.verifyHasPermissionsDOAP(hasPermissions)))
assertFailsWithA[BadRequestException](
exit,
s"Given permission code 2 and permission name CR are not consistent.",
Expand All @@ -543,7 +520,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
)

val exit =
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions)))
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponder](_.verifyHasPermissionsDOAP(hasPermissions)))
assertFailsWithA[BadRequestException](
exit,
s"One of permission code or permission name must be provided for a default object access permission.",
Expand All @@ -560,7 +537,7 @@ class PermissionsMessagesADMSpec extends CoreSpec {
),
)
val exit =
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions)))
UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponder](_.verifyHasPermissionsDOAP(hasPermissions)))
assertFailsWithA[BadRequestException](
exit,
s"additionalInformation of a default object access permission type cannot be empty.",
Expand Down