-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/it/chalmers/gamma/adapter/primary/web/ClientApprovingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package it.chalmers.gamma.adapter.primary.web; | ||
|
||
import it.chalmers.gamma.app.client.domain.ClientUid; | ||
import it.chalmers.gamma.app.migration.ClientApproving; | ||
import it.chalmers.gamma.app.user.domain.UserId; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* This is only used as a part of migration from old gamma to new gamma. | ||
* We want to transfer the accepting of a client for certain project, | ||
* such as HubbIT and BookIT. | ||
*/ | ||
@Controller | ||
public class ClientApprovingController { | ||
|
||
private final ClientApproving clientApproving; | ||
|
||
public ClientApprovingController(ClientApproving clientApproving) { | ||
this.clientApproving = clientApproving; | ||
} | ||
|
||
public record ClientApprovingForm(String clientUid, String userIds) { } | ||
|
||
@GetMapping("/client-approving") | ||
public ModelAndView getClientApproving(@RequestHeader(value = "HX-Request", required = false) boolean htmxRequest) { | ||
ModelAndView mv = new ModelAndView(); | ||
if (htmxRequest) { | ||
mv.setViewName("pages/client-approving"); | ||
} else { | ||
mv.setViewName("index"); | ||
mv.addObject("page", "pages/client-approving"); | ||
} | ||
|
||
mv.addObject("form", new ClientApprovingForm("", "")); | ||
|
||
return mv; | ||
} | ||
|
||
@PostMapping("/client-approving") | ||
public ModelAndView massApproveClient(ClientApprovingForm form) { | ||
List<UserId> userIds = Arrays.stream(form.userIds.split(",")).map(UserId::valueOf).toList(); | ||
|
||
clientApproving.approve(ClientUid.valueOf(form.clientUid), userIds); | ||
|
||
return new ModelAndView("redirect:/clients/" + form.clientUid); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/it/chalmers/gamma/app/migration/ClientApproving.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package it.chalmers.gamma.app.migration; | ||
|
||
import it.chalmers.gamma.app.authentication.AccessGuard; | ||
import it.chalmers.gamma.app.client.domain.ClientRepository; | ||
import it.chalmers.gamma.app.client.domain.ClientUid; | ||
import it.chalmers.gamma.app.user.domain.UserId; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
import static it.chalmers.gamma.app.authentication.AccessGuard.isAdmin; | ||
|
||
@Service | ||
public class ClientApproving { | ||
|
||
private final AccessGuard accessGuard; | ||
private final ClientRepository clientRepository; | ||
|
||
public ClientApproving(AccessGuard accessGuard, ClientRepository clientRepository) { | ||
this.accessGuard = accessGuard; | ||
this.clientRepository = clientRepository; | ||
} | ||
|
||
public void approve(ClientUid clientUid, List<UserId> userIds) { | ||
accessGuard.require(isAdmin()); | ||
|
||
for (UserId userId : userIds) { | ||
try { | ||
clientRepository.addClientApproval(userId, clientUid); | ||
} catch(Exception e) { | ||
//ignore... | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/resources/templates/pages/client-approving.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<header th:replace="~{common/header-without-nav}"></header> | ||
<main> | ||
<article> | ||
<header> | ||
Used to mass approve users to a client | ||
</header> | ||
<p> | ||
Use with care, just use this when you know that the user already has accepted the client before. | ||
</p> | ||
<p> | ||
Used for migration purposes. | ||
</p> | ||
<form id="client-approving" th:object="${form}" th:method="post" th:action="@{/client-approving}"> | ||
<div th:replace="~{common/input :: textInput2(field='clientUid', label='Client UID')}"></div> | ||
<div th:replace="~{common/input :: textInput2(field='userIds', label='User Ids (comma seperated)')}"></div> | ||
</form> | ||
<footer> | ||
<button form="client-approving"> | ||
Mass approve | ||
</button> | ||
</footer> | ||
</article> | ||
</main> |