This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch release/v1.2
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/release/v1.2 by this push:
new df7fd1ed4d fix(v1.2): Clean up annotations and remove redundant
request IDs (#9317)
df7fd1ed4d is described below
commit df7fd1ed4d65f17200bbfb4cb6a2df8ee966d2fa
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Tue Nov 10 02:55:39 2026 +0000
fix(v1.2): Clean up annotations and remove redundant request IDs (#9317)
### What changes were proposed in this PR?
Automated backport of #9275 to `release/v1.2`.
Source: 19699e3c4b1b616729eb67e9ad126726b3cda0cb · [automation
run](https://github.com/apache/texera/actions/runs/41942800967)
### Any related issues, documentation, discussions?
Backport of #9275.
### How was this PR tested?
Release-branch CI runs on this branch once the conflicts are resolved
and this PR is marked ready for review.
### Was this PR authored or co-authored using generative AI tooling?
No.
---------
Co-authored-by: Ian Maxon <[email protected]>
Co-authored-by: Meng Wang <[email protected]>
Co-authored-by: Xuan Gu <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
---
.../dashboard/user/quota/UserQuotaResource.scala | 13 +-
.../user/workflow/WorkflowExecutionsResource.scala | 46 ++-
.../user/quota/UserQuotaResourceSpec.scala | 380 +++++++++++++++++++++
.../workflow/WorkflowExecutionsResourceSpec.scala | 66 +++-
4 files changed, 499 insertions(+), 6 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 7f89d3fe1c..bc6f880134 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
@@ -28,6 +28,7 @@ import
org.apache.texera.web.resource.dashboard.user.quota.UserQuotaResource._
import
org.apache.texera.web.resource.dashboard.user.workflow.WorkflowExecutionsResource
import java.util
+import javax.annotation.security.RolesAllowed
import javax.ws.rs._
import javax.ws.rs.core.MediaType
import scala.jdk.CollectionConverters.IterableHasAsScala
@@ -180,6 +181,7 @@ object UserQuotaResource {
}
@Path("/quota")
+@RolesAllowed(Array("REGULAR", "ADMIN"))
class UserQuotaResource {
@GET
@@ -212,7 +214,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 8787bf3798..5fc7652b5c 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
@@ -67,6 +67,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)
@@ -639,7 +665,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 {
ExecutionsMetadataPersistService.tryGetExistingExecution(
@@ -770,7 +796,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)
@@ -805,7 +835,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)
}
@@ -818,7 +852,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
new file mode 100644
index 0000000000..dfffc7770b
--- /dev/null
+++
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/quota/UserQuotaResourceSpec.scala
@@ -0,0 +1,380 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web.resource.dashboard.user.quota
+
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.Tables._
+import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
+import org.apache.texera.dao.jooq.generated.tables.daos.{
+ DatasetDao,
+ UserDao,
+ WorkflowDao,
+ WorkflowExecutionsDao,
+ WorkflowOfUserDao,
+ WorkflowUserAccessDao,
+ WorkflowVersionDao
+}
+import org.apache.texera.dao.jooq.generated.tables.pojos.{
+ Dataset,
+ User,
+ Workflow,
+ WorkflowExecutions,
+ WorkflowOfUser,
+ WorkflowUserAccess,
+ WorkflowVersion
+}
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.flatspec.AnyFlatSpec
+
+import java.sql.Timestamp
+import java.util.UUID
+import javax.ws.rs.WebApplicationException
+
+class UserQuotaResourceSpec extends AnyFlatSpec with BeforeAndAfterAll with
MockTexeraDB {
+
+ private val testUid = 4000 + scala.util.Random.nextInt(1000)
+ private val testWid = 5000 + scala.util.Random.nextInt(1000)
+
+ private var userDao: UserDao = _
+ private var workflowDao: WorkflowDao = _
+ private var workflowVersionDao: WorkflowVersionDao = _
+ private var workflowOfUserDao: WorkflowOfUserDao = _
+ private var workflowUserAccessDao: WorkflowUserAccessDao = _
+ private var workflowExecutionsDao: WorkflowExecutionsDao = _
+ private var datasetDao: DatasetDao = _
+
+ private var testUser: User = _
+ private var testWorkflow: Workflow = _
+ private var testVersion: WorkflowVersion = _
+ private val resource = new UserQuotaResource
+
+ override protected def beforeAll(): Unit = {
+ initializeDBAndReplaceDSLContext()
+
+ userDao = new UserDao(getDSLContext.configuration())
+ workflowDao = new WorkflowDao(getDSLContext.configuration())
+ workflowVersionDao = new WorkflowVersionDao(getDSLContext.configuration())
+ workflowOfUserDao = new WorkflowOfUserDao(getDSLContext.configuration())
+ workflowUserAccessDao = new
WorkflowUserAccessDao(getDSLContext.configuration())
+ workflowExecutionsDao = new
WorkflowExecutionsDao(getDSLContext.configuration())
+ datasetDao = new DatasetDao(getDSLContext.configuration())
+ }
+
+ override protected def afterAll(): Unit = shutdownDB()
+
+ // Each test starts from a clean slate for the ids under test, then seeds
+ // only what it needs, so tests are order-independent.
+ private def resetFixtures(): Unit = {
+ cleanupTestData()
+
+ testUser = new User
+ testUser.setUid(testUid)
+ testUser.setName("quota_user")
+ testUser.setEmail("[email protected]")
+ testUser.setPassword("password")
+ userDao.insert(testUser)
+
+ testWorkflow = new Workflow
+ testWorkflow.setWid(testWid)
+ testWorkflow.setName("quota_workflow_" +
UUID.randomUUID().toString.substring(0, 8))
+ testWorkflow.setContent("{}")
+ testWorkflow.setDescription("desc")
+ testWorkflow.setCreationTime(new Timestamp(System.currentTimeMillis()))
+ testWorkflow.setLastModifiedTime(new Timestamp(System.currentTimeMillis()))
+ workflowDao.insert(testWorkflow)
+
+ testVersion = new WorkflowVersion
+ testVersion.setWid(testWid)
+ testVersion.setContent("{}")
+ testVersion.setCreationTime(new Timestamp(System.currentTimeMillis()))
+ workflowVersionDao.insert(testVersion)
+ }
+
+ private def cleanupTestData(): Unit = {
+ val vidSubquery = getDSLContext
+ .select(WORKFLOW_VERSION.VID)
+ .from(WORKFLOW_VERSION)
+ .where(WORKFLOW_VERSION.WID.eq(testWid))
+
+ getDSLContext
+ .deleteFrom(OPERATOR_PORT_EXECUTIONS)
+ .where(
+ OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.in(
+ getDSLContext
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .where(WORKFLOW_EXECUTIONS.UID.eq(testUid))
+ )
+ )
+ .execute()
+ getDSLContext
+ .deleteFrom(OPERATOR_EXECUTIONS)
+ .where(
+ OPERATOR_EXECUTIONS.WORKFLOW_EXECUTION_ID.in(
+ getDSLContext
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .where(WORKFLOW_EXECUTIONS.UID.eq(testUid))
+ )
+ )
+ .execute()
+ getDSLContext
+ .deleteFrom(WORKFLOW_EXECUTIONS)
+ .where(WORKFLOW_EXECUTIONS.VID.in(vidSubquery))
+ .execute()
+
getDSLContext.deleteFrom(WORKFLOW_VERSION).where(WORKFLOW_VERSION.WID.eq(testWid)).execute()
+ getDSLContext
+ .deleteFrom(WORKFLOW_USER_ACCESS)
+ .where(WORKFLOW_USER_ACCESS.UID.eq(testUid))
+ .execute()
+
getDSLContext.deleteFrom(WORKFLOW_OF_USER).where(WORKFLOW_OF_USER.UID.eq(testUid)).execute()
+
getDSLContext.deleteFrom(WORKFLOW).where(WORKFLOW.WID.eq(testWid)).execute()
+
getDSLContext.deleteFrom(DATASET).where(DATASET.OWNER_UID.eq(testUid)).execute()
+ getDSLContext.deleteFrom(USER).where(USER.UID.eq(testUid)).execute()
+ }
+
+ // ─── helpers ──────────────────────────────────────────────────────────────
+
+ private def insertOwnership(): Unit = {
+ val ownership = new WorkflowOfUser
+ ownership.setUid(testUid)
+ ownership.setWid(testWid)
+ workflowOfUserDao.insert(ownership)
+ }
+
+ private def insertAccess(): Unit = {
+ val access = new WorkflowUserAccess
+ access.setUid(testUid)
+ access.setWid(testWid)
+ access.setPrivilege(PrivilegeEnum.READ)
+ 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)
+ execution.setUid(testUid)
+ execution.setStatus(0.toByte)
+ execution.setResult("")
+ execution.setLogLocation("")
+ execution.setStartingTime(new Timestamp(System.currentTimeMillis()))
+ execution.setBookmarked(false)
+ execution.setName("exec-" + UUID.randomUUID().toString.substring(0, 8))
+ execution.setEnvironmentVersion("test-env-1.0")
+ workflowExecutionsDao.insert(execution)
+ execution
+ }
+
+ private def insertDataset(): Dataset = {
+ val dataset = new Dataset
+ dataset.setOwnerUid(testUid)
+ dataset.setName("quota_ds_" + UUID.randomUUID().toString.substring(0, 8))
+ dataset.setRepositoryName("repo-" +
UUID.randomUUID().toString.substring(0, 8))
+ dataset.setIsPublic(false)
+ dataset.setIsDownloadable(true)
+ dataset.setDescription("")
+ dataset.setCreationTime(new Timestamp(System.currentTimeMillis()))
+ datasetDao.insert(dataset)
+ dataset
+ }
+
+ // ─── getUserCreatedWorkflow
────────────────────────────────────────────────
+
+ "getUserCreatedWorkflow" should "return an empty list when the user owns no
workflows" in {
+ resetFixtures()
+ assert(UserQuotaResource.getUserCreatedWorkflow(testUid).isEmpty)
+ }
+
+ it should "return the workflows owned by the user with their names and
timestamps" in {
+ resetFixtures()
+ insertOwnership()
+
+ val workflows = UserQuotaResource.getUserCreatedWorkflow(testUid)
+
+ assert(workflows.size == 1)
+ val w = workflows.head
+ assert(w.userId == testUid)
+ assert(w.workflowId == testWid)
+ assert(w.workflowName == testWorkflow.getName)
+ // Compare against the DB round-tripped value: Postgres rounds the stored
+ // timestamp, so the in-memory pojo's millis would not match exactly.
+ assert(w.creationTime ==
workflowDao.fetchOneByWid(testWid).getCreationTime.getTime)
+ }
+
+ // ─── getUserAccessedWorkflow
───────────────────────────────────────────────
+
+ "getUserAccessedWorkflow" should "return an empty list when the user has no
access grants" in {
+ resetFixtures()
+ assert(UserQuotaResource.getUserAccessedWorkflow(testUid).isEmpty)
+ }
+
+ it should "return the workflow ids the user can access" in {
+ resetFixtures()
+ insertAccess()
+
+ val accessed = UserQuotaResource.getUserAccessedWorkflow(testUid)
+
+ assert(accessed.size == 1)
+ assert(accessed.get(0) == testWid)
+ }
+
+ // ─── getUserQuotaSize
──────────────────────────────────────────────────────
+
+ "getUserQuotaSize" should "return an empty array when the user has no
executions" in {
+ resetFixtures()
+ assert(UserQuotaResource.getUserQuotaSize(testUid).isEmpty)
+ }
+
+ it should "assemble per-execution result / runtime-stats / log sizes" in {
+ resetFixtures()
+ val execution = insertExecution()
+ getDSLContext
+ .update(WORKFLOW_EXECUTIONS)
+ .set(WORKFLOW_EXECUTIONS.RUNTIME_STATS_SIZE,
java.lang.Long.valueOf(200L))
+ .where(WORKFLOW_EXECUTIONS.EID.eq(execution.getEid))
+ .execute()
+ getDSLContext
+ .insertInto(OPERATOR_PORT_EXECUTIONS)
+ .columns(
+ OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID,
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.RESULT_URI,
+ OPERATOR_PORT_EXECUTIONS.RESULT_SIZE
+ )
+ .values(execution.getEid, "gp-1", "vfs:///r",
java.lang.Long.valueOf(100L))
+ .execute()
+ getDSLContext
+ .insertInto(OPERATOR_EXECUTIONS)
+ .columns(
+ OPERATOR_EXECUTIONS.WORKFLOW_EXECUTION_ID,
+ OPERATOR_EXECUTIONS.OPERATOR_ID,
+ OPERATOR_EXECUTIONS.CONSOLE_MESSAGES_URI,
+ OPERATOR_EXECUTIONS.CONSOLE_MESSAGES_SIZE
+ )
+ .values(execution.getEid, "op-1", "vfs:///c",
java.lang.Long.valueOf(50L))
+ .execute()
+
+ val quota = UserQuotaResource.getUserQuotaSize(testUid)
+
+ assert(quota.length == 1)
+ val q = quota.head
+ assert(q.eid == execution.getEid)
+ assert(q.workflowId == testWid)
+ assert(q.workflowName == testWorkflow.getName)
+ assert(q.resultBytes == 100L)
+ assert(q.runTimeStatsBytes == 200L)
+ assert(q.logBytes == 50L)
+ }
+
+ // ─── class endpoints (delegate to the object using the SessionUser's uid)
──
+
+ "getCreatedWorkflow (endpoint)" should "return the current user's created
workflows" in {
+ resetFixtures()
+ insertOwnership()
+
+ val workflows = resource.getCreatedWorkflow(new SessionUser(testUser))
+
+ assert(workflows.size == 1)
+ assert(workflows.head.workflowId == testWid)
+ }
+
+ "getAccessedWorkflow (endpoint)" should "return the current user's
accessible workflow ids" in {
+ resetFixtures()
+ insertAccess()
+
+ val accessed = resource.getAccessedWorkflow(new SessionUser(testUser))
+
+ assert(accessed.size == 1)
+ assert(accessed.get(0) == testWid)
+ }
+
+ "getUserQuota (endpoint)" should "return the current user's quota storage
array" in {
+ resetFixtures()
+ insertExecution()
+
+ val quota = resource.getUserQuota(new SessionUser(testUser))
+
+ assert(quota.length == 1)
+ assert(quota.head.workflowId == testWid)
+ }
+
+ "getCreatedDatasets (endpoint)" should "return an empty list when the user
owns no datasets" in {
+ resetFixtures()
+ assert(resource.getCreatedDatasets(new SessionUser(testUser)).isEmpty)
+ }
+
+ it should "return the datasets the user created (with size disabled to 0)"
in {
+ resetFixtures()
+ val dataset = insertDataset()
+
+ val datasets = resource.getCreatedDatasets(new SessionUser(testUser))
+
+ assert(datasets.size == 1)
+ assert(datasets.head.name == dataset.getName)
+ assert(datasets.head.size == 0L)
+ }
+
+ // ─── deleteExecutionCollection / deleteCollection
──────────────────────────
+
+ "deleteExecutionCollection" should "delete the execution row from
WORKFLOW_EXECUTIONS" in {
+ resetFixtures()
+ val execution = insertExecution()
+
+ UserQuotaResource.deleteExecutionCollection(execution.getEid)
+
+ assert(workflowExecutionsDao.fetchOneByEid(execution.getEid) == null)
+ }
+
+ "deleteCollection (endpoint)" should "delete the execution row for a caller
with access" in {
+ resetFixtures()
+ insertWriteAccess()
+ val execution = insertExecution()
+
+ 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 ec35922f4e..9a073214f7 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
@@ -30,13 +30,14 @@ import
org.apache.texera.amber.core.workflow.{GlobalPortIdentity, PortIdentity}
import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde.SerdeOps
import org.apache.texera.dao.MockTexeraDB
import org.apache.texera.dao.jooq.generated.Tables._
-import org.apache.texera.dao.jooq.generated.enums.WorkflowComputingUnitTypeEnum
+import org.apache.texera.dao.jooq.generated.enums.{PrivilegeEnum,
WorkflowComputingUnitTypeEnum}
import org.apache.texera.dao.jooq.generated.tables.daos.{
DatasetDao,
UserDao,
WorkflowComputingUnitDao,
WorkflowDao,
WorkflowExecutionsDao,
+ WorkflowUserAccessDao,
WorkflowVersionDao
}
import org.apache.texera.dao.jooq.generated.tables.pojos.{
@@ -45,6 +46,7 @@ import org.apache.texera.dao.jooq.generated.tables.pojos.{
Workflow,
WorkflowComputingUnit,
WorkflowExecutions,
+ WorkflowUserAccess,
WorkflowVersion
}
import org.scalatest.flatspec.AnyFlatSpec
@@ -54,6 +56,7 @@ import java.net.URI
import java.sql.Timestamp
import java.util.UUID
import java.util.concurrent.TimeUnit
+import javax.ws.rs.WebApplicationException
import scala.collection.mutable.ArrayBuffer
class WorkflowExecutionsResourceSpec
@@ -566,6 +569,67 @@ 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")
+ readUser.setPassword("password")
+ 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 {