role corrections
This commit is contained in:
parent
93a1289629
commit
c4f81c425b
@ -18,7 +18,7 @@ apply plugin: 'war'
|
||||
apply plugin: 'application'
|
||||
|
||||
group = 'de.jottyfan.camporganizer'
|
||||
version = '0.4.0'
|
||||
version = '0.4.1'
|
||||
sourceCompatibility = 17
|
||||
mainClassName = "de.jottyfan.camporganizer.Main"
|
||||
|
||||
|
@ -0,0 +1,80 @@
|
||||
package de.jottyfan.camporganizer.db;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class EnumConverter {
|
||||
|
||||
/**
|
||||
* get the German names of the camprole
|
||||
*
|
||||
* @param role the role
|
||||
* @return the German names
|
||||
*/
|
||||
public static final String role2GermanNames(EnumCamprole role) {
|
||||
if (EnumCamprole.student.equals(role)) {
|
||||
return "Teilnehmer";
|
||||
} else if (EnumCamprole.director.equals(role)) {
|
||||
return "Leitungsteam";
|
||||
} else if (EnumCamprole.feeder.equals(role)) {
|
||||
return "Küchenteam";
|
||||
} else if (EnumCamprole.teacher.equals(role)) {
|
||||
return "Mitarbeiter";
|
||||
} else if (EnumCamprole.observer.equals(role)) {
|
||||
return "Mitarbeiterkind";
|
||||
} else {
|
||||
return role == null ? null : role.getLiteral();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the German names of the sex
|
||||
*
|
||||
* @param sex the sex
|
||||
* @return the German names
|
||||
*/
|
||||
public static final String sex2GermanNames(EnumSex sex) {
|
||||
if (EnumSex.female.equals(sex)) {
|
||||
return "weiblich";
|
||||
} else if (EnumSex.male.equals(sex)) {
|
||||
return "männlich";
|
||||
} else {
|
||||
return sex == null ? null : sex.getLiteral();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the enum values in a list of German translations
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
public static final List<KeyValueBean> getSexes() {
|
||||
List<KeyValueBean> list = new ArrayList<>();
|
||||
list.add(new KeyValueBean().of(EnumSex.female.getLiteral(), "weiblich"));
|
||||
list.add(new KeyValueBean().of(EnumSex.male.getLiteral(), "männlich"));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all the enum values in a list of German translations
|
||||
*
|
||||
* @return the list
|
||||
*/
|
||||
public static final List<KeyValueBean> getRoles() {
|
||||
List<KeyValueBean> list = new ArrayList<>();
|
||||
list.add(new KeyValueBean().of(EnumCamprole.director.getLiteral(), "Leitungsteam"));
|
||||
list.add(new KeyValueBean().of(EnumCamprole.feeder.getLiteral(), "Küchenteam"));
|
||||
list.add(new KeyValueBean().of(EnumCamprole.teacher.getLiteral(), "Mitarbeiter"));
|
||||
list.add(new KeyValueBean().of(EnumCamprole.student.getLiteral(), "Teilnehmer"));
|
||||
list.add(new KeyValueBean().of(EnumCamprole.observer.getLiteral(), "Mitarbeiterkind"));
|
||||
return list;
|
||||
}
|
||||
}
|
57
src/main/java/de/jottyfan/camporganizer/db/KeyValueBean.java
Normal file
57
src/main/java/de/jottyfan/camporganizer/db/KeyValueBean.java
Normal file
@ -0,0 +1,57 @@
|
||||
package de.jottyfan.camporganizer.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class KeyValueBean implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* create a new bean from the arguments
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return the bean
|
||||
*/
|
||||
public KeyValueBean of(String key, String value) {
|
||||
KeyValueBean bean = new KeyValueBean();
|
||||
bean.setKey(key);
|
||||
bean.setValue(value);
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the key
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key the key to set
|
||||
*/
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import de.jottyfan.camporganizer.db.EnumConverter;
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
|
||||
import de.jottyfan.camporganizer.db.jooq.tables.records.TPersonRecord;
|
||||
@ -70,8 +71,8 @@ public class BookingsRepository {
|
||||
BookerBean bean = new BookerBean();
|
||||
bean.setPk(r.get(T_PERSON.PK));
|
||||
bean.setName(String.format("%s %s", forename, surname));
|
||||
bean.setRole(EnumCamprole.student.equals(role) ? "Teilnehmer" : "Mitarbeiter");
|
||||
bean.setSex(EnumSex.female.equals(sex) ? "weiblich" : "männlich");
|
||||
bean.setRole(EnumConverter.role2GermanNames(role));
|
||||
bean.setSex(EnumConverter.sex2GermanNames(sex));
|
||||
bean.setBookingDate(r.get(T_PERSON.CREATED));
|
||||
bean.setAccept(r.get(T_PERSON.ACCEPT));
|
||||
bean.setPaid(r.get(T_PERSON.PAID));
|
||||
@ -127,8 +128,8 @@ public class BookingsRepository {
|
||||
BookerBean bean = new BookerBean();
|
||||
bean.setPk(r.get(T_PERSON.PK));
|
||||
bean.setName(String.format("%s %s", forename, surname));
|
||||
bean.setRole(EnumCamprole.student.equals(role) ? "Teilnehmer" : "Mitarbeiter");
|
||||
bean.setSex(EnumSex.female.equals(sex) ? "weiblich" : "männlich");
|
||||
bean.setRole(EnumConverter.role2GermanNames(role));
|
||||
bean.setSex(EnumConverter.sex2GermanNames(sex));
|
||||
bean.setBookingDate(r.get(T_PERSON.CREATED));
|
||||
bean.setAccept(r.get(T_PERSON.ACCEPT));
|
||||
bean.setPaid(r.get(T_PERSON.PAID));
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import de.jottyfan.camporganizer.db.EnumConverter;
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumSex;
|
||||
|
||||
@ -98,8 +99,8 @@ public class CampRepository {
|
||||
PersonBean bean = new PersonBean();
|
||||
bean.setPk(r.get(T_PERSON.PK));
|
||||
bean.setName(String.format("%s %s", forename, surname));
|
||||
bean.setRole(EnumCamprole.student.equals(role) ? "Teilnehmer" : "Mitarbeiter");
|
||||
bean.setSex(EnumSex.female.equals(sex) ? "weiblich" : "männlich");
|
||||
bean.setRole(EnumConverter.role2GermanNames(role));
|
||||
bean.setSex(EnumConverter.sex2GermanNames(sex));
|
||||
bean.setBookingDate(r.get(T_PERSON.CREATED));
|
||||
bean.setAccept(r.get(T_PERSON.ACCEPT));
|
||||
bean.setPaid(r.get(T_PERSON.PAID));
|
||||
|
@ -1,45 +0,0 @@
|
||||
package de.jottyfan.camporganizer.module.business.privileges;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.jottyfan.camporganizer.module.business.camp.impl.CampBean;
|
||||
import de.jottyfan.camporganizer.module.business.privileges.impl.PrivilegesBean;
|
||||
import de.jottyfan.camporganizer.module.business.privileges.impl.ProfileBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public interface IPrivilegesService {
|
||||
|
||||
/**
|
||||
* get all current privileges for the sales
|
||||
*
|
||||
* @return the privileges for sales
|
||||
*/
|
||||
public Map<Integer, CampBean> getPrivileges();
|
||||
|
||||
/**
|
||||
* get all profiles
|
||||
*
|
||||
* @return the profiles
|
||||
*/
|
||||
public List<ProfileBean> getProfiles();
|
||||
|
||||
/**
|
||||
* add a privilege
|
||||
*
|
||||
* @param bean the bean
|
||||
*/
|
||||
public void add(PrivilegesBean bean);
|
||||
|
||||
/**
|
||||
* remove a privilege
|
||||
*
|
||||
* @param bean the bean
|
||||
* @param currentUser the current user in this sessionö
|
||||
*/
|
||||
public void remove(PrivilegesBean bean, String currentUser);
|
||||
}
|
@ -11,8 +11,10 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
|
||||
import de.jottyfan.camporganizer.module.business.business.IBusinessService;
|
||||
import de.jottyfan.camporganizer.module.business.privileges.impl.PrivilegesBean;
|
||||
import de.jottyfan.camporganizer.module.business.privileges.impl.PrivilegesService;
|
||||
import de.jottyfan.camporganizer.module.camplist.CommonController;
|
||||
|
||||
/**
|
||||
@ -27,7 +29,7 @@ public class PrivilegesController extends CommonController {
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private IPrivilegesService privilegesService;
|
||||
private PrivilegesService privilegesService;
|
||||
|
||||
@Autowired
|
||||
private IBusinessService indexService;
|
||||
@ -38,7 +40,7 @@ public class PrivilegesController extends CommonController {
|
||||
String username = indexService.getCurrentUser(request);
|
||||
model.addAttribute("currentUser", username);
|
||||
model.addAttribute("privileges", privilegesService.getPrivileges());
|
||||
model.addAttribute("profiles", privilegesService.getProfiles());
|
||||
model.addAttribute("profiles", privilegesService.getProfiles(EnumCamprole.director, EnumCamprole.teacher));
|
||||
model.addAttribute("bean", new PrivilegesBean());
|
||||
return "business/privileges";
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.jottyfan.camporganizer.module.business.privileges.impl;
|
||||
|
||||
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PERSON;
|
||||
import static de.jottyfan.camporganizer.db.jooq.Tables.T_PROFILE;
|
||||
import static de.jottyfan.camporganizer.db.jooq.Tables.T_SALESPROFILE;
|
||||
import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
|
||||
@ -7,6 +8,7 @@ import static de.jottyfan.camporganizer.db.jooq.Tables.V_CAMP;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -16,6 +18,7 @@ import org.jooq.InsertReturningStep;
|
||||
import org.jooq.Record5;
|
||||
import org.jooq.Record8;
|
||||
import org.jooq.SelectSeekStep3;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -61,11 +64,17 @@ public class PrivilegesRepository {
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<ProfileBean> getProfiles() {
|
||||
public List<ProfileBean> getProfiles(Set<String> allowed) {
|
||||
SelectSeekStep3<Record5<Integer, String, String, LocalDateTime, String>, String, String, LocalDateTime> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_PROFILE.PK, T_PROFILE.FORENAME, T_PROFILE.SURNAME, T_PROFILE.DUEDATE, T_PROFILE.USERNAME)
|
||||
.select(T_PROFILE.PK,
|
||||
T_PROFILE.FORENAME,
|
||||
T_PROFILE.SURNAME,
|
||||
T_PROFILE.DUEDATE,
|
||||
T_PROFILE.USERNAME)
|
||||
.from(T_PROFILE)
|
||||
.leftJoin(T_PERSON).on(T_PERSON.FK_PROFILE.eq(T_PROFILE.PK))
|
||||
.where((allowed == null || allowed.size() < 1) ? DSL.trueCondition() : T_PERSON.CAMPROLE.in(allowed))
|
||||
.orderBy(T_PROFILE.SURNAME, T_PROFILE.FORENAME, T_PROFILE.DUEDATE);
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
|
@ -1,14 +1,16 @@
|
||||
package de.jottyfan.camporganizer.module.business.privileges.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import de.jottyfan.camporganizer.db.jooq.enums.EnumCamprole;
|
||||
import de.jottyfan.camporganizer.module.business.camp.impl.CampBean;
|
||||
import de.jottyfan.camporganizer.module.business.privileges.IPrivilegesService;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,11 +18,10 @@ import de.jottyfan.camporganizer.module.business.privileges.IPrivilegesService;
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class PrivilegesService implements IPrivilegesService {
|
||||
public class PrivilegesService {
|
||||
@Autowired
|
||||
private PrivilegesRepository gateway;
|
||||
|
||||
@Override
|
||||
public Map<Integer, CampBean> getPrivileges() {
|
||||
List<PrivilegesBean> list = gateway.getPrivileges();
|
||||
Map<Integer, CampBean> camps = new HashMap<>();
|
||||
@ -44,17 +45,18 @@ public class PrivilegesService implements IPrivilegesService {
|
||||
return camps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfileBean> getProfiles() {
|
||||
return gateway.getProfiles();
|
||||
public List<ProfileBean> getProfiles(EnumCamprole... allowed) {
|
||||
Set<String> set = new HashSet<>();
|
||||
for (EnumCamprole role : allowed) {
|
||||
set.add(role.getLiteral());
|
||||
}
|
||||
return gateway.getProfiles(allowed == null ? null : set);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(PrivilegesBean bean) {
|
||||
gateway.add(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(PrivilegesBean bean, String currentUser) {
|
||||
gateway.remove(bean, currentUser);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package de.jottyfan.camporganizer.module.business.privileges.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,6 +22,21 @@ public class ProfileBean implements Serializable {
|
||||
return new StringBuilder().append(forename).append(" ").append(surname).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* dropdown representation
|
||||
*
|
||||
* @return the dropdown string
|
||||
*/
|
||||
public String dropdown() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(forename).append(" ");
|
||||
buf.append(surname).append(" (");
|
||||
buf.append(username).append(", ");
|
||||
buf.append(duedate == null ? "" : duedate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")));
|
||||
buf.append(")");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import de.jottyfan.camporganizer.db.EnumConverter;
|
||||
import de.jottyfan.camporganizer.module.camplist.CommonController;
|
||||
|
||||
/**
|
||||
@ -33,6 +34,8 @@ public class RegistrationController extends CommonController {
|
||||
bean.setFkCamp(fkCamp);
|
||||
bean.setRegisterInKeycloak(true); // we want people to register generally
|
||||
model.addAttribute("bean", bean);
|
||||
model.addAttribute("sexes", EnumConverter.getSexes());
|
||||
model.addAttribute("roles", EnumConverter.getRoles());
|
||||
return "/registration/registration";
|
||||
} else {
|
||||
return "/registration/isover";
|
||||
@ -45,6 +48,8 @@ public class RegistrationController extends CommonController {
|
||||
if (bindingResult.hasErrors()) {
|
||||
CampBean campBean = service.getCamp(bean.getFkCamp());
|
||||
model.addAttribute("camp", campBean);
|
||||
model.addAttribute("sexes", EnumConverter.getSexes());
|
||||
model.addAttribute("roles", EnumConverter.getRoles());
|
||||
return "/registration/registration";
|
||||
}
|
||||
Boolean result = service.register(bean, (String) model.getAttribute("currentUser"));
|
||||
|
@ -30,8 +30,7 @@
|
||||
<span class="error" th:each="error : ${#fields.errors('sex')}">[[${error}]]<br /></span>
|
||||
<select th:field="*{sex}" th:class="${'form-select ' + (#fields.hasErrors('sex') ? 'inputerror' : '')}">
|
||||
<option value="">Geschlecht</option>
|
||||
<option value="female">weiblich</option>
|
||||
<option value="male">männlich</option>
|
||||
<option th:each="o : ${sexes}" th:value="${o.key}" th:text="${o.value}"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-6 rowdist">
|
||||
@ -70,11 +69,7 @@
|
||||
<div class="col-sm-6 rowdist">
|
||||
<span class="error" th:each="error : ${#fields.errors('campRole')}">[[${error}]]<br /></span>
|
||||
<select th:field="*{campRole}" th:class="${'form-select' + (#fields.hasErrors('campRole') ? 'inputerror' : '')}">
|
||||
<option value="student">Teilnehmer</option>
|
||||
<option value="teacher">Mitarbeiter</option>
|
||||
<option value="feeder">Küchenteam</option>
|
||||
<option value="director">Leiter</option>
|
||||
<option value="observer">Mitarbeiterkind</option>
|
||||
<option th:each="o : ${roles}" th:value="${o.key}" th:text="${o.value}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user