Skip to content

Commit

Permalink
Restrict draft and withdrawal (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
b1a9id authored and making committed Nov 23, 2017
1 parent 1d6a39b commit 3287a2b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 26 deletions.
22 changes: 14 additions & 8 deletions src/main/java/jjug/ErrorControllerAdvice.java
@@ -1,19 +1,19 @@
package jjug;

import java.nio.file.AccessDeniedException;
import java.util.NoSuchElementException;

import jjug.conference.ConferenceClosedException;
import jjug.submission.CfpClosedException;
import jjug.submission.CfpFixedException;
import jjug.submission.UnpublishedSubmissionException;
import jjug.vote.VoteClosedException;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

import jjug.conference.ConferenceClosedException;
import jjug.submission.CfpClosedException;
import jjug.submission.UnpublishedSubmissionException;
import jjug.vote.VoteClosedException;
import java.nio.file.AccessDeniedException;
import java.util.NoSuchElementException;

@ControllerAdvice(annotations = Controller.class)
public class ErrorControllerAdvice {
Expand Down Expand Up @@ -58,4 +58,10 @@ String voteClosedException() {
String conferenceClosedException() {
return "conference/conferenceClosed";
}
}

@ExceptionHandler(CfpFixedException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
String cfpFixedException() {
return "conference/cfpFixed";
}
}
8 changes: 6 additions & 2 deletions src/main/java/jjug/conference/enums/ConfStatus.java
@@ -1,11 +1,11 @@
package jjug.conference.enums;

import java.util.stream.Stream;

import jjug.DisplayMessage;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@AllArgsConstructor
@Getter
public enum ConfStatus implements DisplayMessage {
Expand All @@ -21,4 +21,8 @@ public static ConfStatus valueOf(int v) {
return Stream.of(values()).filter(x -> x.getValue() == v).findAny()
.orElseThrow(() -> new IllegalArgumentException(v + " is illegal!"));
}

public boolean isFixedCfp() {
return this.value >= SELECTION.getValue();
}
}
4 changes: 4 additions & 0 deletions src/main/java/jjug/submission/CfpFixedException.java
@@ -0,0 +1,4 @@
package jjug.submission;

public class CfpFixedException extends RuntimeException {
}
36 changes: 21 additions & 15 deletions src/main/java/jjug/submission/SubmissionController.java
@@ -1,11 +1,12 @@
package jjug.submission;

import static java.lang.String.format;
import static jjug.submission.enums.SubmissionStatus.*;

import java.util.Optional;
import java.util.UUID;

import jjug.CfpUser;
import jjug.conference.Conference;
import jjug.conference.ConferenceRepository;
import jjug.speaker.Speaker;
import jjug.speaker.SpeakerRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
Expand All @@ -14,13 +15,11 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jjug.CfpUser;
import jjug.conference.Conference;
import jjug.conference.ConferenceRepository;
import jjug.speaker.Speaker;
import jjug.speaker.SpeakerRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Optional;
import java.util.UUID;

import static java.lang.String.format;
import static jjug.submission.enums.SubmissionStatus.*;

@Controller
@RequiredArgsConstructor
Expand Down Expand Up @@ -108,13 +107,20 @@ String editSubmission(@PathVariable UUID submissionId, Model model,
return editForm(submissionId, model, submissionForm);
}
Submission submission = submissionRepository.findOne(submissionId).get();
if (submission.getConference().getConfStatus().isFixedCfp()) {
if (draft.isPresent() || withdraw.isPresent()) {
throw new CfpFixedException();
}
} else {
submission.setSubmissionStatus(draft.map(d -> DRAFT)
.orElseGet(() -> withdraw.map(w -> WITHDRAWN).orElse(SUBMITTED)));
}

Speaker speaker = speakerRepository.findByGithub(user.getGithub())
.orElseGet(() -> Speaker.builder().github(user.getGithub()).build());
BeanUtils.copyProperties(submissionForm, speaker);
BeanUtils.copyProperties(submissionForm, submission);
submission.setSpeaker(speaker);
submission.setSubmissionStatus(draft.map(d -> DRAFT)
.orElseGet(() -> withdraw.map(w -> WITHDRAWN).orElse(SUBMITTED)));
log.info("Edit {}", submission);
submissionRepository.save(submission);
return "redirect:/submissions/{submissionId}/form";
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/templates/conference/cfpFixed.html
@@ -0,0 +1,24 @@
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title th:text="${@cfpProps.applicationName}">アンケート</title>
<link rel="shortcut icon" th:href="@{/images/favicon.ico}" href="../../static/images/favicon.ico"/>
<link rel="stylesheet" th:href="@{/css/style.css}" href="../../static/css/style.css"/>
<link rel="stylesheet" th:href="@{/css/theme.css}" href="../../static/css/theme.css"/>
</head>
<body>
<section>
<h1 th:text="${@cfpProps.applicationName}">JJUG Call for Papers</h1>
</section>
<section>
<h3>下書き、取下には変更できません</h3>
<div sec:authorize="authenticated">
<hr/>
<a th:href="@{/}" href="../index.html" th:text="${@cfpProps.applicationName}">□ アンケート</a>
</div>
</section>
</body>
</html>
4 changes: 3 additions & 1 deletion src/main/resources/templates/submission/submissionForm.html
Expand Up @@ -156,13 +156,15 @@ <h3 th:text="#{private}">aaa</h3>
<br/>
<div>
<input type="submit" value="Submit CFP"/>
<!--/*/ <th:block th:unless="${submission.conference.confStatus.fixedCfp}"> /*/-->
<input type="submit" name="draft" value="Save as Draft"/>
<input th:if="${submissionId}" type="submit" name="withdraw" value="Withdraw CFP"/>
<!--/*/ </th:block> /*/-->
</div>
</form>
<hr/>
<a th:href="@{/}" href="../index.html" th:text="${@cfpProps.applicationName}">CFP</a>
</section>
</div>
</body>
</html>
</html>

0 comments on commit 3287a2b

Please sign in to comment.