Ma77Ball commented on code in PR #5648:
URL: https://github.com/apache/texera/pull/5648#discussion_r3407113477


##########
.github/workflows/template-compliance-warning.yml:
##########


Review Comment:
   Not related. These template-compliance files leaked in from the branch base, 
so I removed them.



##########
.github/template-compliance-warning.txt:
##########


Review Comment:
   Same here, removed.



##########
common/auth/src/main/scala/org/apache/texera/auth/util/ComputingUnitAccess.scala:
##########
@@ -18,38 +18,39 @@
 package org.apache.texera.auth.util
 
 import org.apache.texera.dao.SqlServer
-import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
-import org.apache.texera.dao.jooq.generated.tables.daos.{
-  ComputingUnitUserAccessDao,
-  WorkflowComputingUnitDao
+import org.apache.texera.dao.jooq.generated.Tables.{
+  COMPUTING_UNIT_USER_ACCESS,
+  WORKFLOW_COMPUTING_UNIT
 }
+import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
 import org.jooq.DSLContext
 
-import scala.jdk.CollectionConverters._
-
 object ComputingUnitAccess {
   private def context: DSLContext =
     SqlServer
       .getInstance()
       .createDSLContext()
 
   def getComputingUnitAccess(cuid: Integer, uid: Integer): PrivilegeEnum = {
-    val workflowComputingUnitDao = new 
WorkflowComputingUnitDao(context.configuration())
-    val unit = workflowComputingUnitDao.fetchOneByCuid(cuid)
-
-    if (unit.getUid.equals(uid)) {
-      return PrivilegeEnum.WRITE // owner has write access
-    }
-
-    val computingUnitUserAccessDao = new 
ComputingUnitUserAccessDao(context.configuration())
-    val accessOpt = computingUnitUserAccessDao
-      .fetchByUid(uid)
-      .asScala
-      .find(_.getCuid.equals(cuid))
-
-    accessOpt match {
-      case Some(access) => access.getPrivilege
-      case None         => PrivilegeEnum.NONE
+    // owner uid + caller's access privilege in one query
+    val record = context
+      .select(WORKFLOW_COMPUTING_UNIT.UID, 
COMPUTING_UNIT_USER_ACCESS.PRIVILEGE)
+      .from(WORKFLOW_COMPUTING_UNIT)
+      .leftJoin(COMPUTING_UNIT_USER_ACCESS)
+      .on(
+        COMPUTING_UNIT_USER_ACCESS.CUID
+          .eq(WORKFLOW_COMPUTING_UNIT.CUID)
+          .and(COMPUTING_UNIT_USER_ACCESS.UID.eq(uid))
+      )
+      .where(WORKFLOW_COMPUTING_UNIT.CUID.eq(cuid))
+      .fetchOne()

Review Comment:
   At most one row. `cuid` is the PK of `workflow_computing_unit` and `(cuid, 
uid)` is the PK of `computing_unit_user_access`, so the join can't return more 
than one.



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