Skip to content

Commit

Permalink
refactor(Addressed PR feedback): Cleaned constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
br648 committed Oct 24, 2023
1 parent 6695674 commit 3fc322f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ protected static FeedSourceSummary cleanFeedSourceSummaryForNonAdmins(FeedSource
protected static List<String> cleanFeedSourceLabelIdsForNonAdmins(List<String> labelIds, boolean isAdmin) {
// Admin can view all feed labels, but a non-admin should only see those with adminOnly=false.
return Persistence.labels
.getFiltered(PersistenceUtils.applyAdminFilter(in("_id", labelIds), isAdmin)).stream()
.getFiltered(PersistenceUtils.applyAdminFilter(in("_id", labelIds), isAdmin))
.stream()
.map(label -> label.id)
.collect(Collectors.toList());
}
Expand All @@ -456,7 +457,8 @@ protected static List<String> cleanFeedSourceLabelIdsForNonAdmins(List<String> l
protected static List<String> cleanFeedSourceNotesForNonAdmins(List<String> noteIds, boolean isAdmin) {
// Admin can view all feed notes, but a non-admin should only see those with adminOnly=false.
return Persistence.notes
.getFiltered(PersistenceUtils.applyAdminFilter(in("_id", noteIds), isAdmin)).stream()
.getFiltered(PersistenceUtils.applyAdminFilter(in("_id", noteIds), isAdmin))
.stream()
.map(note -> note.id)
.collect(Collectors.toList());
}
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/com/conveyal/datatools/manager/models/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,22 @@ public String organizationId () {
* Create a new label with auto-gen id.
*/
public Label (String name, String description, String color, boolean adminOnly, String projectId) {
this(null, name, description, color, adminOnly, projectId);
}

/**
* Create a new label with provided id.
*/
public Label (String id, String name, String description, String color, boolean adminOnly, String projectId) {
super();
if (id != null) {
this.id = id;
}
this.name = name;
this.description = description != null ? description : "";
this.color = color != null ? color : "#000000";
this.adminOnly = adminOnly;
this.projectId = projectId;
}

/**
* Create a new label with provided id.
*/
public Label (String id, String name, String description, String color, boolean adminOnly, String projectId) {
this(name, description, color, adminOnly, projectId);
this.id = id;
}

/**
* No-arg constructor to yield an uninitialized label, for dump/restore.
* Should not be used in general code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public class Note extends Model implements Serializable {
*/
public Note(String id, String body, boolean adminOnly) {
super();
if (id != null) {
this.id = id;
}
this.id = id;
this.body = body;
this.adminOnly = adminOnly;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private static Note createNote(String id, String body) {
}

/**
* Helper method to create label. If the id is provided save the label now if not deffer to test to save.
* Helper method to create label. If the id is provided save the label now if not defer to test to save.
*/
private static Label createLabel(String id, String name, String projectId) {
Label label;
Expand Down

0 comments on commit 3fc322f

Please sign in to comment.