Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Portals committed Sep 7, 2024
1 parent 462a9e2 commit 3e7acb2
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.chalmers.gamma.app.common.Email.EmailValidator;
import it.chalmers.gamma.app.image.domain.ImageService;
import it.chalmers.gamma.app.user.MeFacade;
import it.chalmers.gamma.app.user.UserGdprTrainingFacade;
import it.chalmers.gamma.app.user.domain.Nick.NickValidator;
import it.chalmers.gamma.app.user.domain.UnencryptedPassword.UnencryptedPasswordValidator;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -26,9 +27,11 @@
public class HomeController {

private final MeFacade meFacade;
private final UserGdprTrainingFacade userGdprTrainingFacade;

public HomeController(MeFacade meFacade) {
public HomeController(MeFacade meFacade, UserGdprTrainingFacade userGdprTrainingFacade) {
this.meFacade = meFacade;
this.userGdprTrainingFacade = userGdprTrainingFacade;
}

@GetMapping("/")
Expand All @@ -47,6 +50,7 @@ public ModelAndView getMe(

mv.addObject("me", me);
mv.addObject("random", Math.random());
mv.addObject("gdpr", this.userGdprTrainingFacade.hasGdprTraining(me.id()));

return mv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
@Controller
public class UserAgreementController {

@GetMapping("/user-agreement")
public ModelAndView getUserAgreement(@RequestHeader(value = "HX-Request", required = false) boolean htmxRequest) {
ModelAndView mv = new ModelAndView();
if (htmxRequest) {
mv.setViewName("user-agreement/page");
} else {
mv.setViewName("index");
mv.addObject("page", "user-agreement/page");
}

return mv;
@GetMapping("/user-agreement")
public ModelAndView getUserAgreement(
@RequestHeader(value = "HX-Request", required = false) boolean htmxRequest) {
ModelAndView mv = new ModelAndView();
if (htmxRequest) {
mv.setViewName("user-agreement/page");
} else {
mv.setViewName("index");
mv.addObject("page", "user-agreement/page");
}

return mv;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import it.chalmers.gamma.app.common.Email.EmailValidator;
import it.chalmers.gamma.app.user.UserCreationFacade;
import it.chalmers.gamma.app.user.UserFacade;
import it.chalmers.gamma.app.user.UserGdprTrainingFacade;
import it.chalmers.gamma.app.user.domain.AcceptanceYear.AcceptanceYearValidator;
import it.chalmers.gamma.app.user.domain.Cid.CidValidator;
import it.chalmers.gamma.app.user.domain.FirstName.FirstNameValidator;
Expand Down Expand Up @@ -33,14 +34,17 @@ public class UsersController {
private final UserFacade userFacade;
private final UserCreationFacade userCreationFacade;
private final UserResetPasswordFacade userResetPasswordFacade;
private final UserGdprTrainingFacade userGdprTrainingFacade;

public UsersController(
UserFacade userFacade,
UserCreationFacade userCreationFacade,
UserResetPasswordFacade userResetPasswordFacade) {
UserResetPasswordFacade userResetPasswordFacade,
UserGdprTrainingFacade userGdprTrainingFacade) {
this.userFacade = userFacade;
this.userCreationFacade = userCreationFacade;
this.userResetPasswordFacade = userResetPasswordFacade;
this.userGdprTrainingFacade = userGdprTrainingFacade;
}

@GetMapping("/users")
Expand Down Expand Up @@ -111,6 +115,7 @@ public ModelAndView getUser(

mv.addObject("email", u.user().email());
mv.addObject("locked", u.user().locked());
mv.addObject("gdpr", this.userGdprTrainingFacade.hasGdprTraining(u.user().id()));
} else {
Optional<UserFacade.UserWithGroupsDTO> user =
this.userFacade.getWithGroups(UUID.fromString(userId));
Expand Down Expand Up @@ -306,6 +311,7 @@ public ModelAndView editUser(
mv.addObject("acceptanceYear", form.acceptanceYear);
mv.addObject("email", form.email);
mv.addObject("locked", user.get().user().locked());
mv.addObject("gdpr", this.userGdprTrainingFacade.hasGdprTraining(user.get().user().id()));
mv.addObject("userId", userId);

return mv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public List<UserId> getAll() {
.map(gdprTrainedEntity -> new UserId(gdprTrainedEntity.getId()))
.toList();
}

@Override
public boolean getGdprTrainedStatus(UserId userId) {
return this.gdprTrainedJpaRepository.existsById(userId.value());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.chalmers.gamma.app.user;

import static it.chalmers.gamma.app.authentication.AccessGuard.isAdmin;
import static it.chalmers.gamma.app.authentication.AccessGuard.isMe;

import it.chalmers.gamma.app.Facade;
import it.chalmers.gamma.app.authentication.AccessGuard;
Expand Down Expand Up @@ -32,4 +33,11 @@ public void updateGdprTrainedStatus(UUID userId, boolean gdprTrained) {

this.gdprTrainedRepository.setGdprTrainedStatus(new UserId(userId), gdprTrained);
}

public boolean hasGdprTraining(UUID userId) {
UserId id = new UserId(userId);
this.accessGuard.requireEither(isAdmin(), isMe(id));

return this.gdprTrainedRepository.getGdprTrainedStatus(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface GdprTrainedRepository {
void setGdprTrainedStatus(UserId userId, boolean gdprTrained);

List<UserId> getAll();

boolean getGdprTrainedStatus(UserId userId);
}
4 changes: 3 additions & 1 deletion app/src/main/resources/templates/client-details/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
</li>
<li th:if="${client.restriction() != null && client.restriction().superGroups().size() > 0}">
<b>Super group restrictions:</b>
<span th:each="restrictionSuperGroup, stat : ${client.restriction().superGroups()}" th:text="${restrictionSuperGroup.prettyName() + (stat.count == client.restriction().superGroups().size() ? '' : ', ')}"></span>
<span th:each="restrictionSuperGroup, stat : ${client.restriction().superGroups()}">
<a th:href="|/super-groups/${restrictionSuperGroup.id()}|" th:text="${restrictionSuperGroup.prettyName() + (stat.count == client.restriction().superGroups().size() ? '' : ', ')}"></a>
</span>
</li>
<li th:if="${client.restriction() == null || client.restriction().superGroups().size() == 0}">
This client has no restrictions.
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/resources/templates/home/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<b>Preferred language:</b>
<span th:text="${me.language() == 'EN' ? 'English' : (me.language() == 'SV' ? 'Swedish' : '')}"></span>
</li>
<li>
<b>Have you attended GDPR training?</b>
<span th:text="${gdpr ? 'Yes' : 'No'}"></span>
</li>
<li th:if="${me.isAdmin()}">
<b>Is admin?</b>
<span>Yes</span>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/resources/templates/user-details/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<b>Email:</b>
<span th:text="${email}"></span>
</li>
<li th:if="${isAdmin}">
<b>Has GDPR training:</b>
<span th:text="${gdpr}"></span>
</li>
<li th:if="${isAdmin}">
<b>Is locked:</b>
<span th:text="${locked}"></span>
Expand Down

0 comments on commit 3e7acb2

Please sign in to comment.