This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9275-e30e1603bb22c027513718122827749c55f767c8
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 19699e3c4b1b616729eb67e9ad126726b3cda0cb
Author: Ian Maxon <[email protected]>
AuthorDate: Thu Nov 5 00:17:13 2026 +0000

    fix: Clean up annotations and remove redundant request IDs (#9275)
    
    ### What changes were proposed in this PR?
    These are some changes Meng gave me that clean up a few things regarding
    the IDs requests give and some missing annotations
    
    ### Any related issues, documentation, discussions?
    No, it is a small change, so that would be overkill.
    
    ### How was this PR tested?
    It contains its own tests, it's a small change so nothing else should be
    necessary.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    I believe so, but I edited the patches a little for clarity and to
    remove excessive comment narration.
    
    ---------
    
    Co-authored-by: Meng Wang <[email protected]>
---
 .../dashboard/user/quota/UserQuotaResource.scala   | 13 +++-
 .../user/workflow/WorkflowExecutionsResource.scala | 46 +++++++++++--
 .../user/quota/UserQuotaResourceSpec.scala         | 31 ++++++++-
 .../workflow/WorkflowExecutionsResourceSpec.scala  | 78 ++++++++++++++++++++--
 4 files changed, 157 insertions(+), 11 deletions(-)

diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResource.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResource.scala
index 7c528ba49e..77940f1045 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResource.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResource.scala
@@ -31,6 +31,7 @@ import 
org.apache.texera.web.resource.dashboard.user.workflow.{
 }
 
 import java.util
+import javax.annotation.security.RolesAllowed
 import javax.ws.rs._
 import javax.ws.rs.core.MediaType
 import scala.jdk.CollectionConverters.IterableHasAsScala
@@ -171,6 +172,7 @@ object UserQuotaResource {
 }
 
 @Path("/quota")
+@RolesAllowed(Array("REGULAR", "ADMIN"))
 class UserQuotaResource {
 
   @GET
@@ -203,7 +205,16 @@ class UserQuotaResource {
 
   @DELETE
   @Path("/deleteCollection/{eid}")
-  def deleteCollection(@PathParam("eid") eid: Integer): Unit = {
+  @RolesAllowed(Array("REGULAR", "ADMIN"))
+  def deleteCollection(
+      @PathParam("eid") eid: Integer,
+      @Auth current_user: SessionUser
+  ): Unit = {
+    WorkflowExecutionsResource.validateUserCanAccessExecutions(
+      current_user.getUid,
+      Seq(eid),
+      requireWrite = true
+    )
     deleteExecutionCollection(eid)
   }
 }
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
index 93a601d0de..26e0b987c0 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
+++ 
b/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)) {
+        throw new WebApplicationException(Response.Status.UNAUTHORIZED)
+      }
+    }
+  }
+
   def getExpiredExecutionsWithResultOrLog(timeToLive: Int): 
