diff --git a/build.gradle b/build.gradle index e57e620..4a07d96 100644 --- a/build.gradle +++ b/build.gradle @@ -124,6 +124,7 @@ dependencies { compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0' compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0' + compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.35.0' testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' diff --git a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java index 894cf39..5eb7220 100644 --- a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java @@ -13,8 +13,10 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; +import ru.ulstu.core.model.AuthFailureHandler; import ru.ulstu.user.controller.UserController; import ru.ulstu.user.model.UserRoleConstants; import ru.ulstu.user.service.UserService; @@ -35,17 +37,20 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { private final AuthenticationSuccessHandler authenticationSuccessHandler; private final LogoutSuccessHandler logoutSuccessHandler; private final ApplicationProperties applicationProperties; + private final AuthenticationFailureHandler authenticationFailureHandler; public SecurityConfiguration(UserService userService, BCryptPasswordEncoder bCryptPasswordEncoder, AuthenticationSuccessHandler authenticationSuccessHandler, LogoutSuccessHandler logoutSuccessHandler, - ApplicationProperties applicationProperties) { + ApplicationProperties applicationProperties, + AuthFailureHandler authenticationFailureHandler) { this.userService = userService; this.bCryptPasswordEncoder = bCryptPasswordEncoder; this.authenticationSuccessHandler = authenticationSuccessHandler; this.logoutSuccessHandler = logoutSuccessHandler; this.applicationProperties = applicationProperties; + this.authenticationFailureHandler = authenticationFailureHandler; } @Override @@ -66,6 +71,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers(UserController.ACTIVATE_URL).permitAll() .antMatchers(Constants.PASSWORD_RESET_REQUEST_PAGE).permitAll() .antMatchers(Constants.PASSWORD_RESET_PAGE).permitAll() + .antMatchers("/users/block").permitAll() .antMatchers(UserController.URL + UserController.REGISTER_URL).permitAll() .antMatchers(UserController.URL + UserController.ACTIVATE_URL).permitAll() .antMatchers(UserController.URL + UserController.PASSWORD_RESET_REQUEST_URL).permitAll() @@ -76,6 +82,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .formLogin() .loginPage("/login") .successHandler(authenticationSuccessHandler) + .failureHandler(authenticationFailureHandler) .permitAll() .and() .logout() diff --git a/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java b/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java new file mode 100644 index 0000000..8b6bd9d --- /dev/null +++ b/src/main/java/ru/ulstu/core/model/AuthFailureHandler.java @@ -0,0 +1,21 @@ +package ru.ulstu.core.model; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; +import org.springframework.stereotype.Component; +import ru.ulstu.user.error.UserBlockedException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class AuthFailureHandler implements AuthenticationFailureHandler { + @Override + public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, + AuthenticationException ex) throws IOException { + if (ex.getClass() == UserBlockedException.class) { + response.sendRedirect("/users/block"); + } + } +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 1e28a33..48dee8e 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -50,7 +50,7 @@ public class GrantController { @GetMapping("/grant") public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { - GrantDto grantDto = grantService.findOneDto(id); + GrantDto grantDto = grantService.getExistGrantById(id); attachPaper(grantDto); modelMap.put("grantDto", grantDto); } else { diff --git a/src/main/java/ru/ulstu/grant/page/KiasPage.java b/src/main/java/ru/ulstu/grant/page/KiasPage.java index 631f5db..0a83b43 100644 --- a/src/main/java/ru/ulstu/grant/page/KiasPage.java +++ b/src/main/java/ru/ulstu/grant/page/KiasPage.java @@ -1,8 +1,13 @@ package ru.ulstu.grant.page; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; +import com.gargoylesoftware.htmlunit.html.DomElement; +import com.gargoylesoftware.htmlunit.html.DomNode; +import com.gargoylesoftware.htmlunit.html.DomNodeList; +import com.gargoylesoftware.htmlunit.html.HtmlAnchor; +import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlTableDataCell; +import com.gargoylesoftware.htmlunit.html.HtmlTableRow; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -11,16 +16,17 @@ import java.util.List; public class KiasPage { private final static String KIAS_GRANT_DATE_FORMAT = "dd.MM.yyyy HH:mm"; - private WebDriver driver; + private final HtmlPage page; - public KiasPage(WebDriver webDriver) { - this.driver = webDriver; + public KiasPage(HtmlPage page) { + this.page = page; } public boolean goToNextPage() { try { - if (driver.findElements(By.id("js-ctrlNext")).size() > 0) { - driver.findElement(By.id("js-ctrlNext")).click(); + HtmlElement nextPageLink = page.getHtmlElementById("js-ctrlNext"); + if (nextPageLink.isDisplayed()) { + nextPageLink.click(); return true; } } finally { @@ -28,23 +34,25 @@ public class KiasPage { } } - public List getPageOfGrants() { - WebElement listContest = driver.findElement(By.tagName("tBody")); - List grants = listContest.findElements(By.cssSelector("tr.tr")); - return grants; + public List getPageOfGrants() { + return page.getByXPath("/html/body/div[2]/div/div[2]/main/div[1]/table/tbody/tr"); } - public String getGrantTitle(WebElement grant) { - return grant.findElement(By.cssSelector("td.tertiary")).findElement(By.tagName("a")).getText(); + public String getGrantTitle(DomNode grant) { + return ((DomNode)grant.getFirstByXPath("td[@class='tertiary']/a")).getTextContent(); } - public Date parseDeadLineDate(WebElement grantElement) throws ParseException { + public Date parseDeadLineDate(DomNode grantElement) throws ParseException { String deadlineDate = getFirstDeadline(grantElement); //10.06.2019 23:59 SimpleDateFormat formatter = new SimpleDateFormat(KIAS_GRANT_DATE_FORMAT); return formatter.parse(deadlineDate); } - private String getFirstDeadline(WebElement grantElement) { - return grantElement.findElement(By.xpath("./td[5]")).getText(); + private String getFirstDeadline(DomNode grantElement) { + return ((DomNode)grantElement.getFirstByXPath("td[5]")).getTextContent(); + } + + public boolean isTrGrantLine(DomNode grantElement) { + return !((HtmlTableRow)grantElement).getAttribute("class").contains("pagerSavedHeightSpacer"); } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 03ae07f..99387c7 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -1,5 +1,6 @@ package ru.ulstu.grant.service; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -17,7 +18,6 @@ import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; -import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; import ru.ulstu.timeline.service.EventService; @@ -77,6 +77,11 @@ public class GrantService extends BaseService { this.pingService = pingService; } + public GrantDto getExistGrantById(Integer id) { + GrantDto grantDto = new GrantDto(findById(id)); + return grantDto; + } + public List findAll() { return grantRepository.findAll(); } @@ -85,17 +90,13 @@ public class GrantService extends BaseService { return convert(findAll(), GrantDto::new); } - public GrantDto findOneDto(Integer id) { - return new GrantDto(grantRepository.findOne(id)); - } - @Transactional - public Integer create(GrantDto grantDto) throws IOException { + public Grant create(GrantDto grantDto) throws IOException { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта"); grantNotificationService.sendCreateNotification(newGrant); - return newGrant.getId(); + return newGrant; } private Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException { @@ -106,9 +107,11 @@ public class GrantService extends BaseService { grant.setProject(projectService.findById(grantDto.getProject().getId())); } grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines())); - grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream() - .filter(f -> !f.isDeleted()) - .collect(toList()))); + if (!grant.getFiles().isEmpty()) { + grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream() + .filter(f -> !f.isDeleted()) + .collect(toList()))); + } grant.getAuthors().clear(); if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) { grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds))); @@ -123,6 +126,7 @@ public class GrantService extends BaseService { return grant; } + public void createProject(GrantDto grantDto) throws IOException { grantDto.setProject( new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle())))); @@ -130,7 +134,7 @@ public class GrantService extends BaseService { @Transactional public Integer update(GrantDto grantDto) throws IOException { - Grant grant = grantRepository.findOne(grantDto.getId()); + Grant grant = findById(grantDto.getId()); Set oldAuthors = new HashSet<>(grant.getAuthors()); User oldLeader = grant.getLeader(); for (FileDataDto file : grantDto.getFiles().stream() @@ -159,34 +163,19 @@ public class GrantService extends BaseService { } @Transactional - public void delete(Integer grantId) throws IOException { - Grant grant = grantRepository.findOne(grantId); - grantRepository.delete(grant); + public boolean delete(Integer grantId) throws IOException { + Grant grant = findById(grantId); + if (grant != null) { + grantRepository.delete(grant); + return true; + } + return false; } public List getGrantStatuses() { return Arrays.asList(Grant.GrantStatus.values()); } - @Transactional - public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) { - Grant grant = new Grant(); - grant.setTitle(title); - grant.setComment("Комментарий к гранту 1"); - grant.setProject(projectId); - grant.setStatus(APPLICATION); - grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); - grant.getAuthors().add(user); - grant.setLeader(user); - grant.getPapers().add(paper); - grant = grantRepository.save(grant); - - eventService.createFromObject(grant, Collections.emptyList(), false, "гранта"); - grantNotificationService.sendCreateNotification(grant); - - return grant; - } - public boolean save(GrantDto grantDto, Errors errors) throws IOException { grantDto.setName(grantDto.getTitle()); filterEmptyDeadlines(grantDto); @@ -274,20 +263,22 @@ public class GrantService extends BaseService { return paperService.findAllNotCompleted(); } - public void attachPaper(GrantDto grantDto) { + public List attachPaper(GrantDto grantDto) { if (!grantDto.getPaperIds().isEmpty()) { grantDto.getPapers().clear(); grantDto.setPapers(getGrantPapers(grantDto.getPaperIds())); } else { grantDto.getPapers().clear(); } + return grantDto.getPapers(); } - public void removeDeadline(GrantDto grantDto, Integer deadlineId) { + public GrantDto removeDeadline(GrantDto grantDto, Integer deadlineId) { if (grantDto.getDeadlines().get(deadlineId).getId() != null) { grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId()); } grantDto.getDeadlines().remove((int) deadlineId); + return grantDto; } private List getCompletedPapersAuthors(Paper.PaperType type) { @@ -313,10 +304,11 @@ public class GrantService extends BaseService { .collect(toList()); } - public void filterEmptyDeadlines(GrantDto grantDto) { + public List filterEmptyDeadlines(GrantDto grantDto) { grantDto.setDeadlines(grantDto.getDeadlines().stream() - .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) + .filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription())) .collect(Collectors.toList())); + return grantDto.getDeadlines(); } @Transactional @@ -346,8 +338,4 @@ public class GrantService extends BaseService { public void ping(int grantId) throws IOException { pingService.addPing(findById(grantId)); } - - public Grant findGrantById(Integer grantId) { - return grantRepository.findOne(grantId); - } } diff --git a/src/main/java/ru/ulstu/grant/service/KiasService.java b/src/main/java/ru/ulstu/grant/service/KiasService.java index dbeacf5..56474fa 100644 --- a/src/main/java/ru/ulstu/grant/service/KiasService.java +++ b/src/main/java/ru/ulstu/grant/service/KiasService.java @@ -1,35 +1,29 @@ package ru.ulstu.grant.service; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.DomElement; +import com.gargoylesoftware.htmlunit.html.DomNode; +import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlPage; import org.springframework.stereotype.Service; import ru.ulstu.configuration.ApplicationProperties; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.page.KiasPage; import ru.ulstu.user.service.UserService; -import java.nio.file.Paths; +import java.io.IOException; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.List; -import static org.apache.commons.lang3.StringUtils.isEmpty; - @Service public class KiasService { private final static String BASE_URL = "https://www.rfbr.ru/rffi/ru/contest_search?CONTEST_STATUS_ID=%s&CONTEST_TYPE=%s&CONTEST_YEAR=%s"; private final static String CONTEST_STATUS_ID = "1"; private final static String CONTEST_TYPE = "-1"; - private final static String DRIVER_LOCATION = "drivers/%s"; - private final static String WINDOWS_DRIVER = "chromedriver.exe"; - private final static String LINUX_DRIVER = "chromedriver"; - private final static String DRIVER_TYPE = "webdriver.chrome.driver"; - private final UserService userService; private final ApplicationProperties applicationProperties; @@ -39,22 +33,22 @@ public class KiasService { this.applicationProperties = applicationProperties; } - public List getNewGrantsDto() throws ParseException { - WebDriver webDriver = getDriver(); + public List getNewGrantsDto() throws ParseException, IOException { Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId(); List grants = new ArrayList<>(); - for (Integer year : generateGrantYears()) { - webDriver.get(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year)); - grants.addAll(getKiasGrants(webDriver)); + try (final WebClient webClient = new WebClient()) { + for (Integer year : generateGrantYears()) { + final HtmlPage page = webClient.getPage(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year)); + grants.addAll(getKiasGrants(page)); + } } grants.forEach(grantDto -> grantDto.setLeaderId(leaderId)); - webDriver.quit(); return grants; } - public List getKiasGrants(WebDriver webDriver) throws ParseException { + public List getKiasGrants(HtmlPage page) throws ParseException { List newGrants = new ArrayList<>(); - KiasPage kiasPage = new KiasPage(webDriver); + KiasPage kiasPage = new KiasPage(page); do { newGrants.addAll(getGrantsFromPage(kiasPage)); } while (kiasPage.goToNextPage()); //проверка существования следующей страницы с грантами @@ -63,11 +57,13 @@ public class KiasService { private List getGrantsFromPage(KiasPage kiasPage) throws ParseException { List grants = new ArrayList<>(); - for (WebElement grantElement : kiasPage.getPageOfGrants()) { - GrantDto grantDto = new GrantDto( - kiasPage.getGrantTitle(grantElement), - kiasPage.parseDeadLineDate(grantElement)); - grants.add(grantDto); + for (DomNode grantElement : kiasPage.getPageOfGrants()) { + if (kiasPage.isTrGrantLine(grantElement)) { + GrantDto grantDto = new GrantDto( + kiasPage.getGrantTitle(grantElement), + kiasPage.parseDeadLineDate(grantElement)); + grants.add(grantDto); + } } return grants; } @@ -76,26 +72,4 @@ public class KiasService { return Arrays.asList(Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.YEAR) + 1); } - - private WebDriver getDriver() { - System.setProperty(DRIVER_TYPE, getDriverExecutablePath()); - final ChromeOptions chromeOptions = new ChromeOptions(); - chromeOptions.addArguments("--headless"); - return new ChromeDriver(chromeOptions); - } - - private String getDriverExecutablePath() { - return isEmpty(applicationProperties.getDriverPath()) - ? KiasService.class.getClassLoader() - .getResource(String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile() - : Paths.get(applicationProperties.getDriverPath(), getDriverExecutable(isWindows())).toString(); - } - - private String getDriverExecutable(boolean isWindows) { - return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER; - } - - private boolean isWindows() { - return System.getProperty("os.name").toLowerCase().contains("windows"); - } } diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index a458257..0592417 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -180,6 +180,11 @@ public class UserController extends OdinController { return new Response<>(userService.getActivitiesPings(userId, activity)); } + @PostMapping("/block") + public void blockUser(@RequestParam("userId") Integer userId) { + userService.blockUser(userId); + } + @GetMapping("/activities") public Response> getActivitiesList(@RequestParam("userId") Integer userId, @RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom, diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index fd65765..49ef5e3 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -75,6 +75,10 @@ public class UserMvcController extends OdinController { public void getPings() { } + @GetMapping("/block") + public void getBlock() { + } + @GetMapping("/activities") public void getActivities() { } diff --git a/src/main/java/ru/ulstu/user/error/UserBlockedException.java b/src/main/java/ru/ulstu/user/error/UserBlockedException.java new file mode 100644 index 0000000..23b9b3a --- /dev/null +++ b/src/main/java/ru/ulstu/user/error/UserBlockedException.java @@ -0,0 +1,9 @@ +package ru.ulstu.user.error; + +import org.springframework.security.core.AuthenticationException; + +public class UserBlockedException extends AuthenticationException { + public UserBlockedException(String message) { + super(message); + } +} diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index 520b439..bb76618 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -12,6 +12,7 @@ import javax.persistence.Enumerated; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -91,6 +92,10 @@ public class User extends BaseEntity { @Temporal(TemporalType.TIMESTAMP) private Date birthDate; + @ManyToOne() + @JoinColumn(name = "blocker_id") + private User blocker; + public enum UserDegree { CANDIDATE("Кандидат технических наук"), DOCTOR("Доктор технических наук"); @@ -229,6 +234,14 @@ public class User extends BaseEntity { this.degree = degree; } + public User getBlocker() { + return blocker; + } + + public void setBlocker(User blocker) { + this.blocker = blocker; + } + public String getUserAbbreviate() { return String.format(USER_ABBREVIATE_TEMPLATE, lastName == null ? "" : lastName, diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 4cf8e6a..1f28afc 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -24,6 +24,7 @@ import ru.ulstu.core.model.response.PageableItems; import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.user.error.UserActivationError; +import ru.ulstu.user.error.UserBlockedException; import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserIdExistsException; import ru.ulstu.user.error.UserIsUndeadException; @@ -328,6 +329,9 @@ public class UserService implements UserDetailsService { if (!user.getActivated()) { throw new UserNotActivatedException(); } + if (user.getBlocker() != null) { + throw new UserBlockedException(String.format("Вы заблокированы пользователем %s", user.getBlocker().getUserAbbreviate())); + } return new org.springframework.security.core.userdetails.User(user.getLogin(), user.getPassword(), Optional.ofNullable(user.getRoles()).orElse(Collections.emptySet()).stream() @@ -430,6 +434,12 @@ public class UserService implements UserDetailsService { return activitiesPings; } + public void blockUser(int userId) { + User userToBlock = findById(userId); + userToBlock.setBlocker(getCurrentUser()); + userRepository.save(userToBlock); + } + public void createActivityTookToWork(List users) { List activities = new ArrayList<>(); for (User user : users) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bb3b715..b95d006 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,6 +13,8 @@ server.ssl.key-store-password=secret server.ssl.key-password=password # Log settings (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF) logging.level.ru.ulstu=DEBUG +#HtmlUnit +logging.level.com.gargoylesoftware.htmlunit=ERROR # Mail Settings spring.mail.host=smtp.yandex.ru spring.mail.port=465 @@ -31,6 +33,7 @@ spring.jpa.hibernate.ddl-auto=validate liquibase.drop-first=false liquibase.enabled=true liquibase.change-log=classpath:db/changelog-master.xml + # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin diff --git a/src/main/resources/db/changelog-20190605_000000-schema.xml b/src/main/resources/db/changelog-20190605_000000-schema.xml index c035b35..2783660 100644 --- a/src/main/resources/db/changelog-20190605_000000-schema.xml +++ b/src/main/resources/db/changelog-20190605_000000-schema.xml @@ -8,4 +8,22 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-20190607_000002-schema.xml b/src/main/resources/db/changelog-20190607_000002-schema.xml new file mode 100644 index 0000000..9531c87 --- /dev/null +++ b/src/main/resources/db/changelog-20190607_000002-schema.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 3add1eb..4a5e1b2 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -53,5 +53,6 @@ + \ No newline at end of file diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index 05865b5..b5aef4e 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -120,6 +120,20 @@ function resetPassword() { }) } +function blockUser() { + userId = $('#userId').val(); + $.ajax({ + url:"/api/1.0/users/block?userId=" + userId, + contentType: "application/json; charset=utf-8", + method: "POST", + success: function() { + showFeedbackMessage("Пользователь заблокирован", MessageTypesEnum.SUCCESS) + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) +} function isEmailValid(email) { re = /\S+@\S+\.\S+/; diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 32939e7..d3c49dd 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -109,6 +109,7 @@ +