Skip to content

Commit

Permalink
refactor: move project filtering to server side (#8102)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
Alexander Matyushentsev committed Jan 6, 2022
1 parent 722fe92 commit 37851b1
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 254 deletions.
8 changes: 8 additions & 0 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@ func (s *Server) Watch(q *application.ApplicationQuery, ws application.Applicati
if q.Name != nil {
logCtx = logCtx.WithField("application", *q.Name)
}
projects := map[string]bool{}
for i := range q.Projects {
projects[q.Projects[i]] = true
}
claims := ws.Context().Value("claims")
selector, err := labels.Parse(q.Selector)
if err != nil {
Expand All @@ -750,6 +754,10 @@ func (s *Server) Watch(q *application.ApplicationQuery, ws application.Applicati
// sendIfPermitted is a helper to send the application to the client's streaming channel if the
// caller has RBAC privileges permissions to view it
sendIfPermitted := func(a appv1.Application, eventType watch.EventType) {
if len(projects) > 0 && !projects[a.Spec.GetProject()] {
return
}

if appVersion, err := strconv.Atoi(a.ResourceVersion); err == nil && appVersion < minVersion {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as LabelSelector from '../label-selector';
import {ComparisonStatusIcon, HealthStatusIcon} from '../utils';

export interface FilterResult {
projects: boolean;
repos: boolean;
sync: boolean;
health: boolean;
Expand All @@ -25,7 +24,6 @@ export function getFilterResults(applications: Application[], pref: AppsListPref
return applications.map(app => ({
...app,
filterResult: {
projects: pref.projectsFilter.length === 0 || pref.projectsFilter.includes(app.spec.project),
repos: pref.reposFilter.length === 0 || pref.reposFilter.includes(app.spec.source.repoURL),
sync: pref.syncFilter.length === 0 || pref.syncFilter.includes(app.status.sync.status),
health: pref.healthFilter.length === 0 || pref.healthFilter.includes(app.status.health.status),
Expand Down
Loading

0 comments on commit 37851b1

Please sign in to comment.