Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Блокировка/удаление аккаунта в зависимости от флага user.FullDelete в SiteConfig #940

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Secret=secret
recaptcha.private=6LcdM0oUAAAAANYhnHF3jmD1r1TvkiyPaWHjC83x
recaptcha.public=6LcdM0oUAAAAAD2T-0ZW2HPkqZ5nFi1Y52U7BOMI

user.FullDelete = false

EnableHsts=false
# [email protected]
admin.emailAddress=specify_your_real_email_if_you_want_receive_messages
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ru/org/linux/spring/SiteConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,17 @@ public Integer getCommentScoreValueForEditing() {
}
return Integer.valueOf(property);
}

/**
* Полное удаление аккаунта, с переносом сообщений к Delete.
*
* @return true если разрешено, иначе false
*/
public Boolean isUserFullDelete() {
String property = properties.getProperty("user.FullDelete");
if (property == null) {
return false;
}
return Boolean.valueOf(property);
}
}
49 changes: 34 additions & 15 deletions src/main/java/ru/org/linux/user/DeregisterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,38 @@ public class DeregisterController {

@Autowired
private ElasticsearchIndexService indexService;

private boolean isFullDelete;

@RequestMapping(value = "/deregister.jsp", method = {RequestMethod.GET, RequestMethod.HEAD})
public ModelAndView show(
HttpServletRequest request,
@ModelAttribute("form") DeregisterRequest form
) {

Template tmpl = Template.getTemplate(request);
isFullDelete = tmpl.getConfig().isUserFullDelete();

if (!tmpl.isSessionAuthorized()) {
throw new AccessViolationException("Not authorized");
}

User user = tmpl.getCurrentUser();
user.checkAnonymous();

String msgDereg1, msgDereg2;
if(isFullDelete) {
msgDereg1 = "Удаление"; msgDereg2 = "удалить";
}else{
msgDereg1 = "Блокировка"; msgDereg2 = "заблокировать";
}

if (user.getScore() < 100) {
throw new AccessViolationException("Удаление аккаунта недоступно для пользователей со score < 100");
throw new AccessViolationException(msgDereg1 + " аккаунта недоступно для пользователей со score < 100");
}

if (user.isAdministrator() || user.isModerator()) {
throw new AccessViolationException("Нельзя удалить модераторский аккаунт");
throw new AccessViolationException("Нельзя " + msgDereg2 + " модераторский аккаунт");
}

return new ModelAndView("deregister");
Expand All @@ -83,6 +94,7 @@ public ModelAndView deregister(
) {

Template tmpl = Template.getTemplate(request);
isFullDelete = tmpl.getConfig().isUserFullDelete();

if (!tmpl.isSessionAuthorized()) {
throw new AccessViolationException("Not authorized");
Expand All @@ -91,50 +103,57 @@ public ModelAndView deregister(
User user = tmpl.getCurrentUser();
user.checkAnonymous();

String msgDereg1, msgDereg2, msgDereg3;
if(isFullDelete) {
msgDereg1 = "Удаление"; msgDereg2 = "удалить"; msgDereg3 = "самостоятельное удаление";
}else{
msgDereg1 = "Блокировка"; msgDereg2 = "заблокировать"; msgDereg3 = "самостоятельная блокировка";
}

if (user.getScore() < 100) {
throw new AccessViolationException("Удаление аккаунта недоступно для пользователей со score < 100");
throw new AccessViolationException(msgDereg1 + " аккаунта недоступно для пользователей со score < 100");
}

if (!user.matchPassword(form.getPassword())) {
errors.rejectValue("password", null, "Неверный пароль");
}

if (user.isAdministrator() || user.isModerator()) {
throw new AccessViolationException("Нельзя удалить модераторский аккаунт");
throw new AccessViolationException("Нельзя " + msgDereg2 + " модераторский аккаунт");
}

if (errors.hasErrors()) {
return new ModelAndView("deregister");
}

// Move messages
/*
List<Integer> movedComments = commentDao.getAllByUser(user);
List<Integer> movedTopics = topicDao.getAllByUser(user);
if (isFullDelete) {
List<Integer> movedComments = commentDao.getAllByUser(user);
List<Integer> movedTopics = topicDao.getAllByUser(user);

userDao.moveMessages(user.getId(), userDao.findUserId("Deleted"));
userDao.moveMessages(user.getId(), userDao.findUserId("Deleted"));

indexService.reindexComments(movedComments);
indexService.reindexTopics(movedTopics);
*/
indexService.reindexComments(movedComments);
indexService.reindexTopics(movedTopics);
}

// Remove user info
userDao.resetUserpic(user, user);
userDao.updateUser(user, "", "", null, "", null, "");

// Block account
userDao.block(user, user, "самостоятельная блокировка аккаунта");
userDao.block(user, user, msgDereg3 + " аккаунта");

return new ModelAndView(
"action-done",
"message",
"Удаление пользователя прошло успешно."
msgDereg1 + " пользователя прошло успешно."
);
}

@InitBinder("form")
public void requestValidator(WebDataBinder binder) {
binder.setValidator(new DeregisterRequestValidator());
binder.setValidator(new DeregisterRequestValidator(isFullDelete));
binder.setBindingErrorProcessor(new ExceptionBindingErrorProcessor());
}
}
15 changes: 10 additions & 5 deletions src/main/java/ru/org/linux/user/DeregisterRequestValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.springframework.validation.Validator;

public class DeregisterRequestValidator implements Validator {
public DeregisterRequestValidator(boolean isFullDelete) {
this.isFullDelete = isFullDelete;
}
private boolean isFullDelete;
@Override
public boolean supports(Class aClass) {
return DeregisterRequest.class.equals(aClass);
Expand All @@ -28,16 +32,17 @@ public boolean supports(Class aClass) {
public void validate(Object o, Errors errors) {
DeregisterRequest form = (DeregisterRequest) o;

String msgDereg;
if(isFullDelete) msgDereg = "с удалением"; else msgDereg = "с блокировкой";

if (!form.getAcceptBlock()) {
errors.reject("acceptBlock", null, "Вы не согласились с блокировкой аккаунта");
errors.reject("acceptBlock", null, "Вы не согласились " + msgDereg + " аккаунта");
}

/*
if (!form.getAcceptMoveToDeleted()) {
if(isFullDelete && !form.getAcceptMoveToDeleted()) {
errors.reject("acceptMoveToDeleted", null, "Вы не согласились с передачей всех сообщений специальному пользователю");
}
*/


if (!form.getAcceptOneway()) {
errors.reject("acceptOneway", null, "Вы не согласились с невозможностью восстановления аккаунта");
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/config.properties.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Secret=secret
recaptcha.private=6LcdM0oUAAAAANYhnHF3jmD1r1TvkiyPaWHjC83x
recaptcha.public=6LcdM0oUAAAAAD2T-0ZW2HPkqZ5nFi1Y52U7BOMI

user.FullDelete = false

EnableHsts=false
# [email protected]
admin.emailAddress=specify_your_real_email_if_you_want_receive_messages
Expand Down
22 changes: 14 additions & 8 deletions src/main/webapp/WEB-INF/jsp/deregister.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@
--%>
<jsp:include page="head.jsp"/>

<title>Удаление пользователя</title>
<c:set var="fullDelete" value="${template.getConfig().isUserFullDelete()}" />
<c:set var="msgDereg1" value="${fullDelete ? 'Удалить' : 'Заблокировать'}" />
<c:set var="msgDereg2" value="${fullDelete ? 'Удаление' : 'Блокировка'}" />

<title>${msgDereg2} пользователя</title>

<jsp:include page="header.jsp"/>
<H1>Удаление пользователя</H1>
<H1>${msgDereg2} пользователя</H1>
<p>
Аккаунт становится недоступен для входа<%--, все сообщения переходят к специальному пользователю--%>.
Аккаунт становится недоступен для входа
<c:if test="${fullDelete}">
, все сообщения переходят к специальному пользователю.
</c:if>
</p>

<form:form modelAttribute="form" method="POST" action="deregister.jsp" id="registerForm">
Expand All @@ -39,23 +46,22 @@
<div class="control-group">
<lor:captcha/>
</div>

<div class="control-group">
<label>Заблокировать мой аккаунт
<label>${msgDereg1} мой аккаунт
<form:checkbox path="acceptBlock" value="true" required="required" cssErrorClass="error"/>
</label>
<%--
<c:if test="${fullDelete}">
<label>Передать все сообщения специальному пользователю
<form:checkbox path="acceptMoveToDeleted" value="true" required="required" cssErrorClass="error"/>
</label>
--%>
</c:if>
<label>Согласен с невозможностью восстановления
<form:checkbox path="acceptOneway" value="true" required="required" cssErrorClass="error"/>
</label>
</div>

<div class="form-actions">
<button type=submit class="btn btn-primary">Удалить аккаунт</button>
<button type=submit class="btn btn-primary">${msgDereg1} аккаунт</button>
</div>
</form:form>
<jsp:include page="footer.jsp"/>
8 changes: 5 additions & 3 deletions src/main/webapp/WEB-INF/jsp/edit-profile.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ $script.ready('plugins', function() {
</form>

<h2>Другие настройки</h2>
<c:set var="fullDelete" value="${template.getConfig().isUserFullDelete()}" />
<c:set var="msgDereg1" value="${fullDelete ? 'Удаление' : 'Блокировка'}" />
<ul>
<li><a href="/addphoto.jsp">Добавить фотографию</a></li>
<li><a href="/people/${nick}/edit">Изменение регистрации</a></li>
<li><a href="/edit-boxes.jsp">Настройка главной страницы</a>
<li><a href="<c:url value="/user-filter"/>">Настройка фильтрации сообщений</a>
<li><a href="/edit-boxes.jsp">Настройка главной страницы</a></li>
<li><a href="<c:url value="/user-filter"/>">Настройка фильтрации сообщений</a></li>
<c:if test="${template.currentUser.score >= 100 && !template.moderatorSession && !template.currentUser.administrator}">
<li><a href="/deregister.jsp">Удаление аккаунта</a>
<li><a href="/deregister.jsp">${msgDereg1} аккаунта</a></li>
</c:if>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/sass/tango/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ p {
}

#bd li {
margin-left: 2em;
list-style: inherit;
list-style-position: inside;
}

#bd .sign {
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/sass/waltz/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ p {
}

#bd li {
margin-left: 2em;
list-style: inherit;
list-style-position: inside;
}

#bd .sign {
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/sass/zomg_ponies/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ div.msg-top-header{
}

#bd li {
margin-left: 2em;
list-style: inherit;
list-style-position: inside;
}

#bd .sign {
Expand Down