aglinxinyuan commented on code in PR #9480:
URL: https://github.com/apache/texera/pull/9480#discussion_r4593304568


##########
common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala:
##########
@@ -41,6 +41,24 @@ object ResourceAccess {
   /** One shared grant, as returned by the access-list endpoints. */
   case class AccessEntry(email: String, name: String, privilege: EnumType) {}
 
+  /** All matching IDs in each resource table, so mounts can reject ambiguous 
legacy names. */
+  private[service] def repositoryIds(
+      ctx: DSLContext,
+      repositoryName: String
+  ): (java.util.List[Integer], java.util.List[Integer]) = {
+    val datasetIds = ctx
+      .select(DATASET.DID)
+      .from(DATASET)
+      .where(DATASET.REPOSITORY_NAME.eq(repositoryName))
+      .fetch(DATASET.DID)
+    val modelIds = ctx
+      .select(MODEL.MID)
+      .from(MODEL)
+      .where(MODEL.REPOSITORY_NAME.eq(repositoryName))
+      .fetch(MODEL.MID)
+    (datasetIds, modelIds)

Review Comment:
   Done in 1b37b2d0e4. `repositoryIds` now returns Scala lists, so 
`S3ProxyServlet` and `ComputingUnitMountResource` match on `(did :: Nil, Nil)` 
and `(Nil, mid :: Nil)` again.
   



##########
common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala:
##########
@@ -136,7 +152,10 @@ object ResourceAccess {
       requesterUid: Integer
   ): String = {
     requireReadAccess(ctx, resource, id, requesterUid)
-    Option(owner(ctx, resource, id)).map(_.getEmail).getOrElse("")
+    ownerUid(ctx, resource, id)
+      .flatMap(uid => 
Option(ctx.select(USER.EMAIL).from(USER).where(USER.UID.eq(uid)).fetchOne()))
+      .map(_.value1())
+      .getOrElse("")

Review Comment:
   Done in 1b37b2d0e4. `ownerEmail` and `getOwner` now read the email in one 
join, and `accessList` uses `ownerUid`; `ownerEmail` keeps `.map(_.value1())`, 
so an owner without an email still gets `null` as on main. Leaving `owner` for 
a follow-up, as you suggested.
   



##########
common/resource/src/main/scala/org/apache/texera/service/resource/ResourceAccess.scala:
##########
@@ -256,11 +275,15 @@ object ResourceAccess {
       requesterUid: Integer
   ): Response = {
     requireWriteAccess(ctx, resource, id, requesterUid)
-    val grantee = new UserDao(ctx.configuration()).fetchOneByEmail(email)
-    if (grantee == null || grantee.getIsPlaceholder) {
+    val grantee = ctx
+      .select(USER.UID, USER.IS_PLACEHOLDER)
+      .from(USER)
+      .where(USER.EMAIL.eq(email))
+      .fetchOne()
+    if (grantee == null || grantee.value2()) {
       throw new BadRequestException(s"No registered user with email $email")
     }
-    val granteeUid = grantee.getUid
+    val granteeUid = grantee.value1()

Review Comment:
   Done in 1b37b2d0e4. `OwnerAccess.registeredUid` now holds the lookup and the 
placeholder rule, `ResourceAccess.grant` and 
`WorkflowAccessResource.grantAccess` each throw their own `BadRequestException` 
on `None`, and `readContext` is gone.
   



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