Skip to content

Commit

Permalink
some changes about access
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoleNG18 committed Apr 17, 2024
1 parent 0ae2309 commit 106214f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
.requestMatchers("/classes/add","/classes/edit/**",
"/classes/edited/**","/classes/delete/**","/students/**","/classes/{idTeacher}/{id}","/classes").hasRole(UserRoleEnum.ADMIN.name())

.requestMatchers("/students/{id}").hasAnyRole(UserRoleEnum.USER.name(),UserRoleEnum.ADMIN.name())

.requestMatchers("/denseBall", "/jump",
"/thirty", "/twoHundred",
"/tTest","/classes/{idTeacher}/{id}","/classes").hasRole(UserRoleEnum.USER.name())
"/tTest","/classes/{id}","/classes").hasRole(UserRoleEnum.USER.name())

// all other requests are authenticated.
.anyRequest().authenticated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void updateClassesEveryYear() {
}
}

public UUID saveClass(ClassAddBindingDto classAddBindingDto,
public void saveClass(ClassAddBindingDto classAddBindingDto,
String teacherName) {

SchoolEntity schoolByTeacher = this.userService.getSchoolByTeacher(teacherName);
Expand All @@ -86,8 +86,6 @@ public UUID saveClass(ClassAddBindingDto classAddBindingDto,

this.userService.setClassToTeacher(classToSave, teacherName);
this.schoolService.addClassToSchool(schoolByTeacher, classToSave);

return this.classRepository.getReferenceById(classToSave.getId()).getId();
}

private ClassEntity mapToClassEntity(ClassAddBindingDto classAddBindingDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public String postAddClass(@Valid ClassAddBindingDto classAddBindingDto,
return "redirect:/classes/add";
}

this.classesService.saveClass(classAddBindingDto, classAddBindingDto.getTeacher());

return "redirect:/classes";
}

Expand Down Expand Up @@ -136,9 +138,6 @@ public String editClass(

this.classesService.editClass(id, classEdit);

// UserEntity currentUser = this.userService.getUserByEmail(principal.getName());

// return "redirect:/classes/" + currentUser.getId() + "/" + id;
return "redirect:/classes/"+id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.hibernate.ObjectNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public String postAddStudent(@Valid StudentAddBindingDto studentAddBindingDto,
public String editStudent(@PathVariable("id") UUID id,
@Valid StudentUpdateBindingDto studentUpdate,
BindingResult bindingResult,
RedirectAttributes redirectAttributes,
Principal principal) {
RedirectAttributes redirectAttributes) {

if (bindingResult.hasErrors()) {

Expand All @@ -97,9 +96,8 @@ public String editStudent(@PathVariable("id") UUID id,
}

UUID classId = this.studentsService.editStudent(studentUpdate, id);
UserEntity currentUser = this.userService.getUserByEmail(principal.getName());

return "redirect:/classes/" + currentUser.getId() + "/" + classId;
return "redirect:/classes/" + classId;
}

@PostMapping("/delete/{idTeacher}/{id}")
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/current-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h2 th:text="#{current_class_classes}">Classes</h2>

<ul th:each="class: ${classes}">
<li><a th:text="${class.className}"
th:href="@{/classes/{idTeacher}/{id}(idTeacher=${class.getTeacher().id},id=${class.id})}">class</a>
th:href="@{/classes/{id}(id=${class.id})}">class</a>
</li>
</ul>
</div>
Expand Down

0 comments on commit 106214f

Please sign in to comment.