Copilot commented on code in PR #9275:
URL: https://github.com/apache/texera/pull/9275#discussion_r4463194430
##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala:
##########
@@ -68,6 +68,32 @@ object WorkflowExecutionsResource {
executionsDao.fetchOneByEid(eId)
}
+ def userCanAccessExecution(uid: Integer, eid: Integer, requireWrite:
Boolean): Boolean = {
+ val owningWid = context
+ .select(WORKFLOW_VERSION.WID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_EXECUTIONS.EID.eq(eid))
+ .fetchOneInto(classOf[Integer])
+ owningWid != null && (
+ if (requireWrite) WorkflowAccessResource.hasWriteAccess(owningWid, uid)
+ else WorkflowAccessResource.hasReadAccess(owningWid, uid)
+ )
+ }
+
+ def validateUserCanAccessExecutions(
+ uid: Integer,
+ eids: Seq[Integer],
+ requireWrite: Boolean
+ ): Unit = {
+ eids.distinct.foreach { eid =>
+ if (!userCanAccessExecution(uid, eid, requireWrite)) {
Review Comment:
`validateUserCanAccessExecutions` performs an execution-to-workflow query
and then a separate privilege query for every distinct EID. The bookmark/delete
endpoints are batch APIs, so a request containing N executions now incurs
roughly 2N database round trips (with no bound on the array), which can turn
normal bulk operations into a database bottleneck. Resolve all EIDs and their
workflow IDs in one set-based query and evaluate the caller's access in bulk
before applying the update/delete.
##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala:
##########
@@ -349,12 +358,30 @@ class UserQuotaResourceSpec extends AnyFlatSpec with
BeforeAndAfterAll with Mock
assert(workflowExecutionsDao.fetchOneByEid(execution.getEid) == null)
}
- "deleteCollection (endpoint)" should "delete the execution row for the given
eid" in {
+ "deleteCollection (endpoint)" should "delete the execution row for a caller
with access" in {
resetFixtures()
+ insertWriteAccess()
val execution = insertExecution()
- resource.deleteCollection(execution.getEid)
+ resource.deleteCollection(execution.getEid, new SessionUser(testUser))
assert(workflowExecutionsDao.fetchOneByEid(execution.getEid) == null)
}
+
+ it should "reject a caller who has mistaken the eid" in {
Review Comment:
The test name is misleading and grammatically unclear: the caller has not
“mistaken” the EID; this case verifies that a caller without access is
rejected. Naming it after the authorization condition will make failures easier
to understand.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]