tanishqgandhi1908 commented on code in PR #9190:
URL: https://github.com/apache/texera/pull/9190#discussion_r4395544502
##########
amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowAccessResource.scala:
##########
@@ -81,18 +80,40 @@ object WorkflowAccessResource {
* @return PrivilegeEnum value indicating NONE/READ/WRITE
*/
def getPrivilege(wid: Integer, uid: Integer): PrivilegeEnum = {
- val access = context
- .select()
- .from(WORKFLOW_USER_ACCESS)
-
.where(WORKFLOW_USER_ACCESS.WID.eq(wid).and(WORKFLOW_USER_ACCESS.UID.eq(uid)))
- .fetchOneInto(classOf[WorkflowUserAccess])
- if (access == null) {
- PrivilegeEnum.NONE
- } else {
- access.getPrivilege
- }
+ // One round trip: the caller's own ownership row and grant, read
together. Both joins are
+ // narrowed to the caller, so a workflow with several owners still yields
one row.
+ val row = context
+ .select(WORKFLOW_OF_USER.UID, WORKFLOW_USER_ACCESS.PRIVILEGE)
+ .from(WORKFLOW)
+ .leftJoin(WORKFLOW_OF_USER)
+
.on(WORKFLOW_OF_USER.WID.eq(WORKFLOW.WID).and(WORKFLOW_OF_USER.UID.eq(uid)))
+ .leftJoin(WORKFLOW_USER_ACCESS)
+
.on(WORKFLOW_USER_ACCESS.WID.eq(WORKFLOW.WID).and(WORKFLOW_USER_ACCESS.UID.eq(uid)))
+ .where(WORKFLOW.WID.eq(wid))
+ .fetchOne()
+ if (row == null) PrivilegeEnum.NONE
+ else OwnerAccess.privilege(row.value1() != null, row.value2())
}
+ def isOwner(wid: Integer, uid: Integer): Boolean =
+ context.fetchExists(
+ WORKFLOW_OF_USER,
+ WORKFLOW_OF_USER.WID.eq(wid).and(WORKFLOW_OF_USER.UID.eq(uid))
+ )
Review Comment:
Thanks! Done: dropped workflowOfUserExists in favour of
WorkflowAccessResource.isOwner for the persist and delete paths, and
updateWorkflowField now checks hasWriteAccess alone.
--
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]