aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/service/UserService.java2
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java6
-rw-r--r--src/main/java/com/juick/www/controllers/Settings.java4
-rw-r--r--src/main/resources/templates/views/settings_main.html2
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java5
5 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index c0428169..06637aee 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -185,4 +185,6 @@ public interface UserService {
String getJIDByHash(String hash);
boolean setJIDUser(String hash, int uid);
+
+ boolean canDeleteTelegramUser(User user);
}
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index e73f4ea3..fd42048c 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -914,4 +914,10 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
public boolean setJIDUser(String hash, int uid) {
return getJdbcTemplate().update("UPDATE jids SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public boolean canDeleteTelegramUser(User user) {
+ return getEmails(user).size() > 0 || getFbCrossPostStatus(user.getUid()).isConnected() || getVkTokens(user.getUid()).isPresent();
+ }
}
diff --git a/src/main/java/com/juick/www/controllers/Settings.java b/src/main/java/com/juick/www/controllers/Settings.java
index 8fefadc2..1dc5f1c3 100644
--- a/src/main/java/com/juick/www/controllers/Settings.java
+++ b/src/main/java/com/juick/www/controllers/Settings.java
@@ -248,7 +248,9 @@ public class Settings {
result = "<p><a href=\"/settings\">Back</a></p>";
break;
case "telegram-del":
- telegramService.deleteTelegramUser(visitor.getUid());
+ if (userService.canDeleteTelegramUser(visitor)) {
+ telegramService.deleteTelegramUser(visitor.getUid());
+ }
result = "<p><a href=\"/settings\">Back</a></p>";
break;
case "facebook-disable":
diff --git a/src/main/resources/templates/views/settings_main.html b/src/main/resources/templates/views/settings_main.html
index a6cca7a3..678d4c6f 100644
--- a/src/main/resources/templates/views/settings_main.html
+++ b/src/main/resources/templates/views/settings_main.html
@@ -24,7 +24,7 @@
<form action="/settings" method="post">
<div>Telegram: <b>{{ telegram_name }}</b> &mdash;
<input type="hidden" name="page" value="telegram-del"/>
- <input type="submit" value=" Disable " class="Button" />
+ <input type="submit" value=" Disable " {% if not beans.userServiceImpl.canDeleteTelegramUser(visitor) %}disabled="disabled"{% endif %} class="Button" />
</div>
</form>
{% else %}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 1ef8fe7f..df247b66 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2160,8 +2160,13 @@ public class ServerTests {
@Test
public void verifiedUsersTest() {
assertThat(userService.getUserByName("ugnich").isVerified(), is(false));
+ jdbcTemplate.update("INSERT INTO telegram(user_id, tg_id) VALUES(?, ?)", ugnich.getUid(), "100001866137681");
+ assertThat(userService.canDeleteTelegramUser(userService.getUserByName("ugnich")), is(false));
jdbcTemplate.update("INSERT INTO facebook(user_id, fb_id) VALUES(?, ?)", ugnich.getUid(), "100001866137681");
assertThat(userService.getUserByName("ugnich").isVerified(), is(true));
+ assertThat(userService.canDeleteTelegramUser(userService.getUserByName("ugnich")), is(true));
+ jdbcTemplate.update("DELETE FROM facebook");
+ assertThat(userService.canDeleteTelegramUser(userService.getUserByName("ugnich")), is(false));
}
@Test