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


##########
file-service/src/test/scala/org/apache/texera/service/resource/AccessResourceBehaviors.scala:
##########
@@ -0,0 +1,454 @@
+/*
+ * 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.service.resource
+
+import jakarta.ws.rs.core.Response
+import jakarta.ws.rs.{BadRequestException, ForbiddenException}
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.dao.jooq.generated.enums.{PrivilegeEnum, UserRoleEnum}
+import org.apache.texera.dao.jooq.generated.tables.daos.UserDao
+import org.apache.texera.dao.jooq.generated.tables.pojos.User
+import org.jooq.{DSLContext, Record}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
+
+import scala.jdk.CollectionConverters._
+
+/**
+  * The access cases [[DatasetAccessResourceSpec]] and 
[[ModelAccessResourceSpec]] share.
+  *
+  * Datasets and models apply the same access rules through 
[[ResourceAccess]], but each exposes
+  * its own helpers and endpoints. A subclass seeds its resource and binds 
every case to those
+  * helpers and endpoints, so both APIs stay covered case by case. Explicit 
grants are seeded,
+  * read and cleared through the resource's [[ResourceTables]]. Test names 
keep each resource's
+  * own helper names (`isDatasetPublic`, `getOwnerEmailOfModel`, ...), as the 
separate specs did.
+  *
+  * @param tables the resource's tables
+  * @param placeholderHandle the prefix of the placeholder account a grant 
case creates
+  */
+abstract class AccessResourceBehaviors[R <: Record, A <: Record](
+    tables: ResourceTables[R, A],
+    placeholderHandle: String
+) extends AnyFlatSpec
+    with Matchers
+    with MockTexeraDB
+    with BeforeAndAfterAll
+    with BeforeAndAfterEach {
+
+  private val label = tables.label
+  private val Label = label.capitalize
+
+  /** Inserts one resource owned by `ownerUid` and returns its id. */
+  protected def insertResource(
+      name: String,
+      description: String,
+      isPublic: Boolean,
+      ownerUid: Integer
+  ): Integer
+
+  // the resource's privilege helpers
+  protected def resourceIsPublic(ctx: DSLContext, id: Integer): Boolean
+  protected def userOwnsResource(ctx: DSLContext, id: Integer, uid: Integer): 
Boolean
+  protected def userPrivilege(ctx: DSLContext, id: Integer, uid: Integer): 
PrivilegeEnum
+  protected def userCanRead(ctx: DSLContext, id: Integer, uid: Integer): 
Boolean
+  protected def userCanWrite(ctx: DSLContext, id: Integer, uid: Integer): 
Boolean
+  protected def resourceOwner(ctx: DSLContext, id: Integer): User
+
+  // the resource's endpoints
+  protected def grant(id: Integer, email: String, privilege: String, user: 
SessionUser): Response
+  protected def revoke(id: Integer, email: String, user: SessionUser): Response
+  protected def accessListOf(
+      id: Integer,
+      user: SessionUser
+  ): java.util.List[ResourceAccess.AccessEntry]
+  protected def ownerEmail(id: Integer, user: SessionUser): String
+
+  /**
+    * Registers the grantAccess cases only this resource has, right after the 
placeholder case.
+    * It runs while the cases are being registered, so an override may only 
register cases.
+    */
+  protected def resourceOnlyGrantCases(): Unit = {}

Review Comment:
   Both resources go through the same `ResourceAccess.grant`, which rejects an 
unknown email for datasets too, so the unknown-email case can live in the 
shared list. That drops this hook and its registration-time caveat, lets 
`privateId`, `ownerSession` and `accessList` go back to `private`, and gives 
the dataset spec the case it was missing.
   
   `placeholderHandle` is in the same spot: it only keeps the old 
`ds-placeholder` fixture email, and `label` works as well, as it already does 
for the owner. 



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