-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate delete companion #278
Changes from 3 commits
f44faf2
cb120c5
528d8bb
501dcca
9beaf93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.mongodb.client.model.Filters; | ||
import org.opentripplanner.middleware.auth.Auth0Users; | ||
import org.opentripplanner.middleware.auth.RequestingUser; | ||
import org.opentripplanner.middleware.persistence.Persistence; | ||
|
@@ -21,7 +22,11 @@ | |
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.opentripplanner.middleware.tripmonitor.TrustedCompanion.invalidateRelatedUsers; | ||
import static org.opentripplanner.middleware.tripmonitor.TrustedCompanion.removeCompanion; | ||
import static org.opentripplanner.middleware.tripmonitor.TrustedCompanion.removeDependent; | ||
import static org.opentripplanner.middleware.tripmonitor.TrustedCompanion.removeObserver; | ||
import static org.opentripplanner.middleware.tripmonitor.TrustedCompanion.removePrimaryTraveler; | ||
|
||
/** | ||
* This represents a user of an OpenTripPlanner instance (typically of the standard OTP UI/otp-react-redux). | ||
|
@@ -143,20 +148,34 @@ public boolean delete(boolean deleteAuth0User) { | |
// If a related user, invalidate relationship with all dependents. | ||
for (String userId : dependents) { | ||
OtpUser dependent = Persistence.otpUsers.getById(userId); | ||
if (dependent != null) { | ||
for (RelatedUser relatedUser : dependent.relatedUsers) { | ||
if (relatedUser.email.equals(this.email)) { | ||
relatedUser.status = RelatedUser.RelatedUserStatus.INVALID; | ||
} | ||
} | ||
if (dependent != null && invalidateRelatedUsers(email, dependent.relatedUsers)) { | ||
Persistence.otpUsers.replace(dependent.id, dependent); | ||
} | ||
} | ||
|
||
// If a dependent, remove relationship with all related users. | ||
// If a dependent user, remove relationship with all related users. | ||
for (RelatedUser relatedUser : relatedUsers) { | ||
removeDependent(this, relatedUser); | ||
} | ||
|
||
// If a dependent user, remove self as the primary traveler in trips created by other users. | ||
// TODO: Should we alert the user who created the trip of the deletion? | ||
Persistence.monitoredTrips | ||
.getFiltered(Filters.eq("primary.userId", id)) | ||
.forEach(trip -> removePrimaryTraveler(this, trip)); | ||
|
||
// If a companion user, invalidate relationship in trips where they are companions and observers. | ||
// TODO: Should we alert the user who created the trip of the deletion? | ||
Persistence.monitoredTrips | ||
.getFiltered(Filters.eq("companion.email", email)) | ||
.forEach(trip -> removeCompanion(this, trip)); | ||
|
||
// If a companion user, invalidate relationship in trips where they are companions and observers. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit. this comment is a duplicate of the comment above. |
||
// TODO: Should we alert the user who created the trip of the deletion? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it would hurt to notify the creator of the trip. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Persistence.monitoredTrips | ||
.getFiltered(Filters.eq("observers.email", email)) | ||
.forEach(trip -> removeObserver(this, trip)); | ||
|
||
return Persistence.otpUsers.removeById(this.id); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is probably a case here for just deleting the trip if the primary traveler is no longer travelling. Perhaps that would start to complicate things though?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good observation. Could preventing tracking if a companion is set but no primary traveler is defined be a better way to handle that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think deleting the trip makes sense if there is no primary traveler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue #282 to track that.