Skip to content

Commit

Permalink
[FIXED JENKINS-18604] Simpler to just add the ones that are favorite
Browse files Browse the repository at this point in the history
- Simplifies the code and fixes the bug: double win!!!
  • Loading branch information
stephenc committed Jul 3, 2013
1 parent 820afb9 commit 6376257
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/main/java/hudson/plugins/favorite/filter/FavoriteFilter.java
Expand Up @@ -21,33 +21,25 @@ public FavoriteFilter() {

@Override
public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) {
List<TopLevelItem> filtered = new ArrayList<TopLevelItem>(added);
List<TopLevelItem> filtered = new ArrayList<TopLevelItem>();

Authentication authentication = Hudson.getAuthentication();

String name = authentication.getName();
if (name != null && authentication.isAuthenticated()) {
User user = Hudson.getInstance().getUser(name);
if (user == null) {
clearView(all, filtered);
} else {
if (user != null) {
FavoriteUserProperty fup = user.getProperty(FavoriteUserProperty.class);
for (TopLevelItem item : all) {
if (fup == null || !fup.isJobFavorite(item.getFullName())) {
filtered.remove(item);
if (fup != null) {
for (TopLevelItem item : added) {
if (fup.isJobFavorite(item.getFullName())) {
filtered.add(item);
}
}
}
}
} else {
clearView(all, filtered);
}
return filtered;
}

private void clearView(List<TopLevelItem> all, List<TopLevelItem> filtered) {
for (TopLevelItem item : all) {
filtered.remove(item);
}
}

}

0 comments on commit 6376257

Please sign in to comment.