From 106c53cce6725591337773d412c0fb74eaf81ed8 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 17 Apr 2023 16:01:28 +0300
Subject: Add/remove from whitelist on web
---
src/main/assets/scripts.js | 25 ++++++++++++++++++++++
.../com/juick/service/PrivacyQueriesService.java | 2 ++
.../juick/service/PrivacyQueriesServiceImpl.java | 16 ++++++++++++++
src/main/java/com/juick/www/api/Users.java | 21 ++++++++++++------
src/main/java/com/juick/www/controllers/Site.java | 1 +
.../templates/views/partial/usercolumn.html | 15 ++++++++++++-
6 files changed, 73 insertions(+), 7 deletions(-)
(limited to 'src/main')
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js
index 6c5e987b..4422fdb3 100644
--- a/src/main/assets/scripts.js
+++ b/src/main/assets/scripts.js
@@ -492,6 +492,23 @@ function setPrivacy(e, mid) {
.catch(console.err);
return false;
}
+function toggleWL(e, name) {
+ fetch('/api/users/wl?name=' + name
+ + '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
+ credentials: 'same-origin',
+ method: 'POST'
+ })
+ .then(handleErrors)
+ .then(function(response) {
+ if (response.ok) {
+ window.location.reload();
+ } else {
+ alert('Something went wrong :(');
+ }
+ })
+ .catch(console.err);
+ return false;
+}
function getTags() {
fetch('/api/tags?hash=' + document.getElementById('body').getAttribute('data-hash'), {
@@ -714,6 +731,14 @@ ready(() => {
e.preventDefault();
});
});
+ Array.from(document.querySelectorAll('.a-vip')).forEach(function(e) {
+ e.addEventListener('click', function(e) {
+ toggleWL(
+ e.target,
+ e.target.closest('[data-name]').getAttribute('data-name'));
+ e.preventDefault();
+ });
+ });
Array.from(document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]')).forEach(function(el) {
el.addEventListener('click', function(e) {
let fname = /** @type {HTMLElement} */ (e.target).closest('[data-fname]').getAttribute('data-fname');
diff --git a/src/main/java/com/juick/service/PrivacyQueriesService.java b/src/main/java/com/juick/service/PrivacyQueriesService.java
index 68c157f6..f1b9915d 100644
--- a/src/main/java/com/juick/service/PrivacyQueriesService.java
+++ b/src/main/java/com/juick/service/PrivacyQueriesService.java
@@ -35,4 +35,6 @@ public interface PrivacyQueriesService {
@CacheEvict(value = { "discussions", "messages", "replies" }, allEntries = true)
PrivacyResult blacklistTag(User user, Tag tag);
+
+ PrivacyResult whiteListUser(User user, User target);
}
diff --git a/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java b/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
index 437c9f8c..d954df09 100644
--- a/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
+++ b/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java
@@ -60,4 +60,20 @@ public class PrivacyQueriesServiceImpl extends BaseJdbcService implements Privac
return PrivacyResult.Added;
}
+
+ @Override
+ public PrivacyResult whiteListUser(User user, User target) {
+ int result = getJdbcTemplate().update(
+ "DELETE FROM wl_users WHERE user_id = ? AND wl_user_id = ?",
+ user.getUid(), target.getUid());
+
+ if (result > 0)
+ return PrivacyResult.Removed;
+
+ getJdbcTemplate().update(
+ "INSERT INTO wl_users(user_id, wl_user_id) VALUES (?, ?)",
+ user.getUid(), target.getUid());
+
+ return PrivacyResult.Added;
+ }
}
diff --git a/src/main/java/com/juick/www/api/Users.java b/src/main/java/com/juick/www/api/Users.java
index afca7ee3..19075fe5 100644
--- a/src/main/java/com/juick/www/api/Users.java
+++ b/src/main/java/com/juick/www/api/Users.java
@@ -28,12 +28,7 @@ import javax.inject.Inject;
import com.juick.model.AnonymousUser;
import com.juick.model.ApplicationStatus;
import com.juick.model.User;
-import com.juick.service.EmailService;
-import com.juick.service.MessagesService;
-import com.juick.service.StorageService;
-import com.juick.service.TagService;
-import com.juick.service.TelegramService;
-import com.juick.service.UserService;
+import com.juick.service.*;
import com.juick.service.activities.UpdateUserEvent;
import com.juick.service.component.MailVerificationEvent;
import com.juick.util.HttpBadRequestException;
@@ -59,6 +54,8 @@ public class Users {
@Inject
private UserService userService;
@Inject
+ private PrivacyQueriesService privacyQueriesService;
+ @Inject
private MessagesService messagesService;
@Inject
private TelegramService telegramService;
@@ -222,6 +219,18 @@ public class Users {
throw new HttpNotFoundException();
}
+ @PostMapping("/api/users/wl")
+ public void toggleWL(@Parameter(hidden = true) User visitor, @RequestParam String name) {
+ if (!visitor.isAnonymous()) {
+ User user = userService.getUserByName(name);
+ if (!user.isAnonymous()) {
+ privacyQueriesService.whiteListUser(visitor, user);
+ }
+ } else {
+ throw new HttpBadRequestException();
+ }
+ }
+
@GetMapping("/api/info/{uname}")
public User getUserInfo(@Parameter(hidden = true) User visitor, @PathVariable String uname) {
User user = userService.getUserByName(uname);
diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java
index 9773c098..834a2a25 100644
--- a/src/main/java/com/juick/www/controllers/Site.java
+++ b/src/main/java/com/juick/www/controllers/Site.java
@@ -83,6 +83,7 @@ public class Site {
model.addAttribute("user", user);
model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid()));
model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid()));
+ model.addAttribute("isInWL", userService.isInWL(visitor.getUid(), user.getUid()));
model.addAttribute("isInBLAny", userService.isInBLAny(user.getUid(), visitor.getUid()));
model.addAttribute("statsIRead", userService.getUserFriends(user.getUid()).size());
model.addAttribute("statsMyReaders", userService.getUserReaders(user.getUid()).size());
diff --git a/src/main/resources/templates/views/partial/usercolumn.html b/src/main/resources/templates/views/partial/usercolumn.html
index ee9ab267..aec72c58 100644
--- a/src/main/resources/templates/views/partial/usercolumn.html
+++ b/src/main/resources/templates/views/partial/usercolumn.html
@@ -19,7 +19,7 @@
{% if isInBL %}
- Unblock
+ Unblock
{% else %}
@@ -27,6 +27,19 @@
Block
{% endif %}
+ {% if visitor.premium or beans.userServiceImpl.isAdminUser(visitor) %}
+ {% if isInWL %}
+
+
+ Remove from VIP
+
+ {% else %}
+
+
+ Add to VIP
+
+ {% endif %}
+ {% endif %}
{% if not isInBLAny %}
--
cgit v1.2.3