List[WorkflowExecutions] = {
     val deadline = new Timestamp(
       System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(timeToLive)
@@ -628,7 +654,7 @@ class WorkflowExecutionsResource {
       @Auth sessionUser: SessionUser
   ): List[String] = {
     val user = sessionUser.getUser
-    if (!WorkflowAccessResource.hasReadAccess(wid, user.getUid)) {
+    if (!userCanAccessExecution(user.getUid, eid, requireWrite = false)) {
       List()
     } else {
       val logLocation = context
@@ -761,7 +787,11 @@ class WorkflowExecutionsResource {
       request: ExecutionGroupBookmarkRequest,
       @Auth sessionUser: SessionUser
   ): Unit = {
-    validateUserCanAccessWorkflow(sessionUser.getUser.getUid, request.wid)
+    validateUserCanAccessExecutions(
+      sessionUser.getUser.getUid,
+      request.eIds.toSeq,
+      requireWrite = true
+    )
     val eIdsList = request.eIds.toSeq.asJava
     if (request.isBookmarked) {
       // If currently bookmarked, un-bookmark (set bookmarked = false)
@@ -803,7 +833,11 @@ class WorkflowExecutionsResource {
       request: ExecutionGroupDeleteRequest,
       @Auth sessionUser: SessionUser
   ): Unit = {
-    validateUserCanAccessWorkflow(sessionUser.getUser.getUid, request.wid)
+    validateUserCanAccessExecutions(
+      sessionUser.getUser.getUid,
+      request.eIds.toSeq,
+      requireWrite = true
+    )
     removeAllExecutionFiles(request.eIds)
   }
 
@@ -816,7 +850,11 @@ class WorkflowExecutionsResource {
       request: ExecutionRenameRequest,
       @Auth sessionUser: SessionUser
   ): Unit = {
-    validateUserCanAccessWorkflow(sessionUser.getUser.getUid, request.wid)
+    validateUserCanAccessExecutions(
+      sessionUser.getUser.getUid,
+      Seq(request.eId),
+      requireWrite = true
+    )
     val execution = getExecutionById(request.eId)
     execution.setName(request.executionName)
     executionsDao.update(execution)
diff --git 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala
index e0798059d4..760500d9f3 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala
@@ -47,6 +47,7 @@ import org.scalatest.flatspec.AnyFlatSpec
 import java.sql.Timestamp
 import java.util.UUID
 import scala.jdk.CollectionConverters._
+import javax.ws.rs.WebApplicationException
 
 class UserQuotaResourceSpec extends AnyFlatSpec with BeforeAndAfterAll with 
MockTexeraDB {
 
@@ -167,6 +168,14 @@ class UserQuotaResourceSpec extends AnyFlatSpec with 
BeforeAndAfterAll with Mock
     workflowUserAccessDao.insert(access)
   }
 
+  private def insertWriteAccess(): Unit = {
+    val access = new WorkflowUserAccess
+    access.setUid(testUid)
+    access.setWid(testWid)
+    access.setPrivilege(PrivilegeEnum.WRITE)
+    workflowUserAccessDao.insert(access)
+  }
+
   private def insertExecution(): WorkflowExecutions = {
     val execution = new WorkflowExecutions
     execution.setVid(testVersion.getVid)
@@ -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 {
+    resetFixtures()
+    insertWriteAccess()
+    val execution = insertExecution()
+
+    val otherUser = new User
+    otherUser.setUid(testUid + 100000)
+    otherUser.setName("otherUser")
+    otherUser.setEmail("otherUser-" + UUID.randomUUID().toString.substring(0, 
8) + "@example.com")
+
+    intercept[WebApplicationException] {
+      resource.deleteCollection(execution.getEid, new SessionUser(otherUser))
+    }
+
+    assert(workflowExecutionsDao.fetchOneByEid(execution.getEid) != null)
+  }
 }
diff --git 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
index 7cc549004d..b656a48346 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
@@ -47,6 +47,7 @@ import org.apache.texera.dao.jooq.generated.tables.daos.{
   WorkflowComputingUnitDao,
   WorkflowDao,
   WorkflowExecutionsDao,
+  WorkflowUserAccessDao,
   WorkflowVersionDao
 }
 import org.apache.texera.dao.jooq.generated.tables.pojos.{
@@ -55,6 +56,7 @@ import org.apache.texera.dao.jooq.generated.tables.pojos.{
   Workflow,
   WorkflowComputingUnit,
   WorkflowExecutions,
+  WorkflowUserAccess,
   WorkflowVersion
 }
 import 
org.apache.texera.amber.engine.architecture.coordinator.OperatorPortResultUriAvailable
@@ -677,6 +679,66 @@ class WorkflowExecutionsResourceSpec
     assert(survivorEids.contains(survivor.getEid))
   }
 
+  private def grantAccess(uid: Integer, privilege: PrivilegeEnum): Unit = {
+    val access = new WorkflowUserAccess
+    access.setUid(uid)
+    access.setWid(testWorkflowWid)
+    access.setPrivilege(privilege)
+    new WorkflowUserAccessDao(getDSLContext.configuration()).insert(access)
+  }
+
+  "validateUserCanAccessExecutions" should "authorize by the execution's 
workflow" in {
+    grantAccess(testUserId, PrivilegeEnum.WRITE)
+    val execution = insertExecution()
+    val eid = execution.getEid
+    val otherUserUid = testUserId + 100000
+
+    WorkflowExecutionsResource.validateUserCanAccessExecutions(
+      testUserId,
+      Seq(eid),
+      requireWrite = true
+    )
+
+    intercept[WebApplicationException] {
+      WorkflowExecutionsResource.validateUserCanAccessExecutions(
+        otherUserUid,
+        Seq(eid),
+        requireWrite = true
+      )
+    }
+
+    assert(
+      !WorkflowExecutionsResource.userCanAccessExecution(
+        testUserId,
+        eid + 999999,
+        requireWrite = false
+      )
+    )
+  }
+
+  it should "handle read" in {
+    val readUid = testUserId + 1
+    val readUser = new User
+    readUser.setUid(readUid)
+    readUser.setName("read_only_user")
+    readUser.setEmail("readonly-" + UUID.randomUUID().toString.substring(0, 8) 
+ "@example.com")
+    userDao.insert(readUser)
+    grantAccess(readUid, PrivilegeEnum.READ)
+    val execution = insertExecution()
+    val eid = execution.getEid
+
+    try {
+      assert(WorkflowExecutionsResource.userCanAccessExecution(readUid, eid, 
requireWrite = false))
+      assert(!WorkflowExecutionsResource.userCanAccessExecution(readUid, eid, 
requireWrite = true))
+    } finally {
+      getDSLContext
+        .deleteFrom(WORKFLOW_USER_ACCESS)
+        .where(WORKFLOW_USER_ACCESS.UID.eq(readUid))
+        .execute()
+      getDSLContext.deleteFrom(USER).where(USER.UID.eq(readUid)).execute()
+    }
+  }
+
   // ─── new: updateResultSize ────────────────────────────────────────────────
 
   "updateResultSize" should "set RESULT_SIZE on the matching (eid, 
globalPortId) row" in {
@@ -1065,6 +1127,14 @@ class WorkflowExecutionsResourceSpec
       .set(WORKFLOW_USER_ACCESS.PRIVILEGE, PrivilegeEnum.READ)
       .execute()
 
+  private def grantWriteAccess(uid: Integer = testUserId): Unit =
+    getDSLContext
+      .insertInto(WORKFLOW_USER_ACCESS)
+      .set(WORKFLOW_USER_ACCESS.WID, Integer.valueOf(testWorkflowWid))
+      .set(WORKFLOW_USER_ACCESS.UID, uid)
+      .set(WORKFLOW_USER_ACCESS.PRIVILEGE, PrivilegeEnum.WRITE)
+      .execute()
+
   private def userWithoutAccess(): User = {
     val u = new User
     u.setUid(testUserId + 5000)
@@ -1248,7 +1318,7 @@ class WorkflowExecutionsResourceSpec
   }
 
   it should "bookmark executions that are currently un-bookmarked" in {
-    grantReadAccess()
+    grantWriteAccess()
     val exec = insertExecution() // bookmarked = false
     resource.setExecutionAreBookmarked(
       ExecutionGroupBookmarkRequest(testWorkflowWid, Array(exec.getEid), 
isBookmarked = false),
@@ -1258,7 +1328,7 @@ class WorkflowExecutionsResourceSpec
   }
 
   it should "un-bookmark executions that are currently bookmarked" in {
-    grantReadAccess()
+    grantWriteAccess()
     val exec = insertExecution()
     resource.setExecutionAreBookmarked(
       ExecutionGroupBookmarkRequest(testWorkflowWid, Array(exec.getEid), 
isBookmarked = true),
@@ -1268,7 +1338,7 @@ class WorkflowExecutionsResourceSpec
   }
 
   "updateWorkflowExecutionsName" should "rename the execution" in {
-    grantReadAccess()
+    grantWriteAccess()
     val exec = insertExecution(name = "old-name")
     resource.updateWorkflowExecutionsName(
       ExecutionRenameRequest(testWorkflowWid, exec.getEid, "new-name"),
@@ -1278,7 +1348,7 @@ class WorkflowExecutionsResourceSpec
   }
 
   "groupDeleteExecutionsOfWorkflow" should "delete the execution rows" in {
-    grantReadAccess()
+    grantWriteAccess()
     val e1 = insertExecution()
     val e2 = insertExecution()
     resource.groupDeleteExecutionsOfWorkflow(

Reply via email to