Add the Teacher approval for reregister requests
This commit is contained in:
parent
25575fa4e0
commit
69fb4e881e
@ -176,6 +176,16 @@ public class RequestsController {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
//We look in the usercursus table if the student has already the previous year of a curriculum
|
||||
public boolean studentHasPrevYear(Curriculum curriculum, User user){
|
||||
ArrayList<UserCurriculum> userCurrList = userCurriculumRepository.findByUserOrderByCurriculum(user);
|
||||
for (int i = 0; i < userCurrList.size(); i++){
|
||||
if (userCurrList.get(i).getCurriculum().getOption().equals(curriculum.getOption()) && userCurrList.get(i).getCurriculum().getYear() == curriculum.getYear()-1){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@PostMapping("/changecurriculumreq")
|
||||
public ResponseEntity<String> addChangeCurrReq(@RequestBody Map<String,Object> reqInfos){
|
||||
User user = userRepository.findById((Integer) reqInfos.get("userId"));
|
||||
@ -191,8 +201,12 @@ public class RequestsController {
|
||||
|
||||
Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus"));
|
||||
|
||||
ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending);
|
||||
ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending, RequestState.Unrequired);
|
||||
|
||||
//Si l'année du cursus est plus grande que 1 et que l'étudiant n'a pas dans sa liste de cursus l'année d'en dessous alors on demande l'accord du prof
|
||||
if (destinationCurriculum.getYear() > 1 && !studentHasPrevYear(destinationCurriculum, user)){
|
||||
changeCurriculumRequest.setTeacherApprovalState(RequestState.Pending);
|
||||
}
|
||||
changeCurriculumRequestRepository.save(changeCurriculumRequest);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
@ -228,27 +242,49 @@ public class RequestsController {
|
||||
|
||||
toEdit.setState(newState);
|
||||
|
||||
if (newState == RequestState.Accepted){
|
||||
if (newState == RequestState.Accepted && (toEdit.getTeacherApprovalState() == RequestState.Accepted || toEdit.getTeacherApprovalState() == RequestState.Unrequired)){
|
||||
//If actual curriculum is not null then we need to set that the user doesn't follow it anymore
|
||||
User u = toEdit.getUser();
|
||||
if (toEdit.getActualCurriculum() != null){
|
||||
ArrayList<UserCurriculum> listcurr = userCurriculumRepository.findByUserOrderByCurriculum(u);
|
||||
|
||||
for (int i = 0; i < listcurr.size(); i++){
|
||||
if (listcurr.get(i).getCurriculum() == toEdit.getActualCurriculum()){
|
||||
listcurr.get(i).setActual(false);
|
||||
}
|
||||
}
|
||||
|
||||
userCurriculumRepository.saveAll(listcurr);
|
||||
}
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
UserCurriculum userCurriculum = new UserCurriculum(u, toEdit.getDestinationCurriculum(), c.get(Calendar.YEAR), true);
|
||||
userCurriculumRepository.save(userCurriculum);
|
||||
acceptProcedure(toEdit);
|
||||
}
|
||||
|
||||
changeCurriculumRequestRepository.save(toEdit);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/changecurriculumreqteacher/{id}/{newteacherstate}")
|
||||
public ResponseEntity<String> editCCReqTeacherState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newteacherstate){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id);
|
||||
|
||||
toEdit.setState(newteacherstate);
|
||||
|
||||
if (newteacherstate == RequestState.Accepted && toEdit.getState() == RequestState.Accepted){
|
||||
//If actual curriculum is not null then we need to set that the user doesn't follow it anymore
|
||||
acceptProcedure(toEdit);
|
||||
}
|
||||
|
||||
changeCurriculumRequestRepository.save(toEdit);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
private void acceptProcedure(ChangeCurriculumRequest toEdit) {
|
||||
User u = toEdit.getUser();
|
||||
if (toEdit.getActualCurriculum() != null){
|
||||
ArrayList<UserCurriculum> listcurr = userCurriculumRepository.findByUserOrderByCurriculum(u);
|
||||
|
||||
for (int i = 0; i < listcurr.size(); i++){
|
||||
if (listcurr.get(i).getCurriculum() == toEdit.getActualCurriculum()){
|
||||
listcurr.get(i).setActual(false);
|
||||
}
|
||||
}
|
||||
|
||||
userCurriculumRepository.saveAll(listcurr);
|
||||
}
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
UserCurriculum userCurriculum = new UserCurriculum(u, toEdit.getDestinationCurriculum(), c.get(Calendar.YEAR), true);
|
||||
userCurriculumRepository.save(userCurriculum);
|
||||
}
|
||||
}
|
||||
|
@ -26,14 +26,16 @@ public class ChangeCurriculumRequest {
|
||||
|
||||
private RequestState state;
|
||||
|
||||
private RequestState teacherApprovalState;
|
||||
public ChangeCurriculumRequest(){}
|
||||
|
||||
public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state){
|
||||
public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state, RequestState teacherApprovalState){
|
||||
this.user = user;
|
||||
this.actualCurriculum = actualCurriculum;
|
||||
this.destinationCurriculum = destinationCurriculum;
|
||||
this.date = date;
|
||||
this.state = state;
|
||||
this.teacherApprovalState = teacherApprovalState;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
@ -80,4 +82,14 @@ public class ChangeCurriculumRequest {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RequestState getTeacherApprovalState() {
|
||||
return teacherApprovalState;
|
||||
}
|
||||
|
||||
public void setTeacherApprovalState(RequestState teacherApprovalState) {
|
||||
this.teacherApprovalState = teacherApprovalState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,81 +0,0 @@
|
||||
package ovh.herisson.Clyde.Tables.Inscription;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
@Entity
|
||||
public class ReInscriptionRequest {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "Users")
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private User user;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "Curriculum")
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private Curriculum newCurriculum;
|
||||
private RequestState state;
|
||||
|
||||
//Permet de différencier les demandes de changement et une réinscription dans le même Curriculum
|
||||
//Pour la réinscription on va le mettre a 0
|
||||
private boolean type = false;
|
||||
|
||||
public ReInscriptionRequest(){}
|
||||
|
||||
public ReInscriptionRequest(User user, Curriculum newCurriculum, RequestState state, boolean type){
|
||||
this.user = user;
|
||||
this.newCurriculum = newCurriculum;
|
||||
this.state = state;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ReInscriptionRequest(User user, Curriculum newCurriculum, RequestState state){
|
||||
this.user = user;
|
||||
this.newCurriculum = newCurriculum;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Curriculum getNewCurriculum() {
|
||||
return newCurriculum;
|
||||
}
|
||||
|
||||
public void setNewCurriculum(Curriculum newCurriculum) {
|
||||
this.newCurriculum = newCurriculum;
|
||||
}
|
||||
|
||||
public RequestState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(RequestState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public boolean isType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(boolean type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
<script setup>
|
||||
|
||||
import {
|
||||
addUninscReq, editChangeCurrReq,
|
||||
addUninscReq, editChangeCurrReq, editChangeCurrReqTeacherState,
|
||||
editScholarshipReq,
|
||||
editUnregReq, getChangeCurrReqById,
|
||||
getScholarshipReqById,
|
||||
getUnregisterbyId
|
||||
} from "@/rest/requests.js";
|
||||
import i18n from "@/i18n.js";
|
||||
import {getUser} from "@/rest/Users.js";
|
||||
import {getSelf, getUser} from "@/rest/Users.js";
|
||||
import {reactive, ref} from "vue";
|
||||
import AboutStudent from "@/Apps/Inscription/AboutStudent.vue";
|
||||
|
||||
const props = defineProps(["reqId"])
|
||||
const req = ref(await getChangeCurrReqById(props.reqId))
|
||||
|
||||
|
||||
const user = await getSelf()
|
||||
//0 liste, 1 profil
|
||||
const windowstate = ref(0);
|
||||
|
||||
@ -24,6 +24,10 @@ const tag = req.value.user.regNo
|
||||
async function uploadandrefreshChangeRequest(state){
|
||||
await editChangeCurrReq(req.value.id, state);
|
||||
}
|
||||
|
||||
async function editChangeCurrReqTeacherApproval(state){
|
||||
await editChangeCurrReqTeacherState(req.value.id, state)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@ -52,6 +56,10 @@ async function uploadandrefreshChangeRequest(state){
|
||||
<button v-if="req.state === 'Pending'" @click="req.state='Accepted';uploadandrefreshChangeRequest('Accepted')">Accept</button>
|
||||
<button v-if="req.state === 'Pending'" @click="req.state='Refused';uploadandrefreshChangeRequest('Refused')" style="margin-left: 2%;">Refuse</button>
|
||||
</div>
|
||||
<div v-if="user.role === 'Teacher' || user.role === 'Admin'">
|
||||
<button v-if="req.teacherApprovalState === 'Pending'" @click="req.teacherApprovalState='Accepted';editChangeCurrReqTeacherApproval('Accepted')">Accept equivalence</button>
|
||||
<button v-if="req.teacherApprovalState === 'Pending'" @click="req.teacherApprovalState='Refused';editChangeCurrReqTeacherApproval('Refused')">Refuse equivalence</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -114,11 +114,12 @@
|
||||
<div class="reqState">{{item.state}}</div>
|
||||
<div class="infos"><button @click="windowsState=4;targetId=item.id">More infos</button></div>
|
||||
</div>
|
||||
<div class="container" v-if="requestType === 'curriculum change'" style="grid-template-columns:17% 15% 12% 15%;grid-template-areas:'date reqState regno studentfirstname studentlastname infos';">
|
||||
<div class="container" v-if="requestType === 'curriculum change'" style="grid-template-columns:17% 20% 15% 5%;grid-template-areas:'date reqState teacherApproval regno studentfirstname studentlastname infos';">
|
||||
<div class="date" v-if="item.date != undefined">{{item.date.slice(0,10)}}</div>
|
||||
<div class="studentfirstname">{{item.user.firstName}}</div>
|
||||
<div class="studentlastname">{{item.user.lastName}}</div>
|
||||
<div class="reqState">{{item.state}}</div>
|
||||
<div class="reqState">IS approval : {{item.state}}</div>
|
||||
<div class="teacherApproval">Teacher approval : {{item.teacherApprovalState}}</div>
|
||||
<div class="infos"><button @click="windowsState=5;targetId=item.id">More infos</button></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -156,6 +157,11 @@
|
||||
grid-area: equivalencestate;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.teacherApproval{
|
||||
grid-area: teacherApproval;
|
||||
align-self: center;
|
||||
}
|
||||
.studentfirstname{
|
||||
grid-area: studentfirstname;
|
||||
align-self: center;
|
||||
|
@ -375,7 +375,7 @@
|
||||
The cursus you selected has some prerequisites
|
||||
</div>
|
||||
<div>
|
||||
<button @click=" windowState = 0;postChangeCurrReq(changecurrdata);changecurrdata.actualcursus=null;changecurrdata.newcursus=null">{{i18n("courses.confirm")}}</button>
|
||||
<button @click=" windowState = 0;postChangeCurrReq(changecurrdata);changecurrdata.actualcursus=null;changecurrdata.newcursus=1">{{i18n("courses.confirm")}}</button>
|
||||
<button @click="windowState = 0; resetInputs(personnalInfos,patternInfos);" style="float:right;">{{i18n("courses.back")}}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -62,4 +62,8 @@ export async function getChangeCurrReqById(id){
|
||||
|
||||
export async function editChangeCurrReq(id, newState){
|
||||
return restPatch("/changecurriculumreq/"+id+"/"+newState)
|
||||
}
|
||||
|
||||
export async function editChangeCurrReqTeacherState(id, newState){
|
||||
return restPatch("/changecurriculumreqteacher/"+id+"/"+newState)
|
||||
}
|
Loading…
Reference in New Issue
Block a user