Skip to content

Commit ced7506

Browse files
committed
Fixed #103, Fixed #102
1 parent 5b5fcdc commit ced7506

File tree

4 files changed

+110
-31
lines changed

4 files changed

+110
-31
lines changed

src/main/java/org/woehlke/simpleworklist/config/di/WebSecurityConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,16 @@ public WebSecurityConfig(
5858
@Override
5959
protected void configure(HttpSecurity http) throws Exception {
6060
http
61-
.headers().disable()
61+
.headers()
62+
.disable()
6263
.authorizeRequests()
6364
.antMatchers(applicationProperties.getWebSecurity().getAntPatternsPublic())
6465
.permitAll()
6566
.anyRequest()
6667
.fullyAuthenticated()
6768
.and()
69+
.csrf()
70+
.and()
6871
.formLogin()
6972
.loginPage(applicationProperties.getWebSecurity().getLoginPage())
7073
.usernameParameter(applicationProperties.getWebSecurity().getUsernameParameter())
@@ -75,6 +78,8 @@ protected void configure(HttpSecurity http) throws Exception {
7578
.successHandler(loginSuccessHandler)
7679
.permitAll()
7780
.and()
81+
.csrf()
82+
.and()
7883
.logout()
7984
.logoutUrl(applicationProperties.getWebSecurity().getLogoutUrl())
8085
.deleteCookies(applicationProperties.getWebSecurity().getCookieNamesToClear())

src/main/java/org/woehlke/simpleworklist/project/ProjectController.java

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,47 @@ public final String addNewTopLevelProjectForm(
108108
Locale locale, Model model
109109
){
110110
log.info("/project/add/new/project (GET)");
111-
return addNewProject(rootProjectId, userSession, locale, model);
111+
addNewProject(rootProjectId, userSession, locale, model);
112+
return "project/addToplevel";
112113
}
113114

114115

115-
@RequestMapping(path = "/add/new/project", method = RequestMethod.POST)
116+
@RequestMapping(path = "/add/new/project", method = {RequestMethod.POST, RequestMethod.PUT})
116117
public final String addNewTopLevelProjectSave(
117118
@Valid Project project,
118119
@ModelAttribute("userSession") UserSessionBean userSession,
119120
BindingResult result,
120121
Locale locale, Model model
121122
){
122123
log.info("/project/add/new/project (POST)");
123-
return addNewProjectPersist( rootProjectId, userSession, project, result, locale, model );
124+
return addNewProjectPersist( rootProjectId, userSession, project,
125+
result, locale, model, "project/addToplevel");
124126
}
125127

128+
@RequestMapping(path = "/{projectId}/add/new/project", method = RequestMethod.GET)
129+
public final String addNewSubProjectGet(
130+
@PathVariable long projectId,
131+
@ModelAttribute("userSession") UserSessionBean userSession,
132+
Locale locale, Model model
133+
) {
134+
log.info("private addNewProjectGet (GET) projectId="+projectId);
135+
addNewProject(projectId, userSession, locale, model);
136+
return "project/add";
137+
}
138+
139+
@RequestMapping(path = "/{projectId}/add/new/project", method = {RequestMethod.POST, RequestMethod.PUT})
140+
public final String addNewSubProjectPost(
141+
@PathVariable long projectId,
142+
@ModelAttribute("userSession") UserSessionBean userSession,
143+
@Valid Project project,
144+
BindingResult result,
145+
Locale locale, Model model) {
146+
log.info("private addNewProjectPost (POST) projectId="+projectId+" "+project.toString());
147+
return addNewProjectPersist( projectId, userSession, project,
148+
result, locale, model ,"project/add");
149+
}
150+
151+
126152
@RequestMapping(path = "/{thisProjectId}/move/to/{targetProjectId}", method = RequestMethod.GET)
127153
public final String moveProject(
128154
@PathVariable("thisProjectId") Project thisProject,
@@ -243,7 +269,7 @@ public final String deleteProject(
243269
}
244270

245271

246-
private final String addNewProject(
272+
private final void addNewProject(
247273
long projectId,
248274
UserSessionBean userSession,
249275
Locale locale,
@@ -274,15 +300,15 @@ private final String addNewProject(
274300
model.addAttribute("breadcrumb", breadcrumb);
275301
model.addAttribute("thisProject", thisProject);
276302
model.addAttribute("project", project);
277-
return "project/add";
278303
}
279304

280305
private String addNewProjectPersist(
281306
long projectId,
282307
UserSessionBean userSession,
283308
Project project,
284309
BindingResult result,
285-
Locale locale, Model model
310+
Locale locale, Model model,
311+
String template
286312
){
287313
log.info("private addNewProjectPersist projectId="+projectId+" "+project.toString());
288314
Context context = super.getContext(userSession);
@@ -301,7 +327,7 @@ private String addNewProjectPersist(
301327
model.addAttribute("breadcrumb", breadcrumb);
302328
model.addAttribute("thisProject", thisProject);
303329
model.addAttribute("project", project);
304-
return "project/add";
330+
return template;
305331
} else {
306332
if (projectId == 0) {
307333
if(userSession.getContextId()>0) {
@@ -324,28 +350,6 @@ private String addNewProjectPersist(
324350
}
325351
}
326352

327-
@RequestMapping(path = "/{projectId}/add/new/project", method = RequestMethod.GET)
328-
public final String addNewProjectGet(
329-
@PathVariable long projectId,
330-
@ModelAttribute("userSession") UserSessionBean userSession,
331-
Locale locale, Model model
332-
) {
333-
log.info("private addNewProjectGet (GET) projectId="+projectId);
334-
return addNewProject(projectId, userSession, locale, model);
335-
}
336-
337-
@RequestMapping(path = "/{projectId}/add/new/project",
338-
method = RequestMethod.POST)
339-
public final String addNewProjectPost(
340-
@PathVariable long projectId,
341-
@ModelAttribute("userSession") UserSessionBean userSession,
342-
@Valid Project project,
343-
BindingResult result,
344-
Locale locale, Model model) {
345-
log.info("private addNewProjectPost (POST) projectId="+projectId+" "+project.toString());
346-
return addNewProjectPersist( projectId, userSession, project, result, locale, model );
347-
}
348-
349353
@RequestMapping(path = "/task/{sourceTaskId}/changeorderto/{destinationTaskId}", method = RequestMethod.GET)
350354
public String changeTaskOrderIdWithinAProject(
351355
@PathVariable("sourceTaskId") Task sourceTask,

src/main/resources/templates/project/add.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h1>
1919

2020
<div th:fragment="mytwcontent">
2121
<div>
22-
<form id="formId" th:action="@{/project/addchild/{id}(id=${thisProjectId})}" th:object="${project}" method="post">
22+
<form id="formId" th:action="@{/project/{id}/add/new/project(id=${thisProject.id})}" th:object="${project}" method="post">
2323
<div class="form-group">
2424
<label th:for="${#ids.next('name')}" class="control-label">Name</label>
2525
<input type="text" th:field="*{name}" class="form-control" />
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html th:lang="${#locale.language}"
3+
xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:th="http://www.thymeleaf.org"
5+
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
6+
xmlns:sd="http://www.thymeleaf.org/spring-data">
7+
<head th:replace="layout/page :: tw-page-head(headtitle=~{::title},links=~{},refreshMessages=false)">
8+
<title th:text="'SimpleWorklist | ' + #{project.add.h1}">Title</title>
9+
</head>
10+
<body th:replace="layout/page :: tw-page-body(twcontent=~{::mytwcontent},twtitle=~{::mytwtitle},scripts=~{::script})">
11+
12+
<div th:fragment="mytwtitle">
13+
<!-- New Project Form -->
14+
<h1>
15+
<i class="fas fa-folder-open"></i> &nbsp;
16+
<span th:utext="#{project.add.h1}">Add Project</span>
17+
</h1>
18+
</div>
19+
20+
<div th:fragment="mytwcontent">
21+
<div>
22+
<form id="formId" th:action="@{/project/add/new/project}" th:object="${project}" method="post">
23+
<div class="form-group">
24+
<label th:for="${#ids.next('name')}" class="control-label">Name</label>
25+
<input type="text" th:field="*{name}" class="form-control" />
26+
<div>
27+
<div th:each="err : ${#fields.errors('name')}" th:text="${err}" class="alert alert-danger"></div>
28+
</div>
29+
</div>
30+
<div class="form-group">
31+
<label th:for="textEditor" class="control-label">
32+
<span th:utext="#{project.add.description}">Description</span>
33+
</label>
34+
<textarea id="textEditor" name="textEditor" rows="10" cols="50" th:field="*{description}" class="form-control"></textarea>
35+
<div>
36+
<div th:each="err : ${#fields.errors('description')}" th:text="${err}" class="alert alert-danger"></div>
37+
</div>
38+
</div>
39+
<div class="form-group">
40+
<label th:for="${#ids.next('context.id')}" class="control-label">
41+
<span th:utext="#{project.edit.context}">Area</span>
42+
</label>
43+
<select th:field="*{context.id}">
44+
<option th:each="areaOption : ${contexts}"
45+
th:value="${areaOption.id}"
46+
th:text="${locale == 'de' ? areaOption.nameDe : areaOption.nameEn}">Wireframe</option>
47+
</select>
48+
<div>
49+
<div th:each="err : ${#fields.errors('context.id')}" th:text="${err}" class="alert alert-danger"></div>
50+
</div>
51+
</div>
52+
<button id="createNewProject" type="submit" class="btn btn-primary">
53+
<i class="fas fa-save"></i>
54+
<span th:utext="#{project.add.button}">Add Project</span>
55+
</button>
56+
<input type="hidden"
57+
name="${_csrf.parameterName}"
58+
value="${_csrf.token}"/>
59+
</form>
60+
</div>
61+
<!-- Document Window End -->
62+
63+
</div>
64+
65+
<script th:src="@{/webjars/ckeditor/4.11.3/full/ckeditor.js}"></script>
66+
<script th:inline="javascript">
67+
CKEDITOR.replace( 'textEditor' );
68+
</script>
69+
</body>
70+
</html>

0 commit comments

Comments
 (0)