Skip to content

Commit

Permalink
feat #740: filter personal team if tenant's subscriptionSecurity is a…
Browse files Browse the repository at this point in the history
…ctivated.
  • Loading branch information
helakaraa committed Sep 5, 2024
1 parent cad25d6 commit bfcabf4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 9 additions & 2 deletions daikoku/app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3309,14 +3309,21 @@ class ApiController(
val teamUsersFilter =
if (ctx.user.isDaikokuAdmin) Json.obj()
else Json.obj("users.userId" -> ctx.user.id.value)

val typeFilter = if (ctx.tenant.subscriptionSecurity.isDefined
&& ctx.tenant.subscriptionSecurity.exists(identity)) {
Json.obj(
"type" -> Json.obj("$in" -> Json.arr(TeamType.Admin.name, TeamType.Organization.name))
)
} else {
Json.obj()
}
for {
myTeams <- env.dataStore.teamRepo.myTeams(ctx.tenant, ctx.user)
teams <-
env.dataStore.teamRepo
.forTenant(ctx.tenant.id)
.findNotDeleted(
Json.obj("name" -> searchAsRegex) ++ teamUsersFilter,
Json.obj("name" -> searchAsRegex) ++ teamUsersFilter ++ typeFilter,
5,
Json.obj("name" -> 1).some
)
Expand Down
10 changes: 9 additions & 1 deletion daikoku/app/domain/CommonServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ object CommonServices {
_TenantAdminAccessTenant(
AuditTrailEvent("@{user.name} has accessed to all teams list")
)(ctx) {
val typeFilter = if (ctx.tenant.subscriptionSecurity.isDefined
&& ctx.tenant.subscriptionSecurity.exists(identity)) {
Json.obj(
"type" -> Json.obj("$in" -> Json.arr(TeamType.Admin.name, TeamType.Organization.name))
)
} else {
Json.obj()
}
for {
teams <-
env.dataStore.teamRepo
Expand All @@ -681,7 +689,7 @@ object CommonServices {
Json.obj(
"_deleted" -> false,
"name" -> Json.obj("$regex" -> research)
),
)++ typeFilter,
offset,
limit,
Some(Json.obj("_humanReadableId" -> 1))
Expand Down
16 changes: 14 additions & 2 deletions daikoku/app/storage/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,27 @@ trait TeamRepo extends TenantCapableRepo[Team, TeamId] {
env: Env,
ec: ExecutionContext
): Future[Seq[Team]] = {
val typeFilter = if (tenant.subscriptionSecurity.isDefined
&& tenant.subscriptionSecurity.exists(identity)) {
Json.obj(
"type" -> Json.obj("$in" -> Json.arr(TeamType.Admin.name, TeamType.Organization.name))
)
} else {
Json.obj()
}
if (user.isDaikokuAdmin) {
env.dataStore.teamRepo
.forTenant(tenant.id)
.findAllNotDeleted()
.findNotDeleted(
typeFilter
)


} else {
env.dataStore.teamRepo
.forTenant(tenant.id)
.findNotDeleted(
Json.obj("users.userId" -> user.id.value)
Json.obj("users.userId" -> user.id.value) ++ typeFilter
)
}
}
Expand Down

0 comments on commit bfcabf4

Please sign in to comment.