kunwp1 commented on code in PR #9275:
URL: https://github.com/apache/texera/pull/9275#discussion_r4459611563


##########
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)

Review Comment:
   These actions now need write access, but the Execution History panel in the 
workspace still shows bookmark, rename and delete to anyone who can open the 
workflow. That includes read-only collaborators and viewers of public 
workflows. Their clicks now get a 401, and the frontend's 
`UnauthorizedHttpInterceptor` treats any 401 as an expired session, so the user 
is logged out with "Your session has expired". Returning 403 here (signed in 
but not allowed) would avoid the logout, and hiding those buttons for read-only 
users would avoid the error entirely. Either way, the read-to-write change is 
worth a line in the description, since it changes what read-only collaborators 
can do.



##########
amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala:
##########
@@ -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 {

Review Comment:
   No test pins the actual fix, which is that the endpoints now check the eids 
rather than the request's `wid`.  One case per endpoint, like the existing 
"refuse an execution id that belongs to a different workflow" stats test, would 
cover it. Also, `grantAccess` duplicates `grantReadAccess` and the new 
`grantWriteAccess`, and one helper that takes the privilege would do.



-- 
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]

Reply via email to