Skip to content

Commit

Permalink
Shadow ban instead of perma ban #417
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Dec 27, 2024
1 parent 26765f4 commit 7d35ce0
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public Authentication authenticate(Authentication authentication) throws Authent
if (user == null) {
throw new BadCredentialsException("");
}
if (user.isDisabled()) {
throw new DisabledException("");
}

if (password.isEmpty()) {
throw new BadCredentialsException("");
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/nonononoki/alovoa/html/ApiResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ public Map<String, Object> resourceProfileView(@PathVariable UUID uuid) throws
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
}

if (userView.isDisabled()) {
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
}

ModelMap map = new ModelMap();

userView = userRepo.saveAndFlush(userView);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/nonononoki/alovoa/model/UserGdpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
@Data
public class UserGdpr {

private boolean confirmed;
private boolean disabled;
private int preferedMinAge;
private int preferedMaxAge;
private Double locationLatitude;
Expand Down Expand Up @@ -41,8 +39,6 @@ public class UserGdpr {

public static UserGdpr userToUserGdpr(User user) {
UserGdpr u = new UserGdpr();
u.setConfirmed(user.isConfirmed());
u.setDisabled(user.isDisabled());
u.setPreferedMinAge(user.getPreferedMinAge());
u.setPreferedMaxAge(user.getPreferedMaxAge());
u.setTotalDonations(user.getTotalDonations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
import com.nonononoki.alovoa.entity.user.UserDonation;

public interface UserDonationRepository extends JpaRepository<UserDonation, Long> {
List<UserDonation> findTop20ByUserDatesDateOfBirthGreaterThanEqualAndUserDatesDateOfBirthLessThanEqualOrderByDateDesc(Date minDate, Date maxDate);
List<UserDonation> findTop20ByUserDisabledFalseAndUserDatesDateOfBirthGreaterThanEqualAndUserDatesDateOfBirthLessThanEqualOrderByDateDesc(Date minDate, Date maxDate);
}

43 changes: 0 additions & 43 deletions src/main/java/com/nonononoki/alovoa/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,46 +140,7 @@ public void banUser(UUID uuid) throws AlovoaException, NumberFormatException {
throw new AlovoaException("user_is_admin");
}

UserDeleteParams userDeleteParam = UserDeleteParams.builder().conversationRepo(conversationRepo)
.userBlockRepo(userBlockRepo).userHideRepo(userHideRepo).userLikeRepo(userLikeRepo)
.userNotificationRepo(userNotificationRepo).userRepo(userRepo).userReportRepo(userReportRepo)
.userVerificationPictureRepo(userVerificationPictureRepo).build();

try {
UserService.removeUserDataCascading(user, userDeleteParam);
} catch (Exception e) {
logger.warn(ExceptionUtils.getStackTrace(e));
}

user = userRepo.findByEmail(user.getEmail());

user.setAudio(null);
user.setDates(null);
user.setDeleteToken(null);
user.setDescription(null);
user.setLanguage(null);
user.setCountry(null);
user.setDisabled(true);
user.getDonations().clear();
user.setFirstName(null);
user.setGender(null);
user.getImages().clear();
user.setIntention(null);
user.getInterests().clear();
user.setLocationLatitude(null);
user.setLocationLongitude(null);
user.setPassword(null);
user.setPasswordToken(null);
user.setPreferedGenders(null);
user.setPreferedMaxAge(0);
user.setPreferedMinAge(0);
user.setRegisterToken(null);
user.setTotalDonations(0);
user.setProfilePicture(null);
user.setVerificationCode(null);
user.setVerificationPicture(null);
user.setShowZodiac(false);
user.getPrompts().clear();
userRepo.saveAndFlush(user);
}

Expand All @@ -199,10 +160,6 @@ public void deleteAccount(AdminAccountDeleteDto dto) throws AlovoaException {
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
}

if (user.isDisabled()) {
throw new AlovoaException("user_is_banned");
}

if (user.isAdmin()) {
throw new AlovoaException("cannot_delete_admin");
}
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/nonononoki/alovoa/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,9 @@ public User getCurrentUser(boolean throwExceptionWhenNull) throws AlovoaExceptio
}

User user = userRepo.findByEmail(Tools.cleanEmail(email));
if (user != null && user.isDisabled()) {
if (user == null) {
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
} else if (user == null && throwExceptionWhenNull) {
//try again
user = userRepo.findByEmail(Tools.cleanEmail(email));
if (user == null) {
throw new AlovoaException(ExceptionHandler.USER_NOT_FOUND);
}
}

return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public List<DonationDto> filter(int filter) throws AlovoaException, InvalidKeyEx

if (filter == FILTER_RECENT) {
donationsToDtos = DonationDto.donationsToDtos(userDonationRepo
.findTop20ByUserDatesDateOfBirthGreaterThanEqualAndUserDatesDateOfBirthLessThanEqualOrderByDateDesc(
.findTop20ByUserDisabledFalseAndUserDatesDateOfBirthGreaterThanEqualAndUserDatesDateOfBirthLessThanEqualOrderByDateDesc(
minDate, maxDate),
user, userService, textEncryptor, maxEntries, ignoreIntention);
} else if (filter == FILTER_AMOUNT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ public UserPasswordToken resetPassword(PasswordResetDto dto)
throw new AlovoaException("user_has_social_login");
}

if (u.isDisabled()) {
throw new AlovoaException("user_disabled");
}

UserPasswordToken token = new UserPasswordToken();
token.setContent(RandomStringUtils.random(tokenLength, 0, 0, true, true, null, new SecureRandom()));
token.setDate(new Date());
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/nonononoki/alovoa/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -739,25 +739,25 @@ public void likeUser(UUID uuid, String message) throws AlovoaException {
like.setUserTo(user);
currUser.getLikes().add(like);

UserNotification not = new UserNotification();
not.setContent(UserNotification.USER_LIKE);
not.setDate(new Date());
not.setUserFrom(currUser);
not.setUserTo(user);
not.setMessage(message);
currUser.getNotifications().add(not);

user.getDates().setNotificationDate(new Date());

currUser.getHiddenUsers().removeIf(hide -> hide.getUserTo().getId().equals(user.getId()));
if (!currUser.isDisabled()) {
UserNotification not = new UserNotification();
not.setContent(UserNotification.USER_LIKE);
not.setDate(new Date());
not.setUserFrom(currUser);
not.setUserTo(user);
not.setMessage(message);
currUser.getNotifications().add(not);
user.getDates().setNotificationDate(new Date());
currUser.getHiddenUsers().removeIf(hide -> hide.getUserTo().getId().equals(user.getId()));
}

userRepo.saveAndFlush(user);
userRepo.saveAndFlush(currUser);

final boolean isMatch = user.getLikes().stream().filter(o -> o.getUserTo().getId() != null)
.anyMatch(o -> o.getUserTo().getId().equals(currUser.getId()));

if (isMatch) {
if (!currUser.isDisabled() && isMatch) {
Conversation convo = new Conversation();
convo.setUsers(new ArrayList<>());
convo.setDate(new Date());
Expand All @@ -777,7 +777,7 @@ public void likeUser(UUID uuid, String message) throws AlovoaException {
mailService.sendMatchNotificationMail(user);
}

} else if (user.getUserSettings().isEmailLike()) {
} else if (!currUser.isDisabled() && user.getUserSettings().isEmailLike()) {
mailService.sendLikeNotificationMail(user);
}
}
Expand Down

0 comments on commit 7d35ce0

Please sign in to comment.