Skip to content

Commit 594a697

Browse files
committed
fix(dashboard): Remove duplicated rows when dataset shared Publicly in the hub page
1 parent 64342fd commit 594a697

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

amber/src/main/scala/org/apache/texera/web/resource/dashboard/DatasetSearchQueryBuilder.scala

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,38 @@ object DatasetSearchQueryBuilder extends SearchQueryBuilder with LazyLogging {
6666
params: DashboardResource.SearchQueryParams,
6767
includePublic: Boolean = false
6868
): TableLike[_] = {
69-
// Select datasets that any `uid` has access to
70-
// if `uid` is null the left join operation on USER_ACCESS is skipped
71-
// if `uid` is not null find tables of specific `uid` filtered
69+
// Case 1: if `uid` is (set) and `includePublic` is false
70+
// -> return ONLY datasets that given `uid` has explicit access to.
71+
// Case 2: if `uid` is (null) and `includePublic` is true
72+
// -> return ONLY datasets that are public
73+
// Case 3 (DUPLICATE ROWS): if `uid` is (set) and `includePublic` is true
74+
// -> Intersection of datasets that are public and explicitly shared with user is returned
75+
// Case 4: if `uid` is (null) and `includePublic` is false
76+
// -> return public datasets by default as user might not be logged in
7277
val baseJoin = DATASET
7378
.leftJoin(DATASET_USER_ACCESS)
7479
.on(DATASET_USER_ACCESS.DID.eq(DATASET.DID))
7580
.and(if (uid == null) DSL.falseCondition() else DATASET_USER_ACCESS.UID.eq(uid))
7681
.leftJoin(USER)
7782
.on(USER.UID.eq(DATASET.OWNER_UID))
7883

79-
// Set the `condition` where clause here
84+
// Set the `condition` where clause here
8085
val condition: Condition =
81-
if (uid == null) {
86+
if (uid == null) {
87+
// Case 2 and 4
8288
// Get all the public datasets by default
83-
DATASET.IS_PUBLIC.eq(true)
84-
} else if (includePublic) {
85-
// Get all the datasets that `uid` has access to and the publio datasets
86-
DATASET.IS_PUBLIC.eq(true).or(DATASET_USER_ACCESS.UID.isNotNull)
87-
} else {
88-
// If `includePublic`` is false get only user accessible datasets
89-
DATASET_USER_ACCESS.UID.isNotNull
90-
}
89+
DATASET.IS_PUBLIC.eq(true)
90+
} else {
91+
if(includePublic) {
92+
// Case 3
93+
// Get all the datasets that `uid` has access to and the public datasets
94+
DATASET.IS_PUBLIC.eq(true).or(DATASET_USER_ACCESS.UID.isNotNull)
95+
} else{
96+
// Case 1
97+
// If `includePublic` is false get only user accessible datasets
98+
DATASET_USER_ACCESS.UID.isNotNull
99+
}
100+
}
91101
baseJoin.where(condition)
92102
}
93103

@@ -138,7 +148,9 @@ object DatasetSearchQueryBuilder extends SearchQueryBuilder with LazyLogging {
138148
val dd = DashboardDataset(
139149
dataset,
140150
owner.getEmail,
141-
record.get(DATASET_USER_ACCESS.PRIVILEGE, classOf[PrivilegeEnum]),
151+
Option(record.get(
152+
DATASET_USER_ACCESS.PRIVILEGE, classOf[PrivilegeEnum]
153+
)).getOrElse(PrivilegeEnum.NONE),
142154
dataset.getOwnerUid == uid,
143155
size
144156
)

0 commit comments

Comments
 (0)