Skip to content

Commit

Permalink
Setting users private
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Liechti authored and Luca Liechti committed Jan 8, 2020
1 parent fa97b88 commit 2a773d0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/radius/config/MultiHttpSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void configure(HttpSecurity http) throws Exception {
.authorizeRequests()
.antMatchers("/profile", "/answers", "/status", "/toggleStatus").authenticated()
.antMatchers("/admin/**", "/updateConfiguration/**", "/contactUsers/**",
"/sendNewsletter/**", "/banUser**", "/deleteUser**", "/unsubscribeNewsletter**",
"/sendNewsletter/**", "/banUser**", "/deleteUser**", "/setPrivate**", "/unsubscribeNewsletter**",
"/actuator/**", "/health/**").hasRole("ADMIN")
.anyRequest().permitAll();

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/radius/data/repository/JDBCUserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class JDBCUserRepository implements UserRepository {
private static final String UPDATE_LAST_LOGIN = "UPDATE users SET lastlogin = ? WHERE email = ?";
private static final String REGION_DENSITY = "SELECT locations FROM users";
private static final String BAN_USER = "UPDATE users SET banned = TRUE WHERE email = ?";
private static final String SET_PRIVATE = "UPDATE users SET private = TRUE WHERE email = ?";

@Autowired
public void init(DataSource jdbcdatasource, ConfigService configService) {
Expand Down Expand Up @@ -189,6 +190,11 @@ public List<String> regionDensity() {
public void banUser(String email) {
jdbcTemplate.update(BAN_USER, email);
}

@Override
public void setPrivate(String email) {
jdbcTemplate.update(SET_PRIVATE, email);
}
}


Expand Down
2 changes: 2 additions & 0 deletions src/main/java/radius/data/repository/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public interface UserRepository {
List<String> regionDensity();

void banUser(String username);

void setPrivate(String username);
}
14 changes: 14 additions & 0 deletions src/main/java/radius/web/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public String deleteUser(@RequestParam(value = "uuid") String uuid, Model model)
return "admin";
}

@RequestMapping(path="/setPrivate", method=GET)
public String setPrivate(@RequestParam(value = "uuid") String uuid, Model model) {
Optional<String> optionalUser = userService.findEmailByUuid(uuid);
if(optionalUser.isPresent()) {
if(userService.setUserPrivate(optionalUser.get())) {
model.addAttribute("success", Boolean.TRUE);
} else {
model.addAttribute("failure", Boolean.TRUE);
}
}
model.addAttribute("users", userService.allUsers());
return "admin";
}

@RequestMapping(path="/unsubscribeNewsletter", method=GET)
public String unsubscribeNewsletter(@RequestParam(value = "uuid") String uuid, Model model) {
if(newsletterservice.unsubscribe(uuid)){
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/radius/web/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ public boolean banUser(String username) {
return true;
}

public boolean setUserPrivate(String username) {
try {
userRepo.setPrivate(username);
} catch (Exception e) {
return false;
}
return true;
}

public List<User> matchableUsers() {
try {
return userRepo.matchableUsers();
Expand Down
16 changes: 15 additions & 1 deletion src/main/webapp/WEB-INF/views/admin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
<!--<th>Email bestätigt</th>-->
<th>Status</th>
<th>Letzte Änderung</th>
<th>Privat</th>
<th>Sperren</th>
<th>Löschen</th>
</tr>
Expand All @@ -300,7 +301,20 @@
<td><spring:message code="status.${user.status}"/></td>
<td><fmt:formatDate value="${user.dateModified}" pattern = "yyyy-MM-dd"/></td>
<td>
<a href="<c:url value='/banUser?uuid=${user.uuid}'/>" class="adminbutton ban" onClick="return confirm('Diese Aktion kann nur manuell rückgängig gemacht werden. Sicher?');">sperren</a>
<c:choose>
<c:when test="${user.privateUser}">👪👪</c:when>
<c:otherwise>
<a href="<c:url value='/setPrivate?uuid=${user.uuid}'/>" class="adminbutton private" onClick="return confirm('Diese Aktion kann nur manuell rückgängig gemacht werden. Sicher?');">privat</a>
</c:otherwise>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${user.banned}">🔒🔒</c:when>
<c:otherwise>
<a href="<c:url value='/banUser?uuid=${user.uuid}'/>" class="adminbutton ban" onClick="return confirm('Diese Aktion kann nur manuell rückgängig gemacht werden. Sicher?');">sperren</a>
</c:otherwise>
</c:choose>
</td>
<td>
<a href="<c:url value='/deleteUser?uuid=${user.uuid}'/>" class="adminbutton delete" onClick="return confirm('Diese Aktion kann nicht rückgängig gemacht werden. Sicher?');">löschen</a>
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ figure {
.delete {
background-color: #000;
}
.private {
background-color: #70ff8b;
}

0 comments on commit 2a773d0

Please sign in to comment.