update permissionmappings
This commit is contained in:
parent
bfc335703c
commit
aa79839a00
@ -42,7 +42,7 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
* Gets the.
|
* Gets the.
|
||||||
*
|
*
|
||||||
* @param target the target
|
* @param target the target
|
||||||
* @param name the name
|
* @param name the name
|
||||||
* @return the list
|
* @return the list
|
||||||
*/
|
*/
|
||||||
public List<Permission> get(Long target, String name) {
|
public List<Permission> get(Long target, String name) {
|
||||||
@ -126,7 +126,7 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
* Checks for permission.
|
* Checks for permission.
|
||||||
*
|
*
|
||||||
* @param target the target
|
* @param target the target
|
||||||
* @param name the name
|
* @param name the name
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(Long target, String name) {
|
public boolean hasPermission(Long target, String name) {
|
||||||
@ -143,10 +143,10 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
/**
|
/**
|
||||||
* Creates the.
|
* Creates the.
|
||||||
*
|
*
|
||||||
* @param target the target
|
* @param target the target
|
||||||
* @param name the name
|
* @param name the name
|
||||||
* @param addon the addon
|
* @param addon the addon
|
||||||
* @param starts the starts
|
* @param starts the starts
|
||||||
* @param expires the expires
|
* @param expires the expires
|
||||||
* @return the permission
|
* @return the permission
|
||||||
*/
|
*/
|
||||||
@ -188,7 +188,7 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
/**
|
/**
|
||||||
* Clone.
|
* Clone.
|
||||||
*
|
*
|
||||||
* @param name the name
|
* @param name the name
|
||||||
* @param clone the clone
|
* @param clone the clone
|
||||||
* @return the list
|
* @return the list
|
||||||
*/
|
*/
|
||||||
@ -212,7 +212,7 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
* Delete.
|
* Delete.
|
||||||
*
|
*
|
||||||
* @param target the target
|
* @param target the target
|
||||||
* @param name the name
|
* @param name the name
|
||||||
*/
|
*/
|
||||||
public void delete(Long target, String name) {
|
public void delete(Long target, String name) {
|
||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
@ -249,10 +249,10 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
/**
|
/**
|
||||||
* Apply item.
|
* Apply item.
|
||||||
*
|
*
|
||||||
* @param target the target
|
* @param target the target
|
||||||
* @param item the item
|
* @param item the item
|
||||||
* @param answers the answers
|
* @param answers the answers
|
||||||
* @param starts the starts
|
* @param starts the starts
|
||||||
* @param expires the expires
|
* @param expires the expires
|
||||||
*/
|
*/
|
||||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
|
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||||
@ -265,10 +265,10 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
/**
|
/**
|
||||||
* Gets the for item.
|
* Gets the for item.
|
||||||
*
|
*
|
||||||
* @param target the target
|
* @param target the target
|
||||||
* @param item the item
|
* @param item the item
|
||||||
* @param answers the answers
|
* @param answers the answers
|
||||||
* @param starts the starts
|
* @param starts the starts
|
||||||
* @param expires the expires
|
* @param expires the expires
|
||||||
* @return the for item
|
* @return the for item
|
||||||
*/
|
*/
|
||||||
@ -280,6 +280,14 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
Instant permissionStarts = starts;
|
Instant permissionStarts = starts;
|
||||||
Instant permissionsExpires = expires;
|
Instant permissionsExpires = expires;
|
||||||
|
|
||||||
|
if (permissionMapping.getStarts() != null) {
|
||||||
|
permissionStarts = permissionMapping.getStarts();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permissionMapping.getExpires() != null) {
|
||||||
|
permissionsExpires = permissionMapping.getExpires();
|
||||||
|
}
|
||||||
|
|
||||||
if (permissionMapping.isLifetimeRound()) {
|
if (permissionMapping.isLifetimeRound()) {
|
||||||
permissionStarts = InstantHelper.truncate(permissionStarts,
|
permissionStarts = InstantHelper.truncate(permissionStarts,
|
||||||
permissionMapping.getLifetimeUnit());
|
permissionMapping.getLifetimeUnit());
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bstly.we.businesslogic;
|
package de.bstly.we.businesslogic;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -77,23 +78,26 @@ public class PermissionMappingManager {
|
|||||||
/**
|
/**
|
||||||
* Creates the.
|
* Creates the.
|
||||||
*
|
*
|
||||||
* @param item the item
|
* @param item the item
|
||||||
* @param names the names
|
* @param names the names
|
||||||
* @param lifetime the lifetime
|
* @param lifetime the lifetime
|
||||||
* @param lifetimeUnit the lifetime unit
|
* @param lifetimeUnit the lifetime unit
|
||||||
* @param lifetimeRound the lifetime round
|
* @param lifetimeRound the lifetime round
|
||||||
* @param addon the addon
|
* @param addon the addon
|
||||||
* @param product the product
|
* @param product the product
|
||||||
* @param startsQuestion the starts question
|
* @param startsQuestion the starts question
|
||||||
* @param expiresQuestion the expires question
|
* @param expiresQuestion the expires question
|
||||||
* @return the permission mapping
|
* @return the permission mapping
|
||||||
*/
|
*/
|
||||||
public PermissionMapping create(Integer item, Set<String> names, Long lifetime,
|
public PermissionMapping create(Integer item, Set<String> names, Long lifetime,
|
||||||
ChronoUnit lifetimeUnit, boolean lifetimeRound, boolean addon, String product,
|
ChronoUnit lifetimeUnit, boolean lifetimeRound, boolean addon, String product,
|
||||||
String startsQuestion, String expiresQuestion) {
|
Instant starts, Instant expires, String startsQuestion, String expiresQuestion) {
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
Assert.isTrue(!exists(item, name), "PermissionMapping for item '" + item
|
Assert.isTrue(!exists(item, name), "PermissionMapping for item '"
|
||||||
+ "' with permission '" + name + "' already exists!");
|
+ item
|
||||||
|
+ "' with permission '"
|
||||||
|
+ name
|
||||||
|
+ "' already exists!");
|
||||||
}
|
}
|
||||||
PermissionMapping permissionMapping = new PermissionMapping();
|
PermissionMapping permissionMapping = new PermissionMapping();
|
||||||
permissionMapping.setItem(item);
|
permissionMapping.setItem(item);
|
||||||
@ -103,6 +107,8 @@ public class PermissionMappingManager {
|
|||||||
permissionMapping.setLifetimeRound(lifetimeRound);
|
permissionMapping.setLifetimeRound(lifetimeRound);
|
||||||
permissionMapping.setAddon(addon);
|
permissionMapping.setAddon(addon);
|
||||||
permissionMapping.setProduct(product);
|
permissionMapping.setProduct(product);
|
||||||
|
permissionMapping.setStarts(starts);
|
||||||
|
permissionMapping.setExpires(expires);
|
||||||
permissionMapping.setStartsQuestion(startsQuestion);
|
permissionMapping.setStartsQuestion(startsQuestion);
|
||||||
permissionMapping.setExpiresQuestion(expiresQuestion);
|
permissionMapping.setExpiresQuestion(expiresQuestion);
|
||||||
return permissionMappingRepository.save(permissionMapping);
|
return permissionMappingRepository.save(permissionMapping);
|
||||||
@ -124,8 +130,9 @@ public class PermissionMappingManager {
|
|||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
Assert.isTrue(permissionMappingRepository.existsById(id),
|
Assert.isTrue(permissionMappingRepository.existsById(id), "Permission Mapping '"
|
||||||
"Permission Mapping '" + id + "' does not exists!");
|
+ id
|
||||||
|
+ "' does not exists!");
|
||||||
PermissionMapping permissionMapping = permissionMappingRepository.findById(id).get();
|
PermissionMapping permissionMapping = permissionMappingRepository.findById(id).get();
|
||||||
permissionMappingRepository.delete(permissionMapping);
|
permissionMappingRepository.delete(permissionMapping);
|
||||||
}
|
}
|
||||||
@ -133,9 +140,9 @@ public class PermissionMappingManager {
|
|||||||
/**
|
/**
|
||||||
* Gets the.
|
* Gets the.
|
||||||
*
|
*
|
||||||
* @param page the page
|
* @param page the page
|
||||||
* @param size the size
|
* @param size the size
|
||||||
* @param sortBy the sort by
|
* @param sortBy the sort by
|
||||||
* @param descending the descending
|
* @param descending the descending
|
||||||
* @return the page
|
* @return the page
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +52,8 @@ public class PermissionMappingController extends BaseController {
|
|||||||
public Page<PermissionMapping> getPermissionMappings(
|
public Page<PermissionMapping> getPermissionMappings(
|
||||||
@RequestParam("page") Optional<Integer> pageParameter,
|
@RequestParam("page") Optional<Integer> pageParameter,
|
||||||
@RequestParam("size") Optional<Integer> sizeParameter) {
|
@RequestParam("size") Optional<Integer> sizeParameter) {
|
||||||
return permissionMappingManager.get(pageParameter.orElse(0), sizeParameter.orElse(10), "item", true);
|
return permissionMappingManager.get(pageParameter.orElse(0), sizeParameter.orElse(10),
|
||||||
|
"item", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,6 +75,7 @@ public class PermissionMappingController extends BaseController {
|
|||||||
permissionMapping.getNames(), permissionMapping.getLifetime(),
|
permissionMapping.getNames(), permissionMapping.getLifetime(),
|
||||||
permissionMapping.getLifetimeUnit(), permissionMapping.isLifetimeRound(),
|
permissionMapping.getLifetimeUnit(), permissionMapping.isLifetimeRound(),
|
||||||
permissionMapping.isAddon(), permissionMapping.getProduct(),
|
permissionMapping.isAddon(), permissionMapping.getProduct(),
|
||||||
|
permissionMapping.getStarts(), permissionMapping.getExpires(),
|
||||||
permissionMapping.getStartsQuestion(), permissionMapping.getExpiresQuestion());
|
permissionMapping.getStartsQuestion(), permissionMapping.getExpiresQuestion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +101,7 @@ public class PermissionMappingController extends BaseController {
|
|||||||
permissionMapping.getNames(), permissionMapping.getLifetime(),
|
permissionMapping.getNames(), permissionMapping.getLifetime(),
|
||||||
permissionMapping.getLifetimeUnit(), permissionMapping.isLifetimeRound(),
|
permissionMapping.getLifetimeUnit(), permissionMapping.isLifetimeRound(),
|
||||||
permissionMapping.isAddon(), permissionMapping.getProduct(),
|
permissionMapping.isAddon(), permissionMapping.getProduct(),
|
||||||
|
permissionMapping.getStarts(), permissionMapping.getExpires(),
|
||||||
permissionMapping.getStartsQuestion(), permissionMapping.getExpiresQuestion()));
|
permissionMapping.getStartsQuestion(), permissionMapping.getExpiresQuestion()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.bstly.we.model;
|
package de.bstly.we.model;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -51,6 +52,10 @@ public class PermissionMapping {
|
|||||||
private ChronoUnit lifetimeUnit = DEFAULT_LIFETIME_UNIT;
|
private ChronoUnit lifetimeUnit = DEFAULT_LIFETIME_UNIT;
|
||||||
@Column(name = "lifetime_round", columnDefinition = "boolean default false")
|
@Column(name = "lifetime_round", columnDefinition = "boolean default false")
|
||||||
private boolean lifetimeRound;
|
private boolean lifetimeRound;
|
||||||
|
@Column(name = "starts")
|
||||||
|
private Instant starts;
|
||||||
|
@Column(name = "expires")
|
||||||
|
private Instant expires;
|
||||||
@Column(name = "starts_question")
|
@Column(name = "starts_question")
|
||||||
private String startsQuestion;
|
private String startsQuestion;
|
||||||
@Column(name = "expires_question")
|
@Column(name = "expires_question")
|
||||||
@ -200,6 +205,34 @@ public class PermissionMapping {
|
|||||||
this.lifetimeRound = lifetimeRound;
|
this.lifetimeRound = lifetimeRound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the starts
|
||||||
|
*/
|
||||||
|
public Instant getStarts() {
|
||||||
|
return starts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param starts the starts to set
|
||||||
|
*/
|
||||||
|
public void setStarts(Instant starts) {
|
||||||
|
this.starts = starts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the expires
|
||||||
|
*/
|
||||||
|
public Instant getExpires() {
|
||||||
|
return expires;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param expires the expires to set
|
||||||
|
*/
|
||||||
|
public void setExpires(Instant expires) {
|
||||||
|
this.expires = expires;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the starts question.
|
* Gets the starts question.
|
||||||
*
|
*
|
||||||
@ -243,7 +276,8 @@ public class PermissionMapping {
|
|||||||
public static class ChronoUnitConverter implements AttributeConverter<ChronoUnit, String> {
|
public static class ChronoUnitConverter implements AttributeConverter<ChronoUnit, String> {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object)
|
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.
|
||||||
|
* Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String convertToDatabaseColumn(ChronoUnit chronoUnit) {
|
public String convertToDatabaseColumn(ChronoUnit chronoUnit) {
|
||||||
@ -251,7 +285,8 @@ public class PermissionMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object)
|
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.
|
||||||
|
* Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ChronoUnit convertToEntityAttribute(String value) {
|
public ChronoUnit convertToEntityAttribute(String value) {
|
||||||
|
4
pom.xml
4
pom.xml
@ -12,8 +12,8 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
<log4j2.version>2.15.0</log4j2.version>
|
<log4j2.version>2.16.0</log4j2.version>
|
||||||
<revision>1.4.5-SNAPSHOT</revision>
|
<revision>1.4.6-SNAPSHOT</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
Loading…
Reference in New Issue
Block a user