aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/model/Message.java2
-rw-r--r--src/main/java/com/juick/model/User.java12
-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/service/security/JuickUserDetailsService.java4
-rw-r--r--src/main/java/com/juick/www/api/Messages.java4
-rw-r--r--src/main/java/com/juick/www/api/Users.java4
-rw-r--r--src/main/resources/templates/views/partial/usercolumn.html2
-rw-r--r--src/main/resources/templates/views/thread.html2
9 files changed, 22 insertions, 16 deletions
diff --git a/src/main/java/com/juick/model/Message.java b/src/main/java/com/juick/model/Message.java
index 3c86970b..32d888a7 100644
--- a/src/main/java/com/juick/model/Message.java
+++ b/src/main/java/com/juick/model/Message.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
diff --git a/src/main/java/com/juick/model/User.java b/src/main/java/com/juick/model/User.java
index 5f89ecfc..7f04a744 100644
--- a/src/main/java/com/juick/model/User.java
+++ b/src/main/java/com/juick/model/User.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -62,6 +62,8 @@ public class User implements Serializable {
private String description;
private final List<TagStats> tagStats;
private boolean premium;
+ @XmlTransient
+ private boolean admin;
public User() {
tokens = new ArrayList<>();
@@ -288,4 +290,12 @@ public class User implements Serializable {
public void setPremium(boolean premium) {
this.premium = premium;
}
+
+ public boolean isAdmin() {
+ return admin;
+ }
+
+ public void setAdmin(boolean admin) {
+ this.admin = admin;
+ }
}
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 53acdfab..0cbe104f 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -123,8 +123,6 @@ public interface UserService {
void updateLastSeen(User user);
- boolean isAdminUser(User user);
-
Optional<ExternalToken> getTwitterToken(int uid);
@CacheEvict(value = "twitter_user", key="{ #uid }")
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index a7ea5c5f..442bd03c 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -66,6 +66,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
}
user.setVerified(rs.getLong(6) > 0);
user.setPremium(rs.getInt(7) > 0);
+ user.setAdmin(adminUsers.contains(user.getName()));
return user;
}
}
@@ -595,11 +596,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
getJdbcTemplate().update("UPDATE users SET last_seen=? WHERE id=?", toDateTime(Instant.now().atOffset(ZoneOffset.UTC)), user.getUid());
}
- @Override
- public boolean isAdminUser(User user) {
- return adminUsers.contains(user.getName());
- }
-
@Transactional(readOnly = true)
@Override
public Optional<ExternalToken> getTwitterToken(final int uid) {
diff --git a/src/main/java/com/juick/service/security/JuickUserDetailsService.java b/src/main/java/com/juick/service/security/JuickUserDetailsService.java
index e64a0c8e..9371b863 100644
--- a/src/main/java/com/juick/service/security/JuickUserDetailsService.java
+++ b/src/main/java/com/juick/service/security/JuickUserDetailsService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -49,7 +49,7 @@ public class JuickUserDetailsService implements UserDetailsService {
if (!user.isAnonymous()) {
user.setAuthHash(userService.getHashByUID(user.getUid()));
- List<GrantedAuthority> authorities = userService.isAdminUser(user) ?
+ List<GrantedAuthority> authorities = user.isAdmin() ?
JuickUser.ADMIN_AUTHORITY : JuickUser.USER_AUTHORITY;
return new JuickUser(user, authorities);
}
diff --git a/src/main/java/com/juick/www/api/Messages.java b/src/main/java/com/juick/www/api/Messages.java
index ef55944b..969bef4f 100644
--- a/src/main/java/com/juick/www/api/Messages.java
+++ b/src/main/java/com/juick/www/api/Messages.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2021, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -212,7 +212,7 @@ public class Messages {
}
@PostMapping("/api/messages/set_privacy")
public void togglePrivacy(@Parameter(hidden = true) User visitor, @RequestParam Integer mid) {
- if (visitor.isPremium() || userService.isAdminUser(visitor)) {
+ if (visitor.isPremium() || visitor.isAdmin()) {
var msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new);
messagesService.setFriendsOnly(mid, !msg.isFriendsOnly());
msg = messagesService.getMessage(mid).orElseThrow(HttpNotFoundException::new);
diff --git a/src/main/java/com/juick/www/api/Users.java b/src/main/java/com/juick/www/api/Users.java
index 19075fe5..4fb53ca1 100644
--- a/src/main/java/com/juick/www/api/Users.java
+++ b/src/main/java/com/juick/www/api/Users.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -110,6 +110,8 @@ public class Users {
me.setReaders(readers);
me.setAvatar(webApp.getAvatarUrl(visitor));
me.getTagStats().addAll(tagService.getUserTagStats(me.getUid()));
+ me.setPremium(visitor.isPremium());
+ me.setAdmin(visitor.isAdmin());
return (SecureUser)userService.getUserInfo(me);
}
@PostMapping("/api/me")
diff --git a/src/main/resources/templates/views/partial/usercolumn.html b/src/main/resources/templates/views/partial/usercolumn.html
index aec72c58..70d20083 100644
--- a/src/main/resources/templates/views/partial/usercolumn.html
+++ b/src/main/resources/templates/views/partial/usercolumn.html
@@ -27,7 +27,7 @@
<span class="desktop">Block</span>
</a>
{% endif %}
- {% if visitor.premium or beans.userServiceImpl.isAdminUser(visitor) %}
+ {% if visitor.premium or visitor.admin %}
{% if isInWL %}
<a href="/api/users/wl?nick={{ user.name }}" data-name={{ user.name }} class="a-vip">
<i data-icon="ei-unlock" data-size="s"></i>
diff --git a/src/main/resources/templates/views/thread.html b/src/main/resources/templates/views/thread.html
index 3974fddb..19d81d75 100644
--- a/src/main/resources/templates/views/thread.html
+++ b/src/main/resources/templates/views/thread.html
@@ -40,7 +40,7 @@
</div>
{% endif %}
<nav class="l">
- {% if visitor.uid == msg.user.uid and (msg.user.premium or beans.userServiceImpl.isAdminUser(msg.user)) %}
+ {% if visitor.uid == msg.user.uid and (msg.user.premium or msg.user.admin) %}
<a href="/{{ msg.mid }}" class="a-privacy msg-button">
<span class="msg-button-icon">
{% if msg.friendsOnly %}