update borrow module + fix invite
This commit is contained in:
parent
3c98987678
commit
0646a21d97
@ -23,9 +23,11 @@ import de.bstly.we.borrow.model.BorrowItemSlot;
|
||||
import de.bstly.we.borrow.model.QBorrowItem;
|
||||
import de.bstly.we.borrow.model.QBorrowItemManualSlot;
|
||||
import de.bstly.we.borrow.model.QBorrowItemPeriodSlot;
|
||||
import de.bstly.we.borrow.model.QBorrowRequest;
|
||||
import de.bstly.we.borrow.repository.BorrowItemManualSlotRepository;
|
||||
import de.bstly.we.borrow.repository.BorrowItemPeriodSlotRepository;
|
||||
import de.bstly.we.borrow.repository.BorrowItemRepository;
|
||||
import de.bstly.we.borrow.repository.BorrowRequestRepository;
|
||||
import de.bstly.we.businesslogic.UserManager;
|
||||
import de.bstly.we.email.businesslogic.EmailManager;
|
||||
import de.bstly.we.model.User;
|
||||
@ -43,6 +45,8 @@ public class BorrowItemManager {
|
||||
@Autowired
|
||||
private BorrowItemPeriodSlotRepository borrowItemPeriodSlotRepository;
|
||||
@Autowired
|
||||
private BorrowRequestRepository borrowRequestRepository;
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
@Autowired
|
||||
private EmailManager emailManager;
|
||||
@ -50,6 +54,7 @@ public class BorrowItemManager {
|
||||
private QBorrowItem qBorrowItem = QBorrowItem.borrowItem;
|
||||
private QBorrowItemManualSlot qBorrowItemManualSlot = QBorrowItemManualSlot.borrowItemManualSlot;
|
||||
private QBorrowItemPeriodSlot qBorrowItemPeriodSlot = QBorrowItemPeriodSlot.borrowItemPeriodSlot;
|
||||
private QBorrowRequest qBorrowRequest = QBorrowRequest.borrowRequest;
|
||||
|
||||
/**
|
||||
* Exists.
|
||||
@ -207,6 +212,8 @@ public class BorrowItemManager {
|
||||
.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
||||
borrowItemPeriodSlotRepository.deleteAll(borrowItemPeriodSlotRepository
|
||||
.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
||||
borrowRequestRepository.deleteAll(
|
||||
borrowRequestRepository.findAll(qBorrowRequest.item.eq(borrowItem.getId())));
|
||||
|
||||
borrowItemRepository.delete(borrowItem);
|
||||
}
|
||||
@ -217,7 +224,10 @@ public class BorrowItemManager {
|
||||
* @param id the id
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
borrowItemRepository.deleteById(id);
|
||||
BorrowItem borrowItem = get(id);
|
||||
Assert.notNull(borrowItem, "Invalid borrow item id: "
|
||||
+ id);
|
||||
delete(borrowItem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ public class BorrowRequestManager {
|
||||
* @param descending the descending
|
||||
* @return the for user and stauts
|
||||
*/
|
||||
public Page<BorrowRequest> getForUserAndStauts(Long userId, BorrowRequestStatus status,
|
||||
public Page<BorrowRequest> getForUserAndStatus(Long userId, BorrowRequestStatus status,
|
||||
int page, int size, String sortBy, boolean descending) {
|
||||
return borrowRequestRepository.findAll(
|
||||
qBorrowRequest.user.eq(userId).and(qBorrowRequest.status.eq(status)),
|
||||
|
@ -59,56 +59,30 @@ public class BorrowItemController extends BaseController {
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("search") Optional<String> searchParameter) {
|
||||
@RequestParam("search") Optional<String> searchParameter,
|
||||
@RequestParam("owner") Optional<Boolean> ownerParameter) {
|
||||
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_REQUESTS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
Page<BorrowItem> borrowItems;
|
||||
|
||||
Page<BorrowItem> borrowItems = borrowItemManager.get(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"), descParameter.orElse(false),
|
||||
searchParameter.orElse(null));
|
||||
|
||||
for (BorrowItem borrowItem : borrowItems.getContent()) {
|
||||
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
||||
borrowItem.setEmail(null);
|
||||
borrowItem.setEmailNotification(null);
|
||||
if (ownerParameter.isPresent() && ownerParameter.get().booleanValue()) {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowItemManager.applySlots(borrowItem);
|
||||
borrowItems = borrowItemManager.getForUser(getCurrentUserId(), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false), searchParameter.orElse(null));
|
||||
} else {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(),
|
||||
BorrowPermissions.BORROW_REQUESTS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowItems = borrowItemManager.get(pageParameter.orElse(0), sizeParameter.orElse(10),
|
||||
sortParameter.orElse("id"), descParameter.orElse(false),
|
||||
searchParameter.orElse(null));
|
||||
}
|
||||
|
||||
return borrowItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the owner borrow items.
|
||||
*
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParameter the sort parameter
|
||||
* @param descParameter the desc parameter
|
||||
* @param searchParameter the search parameter
|
||||
* @return the owner borrow items
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/mine")
|
||||
public Page<BorrowItem> getOwnerBorrowItems(
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("search") Optional<String> searchParameter) {
|
||||
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
Page<BorrowItem> borrowItems = borrowItemManager.getForUser(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false), searchParameter.orElse(null));
|
||||
|
||||
for (BorrowItem borrowItem : borrowItems.getContent()) {
|
||||
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
||||
borrowItem.setEmail(null);
|
||||
@ -136,7 +110,7 @@ public class BorrowItemController extends BaseController {
|
||||
BorrowItem borrowItem = borrowItemManager.get(id);
|
||||
|
||||
if (borrowItem == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
||||
|
@ -78,53 +78,30 @@ public class BorrowRequestController extends BaseController {
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("owner") Optional<Boolean> ownerParameter) {
|
||||
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_REQUESTS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
Page<BorrowRequest> borrowRequests;
|
||||
|
||||
if (ownerParameter.isPresent() && ownerParameter.get().booleanValue()) {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowRequests = borrowRequestManager.getForOwner(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
} else {
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(),
|
||||
BorrowPermissions.BORROW_REQUESTS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
borrowRequests = borrowRequestManager.getForUser(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
}
|
||||
|
||||
Page<BorrowRequest> borrowRequests = borrowRequestManager.getForUser(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
|
||||
for (BorrowRequest borrowRequest : borrowRequests.getContent()) {
|
||||
BorrowItem borrowItem = borrowItemManager.get(borrowRequest.getItem());
|
||||
borrowItem.setEmail(null);
|
||||
borrowItem.setEmailNotification(null);
|
||||
borrowRequest.setBorrowItem(borrowItem);
|
||||
}
|
||||
|
||||
return borrowRequests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the owner borrow requests.
|
||||
*
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParameter the sort parameter
|
||||
* @param descParameter the desc parameter
|
||||
* @return the owner borrow requests
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/mine")
|
||||
public Page<BorrowRequest> getOwnerBorrowRequests(
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("sort") Optional<String> sortParameter,
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
Page<BorrowRequest> borrowRequests = borrowRequestManager.getForOwner(getCurrentUserId(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||
descParameter.orElse(false));
|
||||
|
||||
for (BorrowRequest borrowRequest : borrowRequests.getContent()) {
|
||||
BorrowItem borrowItem = borrowItemManager.get(borrowRequest.getItem());
|
||||
borrowItem.setEmail(null);
|
||||
@ -294,7 +271,7 @@ public class BorrowRequestController extends BaseController {
|
||||
|
||||
return signedJwt.getJWTClaimsSet().getClaims();
|
||||
} catch (ParseException e) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
throw new EntityResponseStatusException(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,14 +70,14 @@ public class BorrowJwtValidator implements Validator {
|
||||
errors.reject("INVALID");
|
||||
return;
|
||||
} else if (claims.getNotBeforeTime().after(new Date())) {
|
||||
errors.rejectValue("nbf", "UPCOMING");
|
||||
errors.rejectValue("nbf", "UPCOMING", claims.getNotBeforeTime().toInstant().toString());
|
||||
}
|
||||
|
||||
if (claims.getExpirationTime() == null) {
|
||||
errors.reject("INVALID");
|
||||
return;
|
||||
} else if (claims.getExpirationTime().before(new Date())) {
|
||||
errors.rejectValue("exp", "EXPIRED");
|
||||
errors.rejectValue("exp", "EXPIRED", claims.getExpirationTime().toInstant().toString());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -4,7 +4,7 @@
|
||||
package de.bstly.we.borrow.controller.validation;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -130,7 +130,7 @@ public class BorrowRequestValidator implements Validator {
|
||||
BorrowItemPeriodSlot borrowItemPeriodSlot = (BorrowItemPeriodSlot) borrowItemSlot;
|
||||
if (borrowRequest.getStarts().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||
.compareTo(borrowItemPeriodSlot.getStartDay()) >= 0
|
||||
&& OffsetTime
|
||||
&& LocalTime
|
||||
.ofInstant(borrowRequest.getStarts(),
|
||||
ZoneOffset.UTC)
|
||||
.compareTo(
|
||||
@ -139,7 +139,7 @@ public class BorrowRequestValidator implements Validator {
|
||||
}
|
||||
if (borrowRequest.getEnds().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||
.compareTo(borrowItemPeriodSlot.getEndDay()) <= 0
|
||||
&& OffsetTime
|
||||
&& LocalTime
|
||||
.ofInstant(borrowRequest.getEnds(), ZoneOffset.UTC)
|
||||
.compareTo(
|
||||
borrowItemPeriodSlot.getEndTime()) <= 0) {
|
||||
|
@ -4,10 +4,12 @@
|
||||
package de.bstly.we.borrow.model;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
@ -18,13 +20,15 @@ import javax.persistence.Table;
|
||||
public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
||||
|
||||
@Column(name = "start_day")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private DayOfWeek startDay;
|
||||
@Column(name = "end_day")
|
||||
private DayOfWeek endDay;
|
||||
@Column(name = "start_time")
|
||||
private OffsetTime startTime;
|
||||
private LocalTime startTime;
|
||||
@Column(name = "end_day")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private DayOfWeek endDay;
|
||||
@Column(name = "end_time")
|
||||
private OffsetTime endTime;
|
||||
private LocalTime endTime;
|
||||
|
||||
/**
|
||||
* @return the startDay
|
||||
@ -40,6 +44,20 @@ public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
||||
this.startDay = startDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the startTime
|
||||
*/
|
||||
public LocalTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startTime the startTime to set
|
||||
*/
|
||||
public void setStartTime(LocalTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the endDay
|
||||
*/
|
||||
@ -54,31 +72,17 @@ public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
||||
this.endDay = endDay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the startTime
|
||||
*/
|
||||
public OffsetTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startTime the startTime to set
|
||||
*/
|
||||
public void setStartTime(OffsetTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the endTime
|
||||
*/
|
||||
public OffsetTime getEndTime() {
|
||||
public LocalTime getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param endTime the endTime to set
|
||||
*/
|
||||
public void setEndTime(OffsetTime endTime) {
|
||||
public void setEndTime(LocalTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class PermissionManager implements UserDataProvider {
|
||||
* Gets the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return the list
|
||||
*/
|
||||
public List<Permission> get(Long target, String name) {
|
||||
@ -126,7 +126,7 @@ public class PermissionManager implements UserDataProvider {
|
||||
* Checks for permission.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean hasPermission(Long target, String name) {
|
||||
@ -143,10 +143,10 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Creates the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param addon the addon
|
||||
* @param starts the starts
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param addon the addon
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
* @return the permission
|
||||
*/
|
||||
@ -170,9 +170,12 @@ public class PermissionManager implements UserDataProvider {
|
||||
*/
|
||||
public Permission update(Permission permission) {
|
||||
Assert.isTrue(
|
||||
permissionRepository.exists(qPermission.target.eq(permission.getTarget())
|
||||
.and(qPermission.name.eq(permission.getName()))),
|
||||
"Permission '" + permission.getName() + "' for target + '" + permission.getTarget()
|
||||
permissionRepository.exists(qPermission.target
|
||||
.eq(permission.getTarget()).and(qPermission.name.eq(permission.getName()))),
|
||||
"Permission '"
|
||||
+ permission.getName()
|
||||
+ "' for target + '"
|
||||
+ permission.getTarget()
|
||||
+ "' not exists!");
|
||||
Permission updatePermission = permissionRepository.findOne(qPermission.target
|
||||
.eq(permission.getTarget()).and(qPermission.name.eq(permission.getName()))).get();
|
||||
@ -185,7 +188,7 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @param clone the clone
|
||||
* @return the list
|
||||
*/
|
||||
@ -209,13 +212,17 @@ public class PermissionManager implements UserDataProvider {
|
||||
* Delete.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
*/
|
||||
public void delete(Long target, String name) {
|
||||
Assert.isTrue(
|
||||
permissionRepository
|
||||
.exists(qPermission.target.eq(target).and(qPermission.name.eq(name))),
|
||||
"Permission '" + name + "' for target + '" + target + "' not exists!");
|
||||
"Permission '"
|
||||
+ name
|
||||
+ "' for target + '"
|
||||
+ target
|
||||
+ "' not exists!");
|
||||
Permission delete = permissionRepository
|
||||
.findOne(qPermission.target.eq(target).and(qPermission.name.eq(name))).get();
|
||||
permissionRepository.delete(delete);
|
||||
@ -242,13 +249,14 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Apply item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param answers the answers
|
||||
* @param start the start
|
||||
* @param start the start
|
||||
*/
|
||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant start) {
|
||||
for (Permission permission : getForItem(target, item, answers, start)) {
|
||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||
Instant expires) {
|
||||
for (Permission permission : getForItem(target, item, answers, starts, expires)) {
|
||||
permissionRepository.save(permission);
|
||||
}
|
||||
}
|
||||
@ -256,25 +264,25 @@ public class PermissionManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the for item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param answers the answers
|
||||
* @param start the start
|
||||
* @param starts the start
|
||||
* @return the for item
|
||||
*/
|
||||
public List<Permission> getForItem(Long target, Integer item, JsonArray answers,
|
||||
Instant start) {
|
||||
public List<Permission> getForItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||
Instant expires) {
|
||||
List<Permission> permissions = Lists.newArrayList();
|
||||
|
||||
if (start == null) {
|
||||
start = Instant.now();
|
||||
}
|
||||
|
||||
for (PermissionMapping permissionMapping : permissionMappingManager.getAllByItem(item)) {
|
||||
for (String name : permissionMapping.getNames()) {
|
||||
Instant starts = null;
|
||||
Instant expires = InstantHelper.plus(start, permissionMapping.getLifetime(),
|
||||
permissionMapping.getLifetimeUnit());
|
||||
Instant permissionStarts = starts;
|
||||
Instant permissionsExpires = expires;
|
||||
|
||||
if (permissionsExpires == null) {
|
||||
permissionsExpires = InstantHelper.plus(
|
||||
permissionStarts == null ? Instant.now() : permissionStarts,
|
||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
|
||||
}
|
||||
|
||||
boolean additional = true;
|
||||
|
||||
@ -290,8 +298,8 @@ public class PermissionManager implements UserDataProvider {
|
||||
.getAsString();
|
||||
if (StringUtils.hasText(dateTimeString)) {
|
||||
dateTimeString = dateTimeString.replace(" ", "T");
|
||||
starts = OffsetDateTime.parse(dateTimeString).toInstant();
|
||||
expires = InstantHelper.plus(starts,
|
||||
permissionStarts = OffsetDateTime.parse(dateTimeString).toInstant();
|
||||
permissionsExpires = InstantHelper.plus(permissionStarts,
|
||||
permissionMapping.getLifetime(),
|
||||
permissionMapping.getLifetimeUnit());
|
||||
additional = false;
|
||||
@ -307,7 +315,7 @@ public class PermissionManager implements UserDataProvider {
|
||||
.getAsString();
|
||||
if (StringUtils.hasText(dateTimeString)) {
|
||||
dateTimeString = dateTimeString.replace(" ", "T");
|
||||
expires = InstantHelper.plus(
|
||||
permissionsExpires = InstantHelper.plus(
|
||||
OffsetDateTime.parse(dateTimeString).toInstant(),
|
||||
permissionMapping.getLifetime(),
|
||||
permissionMapping.getLifetimeUnit());
|
||||
@ -333,8 +341,8 @@ public class PermissionManager implements UserDataProvider {
|
||||
permission.setTarget(target);
|
||||
permission.setName(name);
|
||||
permission.setAddon(permissionMapping.isAddon());
|
||||
permission.setStarts(starts);
|
||||
permission.setExpires(expires);
|
||||
permission.setStarts(permissionStarts);
|
||||
permission.setExpires(permissionsExpires);
|
||||
} else {
|
||||
permission.setExpires(InstantHelper.plus(permission.getExpires(),
|
||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit()));
|
||||
|
@ -33,7 +33,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Gets the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return the quota
|
||||
*/
|
||||
public Quota get(Long target, String name) {
|
||||
@ -85,7 +85,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Checks for quota.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean hasQuota(Long target, String name) {
|
||||
@ -96,10 +96,10 @@ public class QuotaManager implements UserDataProvider {
|
||||
/**
|
||||
* Creates the.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param value the value
|
||||
* @param unit the unit
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param value the value
|
||||
* @param unit the unit
|
||||
* @param disposable the disposable
|
||||
* @return the quota
|
||||
*/
|
||||
@ -124,7 +124,10 @@ public class QuotaManager implements UserDataProvider {
|
||||
Assert.isTrue(
|
||||
quotaRepository.exists(
|
||||
qQuota.target.eq(quota.getTarget()).and(qQuota.name.eq(quota.getName()))),
|
||||
"Quota '" + quota.getName() + "' for target + '" + quota.getTarget()
|
||||
"Quota '"
|
||||
+ quota.getName()
|
||||
+ "' for target + '"
|
||||
+ quota.getTarget()
|
||||
+ "' not exists!");
|
||||
Quota updateQuota = quotaRepository
|
||||
.findOne(qQuota.target.eq(quota.getTarget()).and(qQuota.name.eq(quota.getName())))
|
||||
@ -138,7 +141,7 @@ public class QuotaManager implements UserDataProvider {
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @param clone the clone
|
||||
* @param value the value
|
||||
* @return the list
|
||||
@ -161,11 +164,15 @@ public class QuotaManager implements UserDataProvider {
|
||||
* Delete.
|
||||
*
|
||||
* @param target the target
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
*/
|
||||
public void delete(Long target, String name) {
|
||||
Assert.isTrue(quotaRepository.exists(qQuota.target.eq(target).and(qQuota.name.eq(name))),
|
||||
"Quota '" + name + "' for target + '" + target + "' not exists!");
|
||||
"Quota '"
|
||||
+ name
|
||||
+ "' for target + '"
|
||||
+ target
|
||||
+ "' not exists!");
|
||||
Quota delete = quotaRepository.findOne(qQuota.target.eq(target).and(qQuota.name.eq(name)))
|
||||
.get();
|
||||
quotaRepository.delete(delete);
|
||||
@ -189,11 +196,52 @@ public class QuotaManager implements UserDataProvider {
|
||||
quotaRepository.deleteAll(quotaRepository.findAll(qQuota.name.eq(name)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public void addForItem(Long target, Integer item, List<Quota> quotas) {
|
||||
for (QuotaMapping quotaMapping : quotaMappingManager.getAllByItem(item)) {
|
||||
boolean added = false;
|
||||
for (Quota quota : quotas) {
|
||||
if (quota.getName().equals(quotaMapping.getName())) {
|
||||
quota.setValue(
|
||||
quotaMapping.isAppend() ? quota.getValue() + quotaMapping.getValue()
|
||||
: quotaMapping.getValue());
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
if (target != null && hasQuota(target, quotaMapping.getName())) {
|
||||
Quota quota = get(target, quotaMapping.getName());
|
||||
|
||||
quota.setValue(
|
||||
quotaMapping.isAppend() ? quota.getValue() + quotaMapping.getValue()
|
||||
: quotaMapping.getValue());
|
||||
|
||||
quotas.add(quota);
|
||||
added = true;
|
||||
}
|
||||
if (!added) {
|
||||
Quota quota = new Quota();
|
||||
quota.setName(quotaMapping.getName());
|
||||
quota.setValue(quotaMapping.getValue());
|
||||
quota.setUnit(quotaMapping.getUnit());
|
||||
quota.setDisposable(quotaMapping.isDisposable());
|
||||
quotas.add(quota);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply item.
|
||||
*
|
||||
* @param target the target
|
||||
* @param item the item
|
||||
* @param item the item
|
||||
*/
|
||||
public void applyItem(Long target, Integer item) {
|
||||
for (QuotaMapping quotaMapping : quotaMappingManager.getAllByItem(item)) {
|
||||
|
@ -17,7 +17,6 @@ import com.google.common.collect.Lists;
|
||||
import de.bstly.we.businesslogic.QuotaManager;
|
||||
import de.bstly.we.controller.support.TokenSessionManager;
|
||||
import de.bstly.we.model.Quota;
|
||||
import de.bstly.we.model.QuotaMapping;
|
||||
|
||||
/**
|
||||
* The Class QuotaController.
|
||||
@ -54,46 +53,12 @@ public class QuotaController extends BaseController {
|
||||
@GetMapping("/new")
|
||||
public List<Quota> getNewQuotas(HttpSession session) {
|
||||
List<Quota> quotas = Lists.newArrayList();
|
||||
|
||||
if (tokenSessionManager.getTokenFromSession(session).isEmpty()) {
|
||||
return quotas;
|
||||
}
|
||||
|
||||
for (String token : tokenSessionManager.getTokenFromSession(session)) {
|
||||
for (QuotaMapping quotaMapping : tokenSessionManager
|
||||
.getQuotaMappingsForToken(getCurrentUserId(), token)) {
|
||||
boolean added = false;
|
||||
for (Quota quota : quotas) {
|
||||
if (quota.getName().equals(quotaMapping.getName())) {
|
||||
quota.setValue(
|
||||
quotaMapping.isAppend() ? quota.getValue() + quotaMapping.getValue()
|
||||
: quotaMapping.getValue());
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
if (quotaManager.hasQuota(getCurrentUserId(), quotaMapping.getName())) {
|
||||
Quota quota = quotaManager.get(getCurrentUserId(), quotaMapping.getName());
|
||||
|
||||
quota.setValue(
|
||||
quotaMapping.isAppend() ? quota.getValue() + quotaMapping.getValue()
|
||||
: quotaMapping.getValue());
|
||||
|
||||
quotas.add(quota);
|
||||
added = true;
|
||||
}
|
||||
if (!added) {
|
||||
Quota quota = new Quota();
|
||||
quota.setName(quotaMapping.getName());
|
||||
quota.setValue(quotaMapping.getValue());
|
||||
quota.setUnit(quotaMapping.getUnit());
|
||||
quota.setDisposable(quotaMapping.isDisposable());
|
||||
quotas.add(quota);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tokenSessionManager.addQuotasForToken(getCurrentUserId(), token, quotas);
|
||||
}
|
||||
|
||||
return quotas;
|
||||
|
@ -27,6 +27,7 @@ import de.bstly.we.businesslogic.QuotaMappingManager;
|
||||
import de.bstly.we.controller.model.ItemResultModel;
|
||||
import de.bstly.we.model.Permission;
|
||||
import de.bstly.we.model.PermissionMapping;
|
||||
import de.bstly.we.model.Quota;
|
||||
import de.bstly.we.model.QuotaMapping;
|
||||
import de.bstly.we.security.model.LocalUserDetails;
|
||||
import de.bstly.we.security.token.LocalAnonymousAuthenticationToken;
|
||||
@ -54,7 +55,7 @@ public class TokenSessionManager {
|
||||
* Gets the permission mappings for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param token the token
|
||||
* @return the permission mappings for token
|
||||
*/
|
||||
public List<PermissionMapping> getPermissionMappingsForToken(Long userId, String token) {
|
||||
@ -78,7 +79,7 @@ public class TokenSessionManager {
|
||||
* Gets the permissions for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param token the token
|
||||
* @return the permissions for token
|
||||
*/
|
||||
public List<Permission> getPermissionsForToken(Long userId, String token) {
|
||||
@ -99,7 +100,7 @@ public class TokenSessionManager {
|
||||
}
|
||||
|
||||
permissions.addAll(permissionManager.getForItem(userId, item,
|
||||
orderPosition.get("answers").getAsJsonArray(), lastPaymentDate));
|
||||
orderPosition.get("answers").getAsJsonArray(), null, null));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
@ -112,7 +113,7 @@ public class TokenSessionManager {
|
||||
* Gets the quota mappings for token.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param token the token
|
||||
* @param token the token
|
||||
* @return the quota mappings for token
|
||||
*/
|
||||
public List<QuotaMapping> getQuotaMappingsForToken(Long userId, String token) {
|
||||
@ -132,6 +133,20 @@ public class TokenSessionManager {
|
||||
return quotaMappings;
|
||||
}
|
||||
|
||||
public void addQuotasForToken(Long userId, String token, List<Quota> quotas) {
|
||||
try {
|
||||
JsonObject result = pretixManager.getCheckInItemBySecret(token);
|
||||
if (result != null && result.get("secret").getAsString().equals(token)
|
||||
&& result.getAsJsonArray("checkins").size() < 1
|
||||
&& "p".equals(result.get("order__status").getAsString())) {
|
||||
int item = result.get("item").getAsInt();
|
||||
quotaManager.addForItem(userId, item, quotas);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply tokens.
|
||||
*
|
||||
@ -158,7 +173,7 @@ public class TokenSessionManager {
|
||||
}
|
||||
|
||||
permissionManager.applyItem(userId, item,
|
||||
position.get("answers").getAsJsonArray(), lastPaymentDate);
|
||||
position.get("answers").getAsJsonArray(), null, null);
|
||||
permissionMappings.addAll(permissionMappingManager.getAllByItem(item));
|
||||
quotaManager.applyItem(userId, item);
|
||||
quotaMappings.addAll(quotaMappingManager.getAllByItem(item));
|
||||
@ -200,7 +215,7 @@ public class TokenSessionManager {
|
||||
/**
|
||||
* Adds the token to session.
|
||||
*
|
||||
* @param secret the secret
|
||||
* @param secret the secret
|
||||
* @param session the session
|
||||
*/
|
||||
public void addTokenToSession(String secret, HttpSession session) {
|
||||
@ -214,7 +229,8 @@ public class TokenSessionManager {
|
||||
}
|
||||
|
||||
if (StringUtils.hasLength(tokens)) {
|
||||
tokens += "," + secret;
|
||||
tokens += ","
|
||||
+ secret;
|
||||
} else {
|
||||
tokens = secret;
|
||||
}
|
||||
@ -226,7 +242,7 @@ public class TokenSessionManager {
|
||||
/**
|
||||
* Removes the token from session.
|
||||
*
|
||||
* @param secret the secret
|
||||
* @param secret the secret
|
||||
* @param session the session
|
||||
*/
|
||||
public void removeTokenFromSession(String secret, HttpSession session) {
|
||||
@ -238,7 +254,8 @@ public class TokenSessionManager {
|
||||
for (String token : ((String) sessionAttribute).split(",")) {
|
||||
if (!token.equals(secret)) {
|
||||
if (StringUtils.hasLength(tokens)) {
|
||||
tokens += "," + secret;
|
||||
tokens += ","
|
||||
+ secret;
|
||||
} else {
|
||||
tokens = secret;
|
||||
}
|
||||
@ -261,7 +278,7 @@ public class TokenSessionManager {
|
||||
/**
|
||||
* Creates the new auth.
|
||||
*
|
||||
* @param auth the auth
|
||||
* @param auth the auth
|
||||
* @param details the details
|
||||
* @return the authentication
|
||||
*/
|
||||
|
@ -35,8 +35,6 @@ public class User implements UserData {
|
||||
private boolean locked;
|
||||
@Column(name = "status", nullable = false)
|
||||
private UserStatus status;
|
||||
@Column(name = "secret")
|
||||
private String secret;
|
||||
@Column(name = "reset_token")
|
||||
private String resetToken;
|
||||
|
||||
@ -148,24 +146,6 @@ public class User implements UserData {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secret.
|
||||
*
|
||||
* @return the secret
|
||||
*/
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the secret.
|
||||
*
|
||||
* @param secret the new secret
|
||||
*/
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reset token.
|
||||
*
|
||||
|
@ -63,8 +63,8 @@ public class InviteManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param search the search
|
||||
* @return the page
|
||||
*/
|
||||
@ -89,17 +89,17 @@ public class InviteManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the by owner.
|
||||
*
|
||||
* @param owner the owner
|
||||
* @param item the item
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param owner the owner
|
||||
* @param item the item
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @param search the search
|
||||
* @param redeemed the redeemed
|
||||
* @param search the search
|
||||
* @param redeemed the redeemed
|
||||
* @return the by owner
|
||||
*/
|
||||
public Page<Invite> getByOwner(Long owner, Integer item, int page, int size, String sortBy,
|
||||
public Page<Invite> getByOwner(Long owner, String quota, int page, int size, String sortBy,
|
||||
boolean descending, String search, String redeemed) {
|
||||
PageRequest pageRequest = PageRequest.of(page, size,
|
||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||
@ -107,8 +107,8 @@ public class InviteManager implements UserDataProvider {
|
||||
BooleanBuilder query = new BooleanBuilder();
|
||||
query.and(qInvite.owner.eq(owner));
|
||||
|
||||
if (item != null) {
|
||||
query.and(qInvite.item.eq(item));
|
||||
if (StringUtils.hasText(quota)) {
|
||||
query.and(qInvite.quota.eq(quota));
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(search)) {
|
||||
@ -129,20 +129,20 @@ public class InviteManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the others.
|
||||
*
|
||||
* @param owner the owner
|
||||
* @param item the item
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param search the search
|
||||
* @param owner the owner
|
||||
* @param item the item
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param search the search
|
||||
* @param redeemed the redeemed
|
||||
* @return the others
|
||||
*/
|
||||
public Page<Invite> getOthers(Long owner, int item, int page, int size, String search,
|
||||
public Page<Invite> getOthers(Long owner, String quota, int page, int size, String search,
|
||||
String redeemed) {
|
||||
|
||||
BooleanBuilder query = new BooleanBuilder();
|
||||
query.and(qInvite.owner.ne(owner));
|
||||
query.and(qInvite.item.eq(item));
|
||||
query.and(qInvite.quota.eq(quota));
|
||||
|
||||
if (StringUtils.hasText(search)) {
|
||||
query.and(qInvite.note.containsIgnoreCase(search));
|
||||
@ -173,7 +173,8 @@ public class InviteManager implements UserDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
InviteMapping inviteMapping = inviteMappingManager.getByItem(invite.getItem());
|
||||
InviteMapping inviteMapping = inviteMappingManager.getByItemAndQuota(invite.getItem(),
|
||||
invite.getQuota());
|
||||
Assert.notNull(inviteMapping, "No mapping for item!");
|
||||
if (StringUtils.hasLength(inviteMapping.getCodeLink())) {
|
||||
invite.setCodeLink(String.format(inviteMapping.getCodeLink(), invite.getCode()));
|
||||
@ -181,6 +182,8 @@ public class InviteManager implements UserDataProvider {
|
||||
invite.setCodeLink(null);
|
||||
}
|
||||
|
||||
invite.setUrl(inviteMapping.getUrl());
|
||||
|
||||
return inviteRepository.save(invite);
|
||||
}
|
||||
|
||||
|
@ -49,16 +49,18 @@ public class InviteMappingManager {
|
||||
* @param item the item
|
||||
* @return the by item
|
||||
*/
|
||||
public InviteMapping getByItem(int item) {
|
||||
return inviteMappingRepository.findOne(qInviteMapping.item.eq(item)).orElse(null);
|
||||
public InviteMapping getByItemAndQuota(int item, String quota) {
|
||||
return inviteMappingRepository
|
||||
.findOne(qInviteMapping.item.eq(item).and(qInviteMapping.quota.eq(quota)))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the page
|
||||
*/
|
||||
@ -70,9 +72,9 @@ public class InviteMappingManager {
|
||||
/**
|
||||
* Creates the.
|
||||
*
|
||||
* @param quota the quota
|
||||
* @param item the item
|
||||
* @param starts the starts
|
||||
* @param quota the quota
|
||||
* @param item the item
|
||||
* @param starts the starts
|
||||
* @param expires the expires
|
||||
* @return the invite mapping
|
||||
*/
|
||||
@ -106,6 +108,16 @@ public class InviteMappingManager {
|
||||
invite.setCodeLink(null);
|
||||
inviteRepository.save(invite);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(inviteMapping.getUrl())) {
|
||||
if (!inviteMapping.getUrl().equals(invite.getUrl())) {
|
||||
invite.setUrl(inviteMapping.getUrl());
|
||||
inviteRepository.save(invite);
|
||||
}
|
||||
} else if (StringUtils.hasText(invite.getUrl())) {
|
||||
invite.setUrl(null);
|
||||
inviteRepository.save(invite);
|
||||
}
|
||||
}
|
||||
|
||||
return inviteMappingRepository.save(inviteMapping);
|
||||
|
@ -4,6 +4,7 @@
|
||||
package de.bstly.we.invite.controller;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -93,24 +94,43 @@ public class InviteController extends BaseController {
|
||||
invite.setNote(null);
|
||||
invite.setOwner(null);
|
||||
} else if (!getCurrentUserId().equals(invite.getOwner())) {
|
||||
if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
|
||||
invite.setId(null);
|
||||
invite.setItem(null);
|
||||
if (!StringUtils.hasText(invite.getNote())) {
|
||||
invite.setNote("...");
|
||||
}
|
||||
invite.setOwner(null);
|
||||
} else {
|
||||
invite.setId(null);
|
||||
invite.setItem(null);
|
||||
invite.setId(null);
|
||||
invite.setCode(null);
|
||||
invite.setCodeLink(null);
|
||||
invite.setOwner(null);
|
||||
if (!permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
|
||||
invite.setNote(null);
|
||||
invite.setOwner(null);
|
||||
}
|
||||
}
|
||||
|
||||
return invite;
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/permissions")
|
||||
public List<Permission> getPermissions(@PathVariable("code") String code) {
|
||||
Invite invite = inviteManager.getByCode(code);
|
||||
if (invite == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
return permissionManager.getForItem(null, invite.getItem(), new JsonArray(),
|
||||
invite.getStarts(), invite.getExpires());
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/quotas")
|
||||
public List<Quota> getQuotas(@PathVariable("code") String code) {
|
||||
Invite invite = inviteManager.getByCode(code);
|
||||
if (invite == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
List<Quota> quotas = Lists.newArrayList();
|
||||
|
||||
quotaManager.addForItem(null, invite.getItem(), quotas);
|
||||
|
||||
return quotas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register.
|
||||
*
|
||||
@ -119,6 +139,11 @@ public class InviteController extends BaseController {
|
||||
@PostMapping
|
||||
public void register(@RequestBody UserModel userModel) {
|
||||
Errors errors = new RequestBodyErrors(userModel);
|
||||
|
||||
if (!StringUtils.hasText(userModel.getToken())) {
|
||||
throw new EntityResponseStatusException(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
Invite invite = inviteManager.getByCode(userModel.getToken());
|
||||
|
||||
if (invite == null) {
|
||||
@ -133,7 +158,7 @@ public class InviteController extends BaseController {
|
||||
boolean register = false;
|
||||
|
||||
for (Permission permission : permissionManager.getForItem(null, invite.getItem(),
|
||||
new JsonArray(), invite.getStarts())) {
|
||||
new JsonArray(), invite.getStarts(), invite.getExpires())) {
|
||||
if (permission.getExpires().isAfter(Instant.now()) && !permission.isAddon()) {
|
||||
register = true;
|
||||
break;
|
||||
@ -180,7 +205,7 @@ public class InviteController extends BaseController {
|
||||
}
|
||||
|
||||
permissionManager.applyItem(user.getId(), invite.getItem(), new JsonArray(),
|
||||
invite.getStarts());
|
||||
invite.getStarts(), invite.getExpires());
|
||||
quotaManager.applyItem(user.getId(), invite.getItem());
|
||||
|
||||
invite.setRedeemed(true);
|
||||
@ -190,12 +215,12 @@ public class InviteController extends BaseController {
|
||||
/**
|
||||
* Gets the invites.
|
||||
*
|
||||
* @param quotaParameter the quota parameter
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParamater the sort paramater
|
||||
* @param descParameter the desc parameter
|
||||
* @param searchParameter the search parameter
|
||||
* @param quotaParameter the quota parameter
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param sortParamater the sort paramater
|
||||
* @param descParameter the desc parameter
|
||||
* @param searchParameter the search parameter
|
||||
* @param redeemedParameter the redeemed parameter
|
||||
* @return the invites
|
||||
*/
|
||||
@ -208,27 +233,20 @@ public class InviteController extends BaseController {
|
||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||
@RequestParam("search") Optional<String> searchParameter,
|
||||
@RequestParam("redeemed") Optional<String> redeemedParameter) {
|
||||
Integer item = null;
|
||||
if (quotaParameter.isPresent() && StringUtils.hasText(quotaParameter.get())) {
|
||||
InviteMapping inviteMapping = inviteMappingManager.get(quotaParameter.get());
|
||||
if (inviteMapping == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||
}
|
||||
item = inviteMapping.getItem();
|
||||
}
|
||||
|
||||
return inviteManager.getByOwner(getCurrentUserId(), item, pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParamater.orElse("id"), descParameter.orElse(false),
|
||||
searchParameter.orElse(null), redeemedParameter.orElse(null));
|
||||
return inviteManager.getByOwner(getCurrentUserId(), quotaParameter.orElse(""),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParamater.orElse("id"),
|
||||
descParameter.orElse(false), searchParameter.orElse(null),
|
||||
redeemedParameter.orElse(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the other invites.
|
||||
*
|
||||
* @param quota the quota
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param searchParameter the search parameter
|
||||
* @param quota the quota
|
||||
* @param pageParameter the page parameter
|
||||
* @param sizeParameter the size parameter
|
||||
* @param searchParameter the search parameter
|
||||
* @param redeemedParameter the redeemed parameter
|
||||
* @return the other invites
|
||||
*/
|
||||
@ -247,7 +265,7 @@ public class InviteController extends BaseController {
|
||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
Page<Invite> page = inviteManager.getOthers(getCurrentUserId(), inviteMapping.getItem(),
|
||||
Page<Invite> page = inviteManager.getOthers(getCurrentUserId(), quota,
|
||||
pageParameter.orElse(0), sizeParameter.orElse(10), searchParameter.orElse(null),
|
||||
redeemedParameter.orElse(null));
|
||||
for (Invite invite : page.getContent()) {
|
||||
@ -264,7 +282,7 @@ public class InviteController extends BaseController {
|
||||
/**
|
||||
* Creates the invite.
|
||||
*
|
||||
* @param quota the quota
|
||||
* @param quota the quota
|
||||
* @param inviteModel the invite model
|
||||
* @return the invite
|
||||
*/
|
||||
@ -290,6 +308,7 @@ public class InviteController extends BaseController {
|
||||
invite.setExpires(inviteMapping.getExpires() != null ? inviteMapping.getExpires()
|
||||
: inviteModel.getExpires());
|
||||
invite.setItem(inviteMapping.getItem());
|
||||
invite.setQuota(inviteMapping.getQuota());
|
||||
|
||||
if (inviteMapping.getMessageLimit() != null && inviteMapping.getMessageLimit() > 0
|
||||
&& StringUtils.hasText(inviteModel.getMessage())
|
||||
|
@ -44,8 +44,8 @@ public class InviteManagingController extends BaseController {
|
||||
/**
|
||||
* Gets the invites.
|
||||
*
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param search the search
|
||||
* @return the invites
|
||||
*/
|
||||
@ -66,7 +66,8 @@ public class InviteManagingController extends BaseController {
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public Invite createOrUpdate(@RequestBody Invite invite) {
|
||||
if (invite.getItem() == null || inviteMappingManager.getByItem(invite.getItem()) == null) {
|
||||
if (invite.getItem() == null || inviteMappingManager.getByItemAndQuota(invite.getItem(),
|
||||
invite.getQuota()) == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ public class Invite implements UserData {
|
||||
private Long owner;
|
||||
private String code;
|
||||
private Integer item;
|
||||
private String quota;
|
||||
private Instant starts;
|
||||
private Instant expires;
|
||||
@Lob
|
||||
@ -36,6 +37,7 @@ public class Invite implements UserData {
|
||||
private String note;
|
||||
private boolean redeemed;
|
||||
private String codeLink;
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
@ -109,6 +111,20 @@ public class Invite implements UserData {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the quota
|
||||
*/
|
||||
public String getQuota() {
|
||||
return quota;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param quota the quota to set
|
||||
*/
|
||||
public void setQuota(String quota) {
|
||||
this.quota = quota;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the starts.
|
||||
*
|
||||
@ -216,4 +232,19 @@ public class Invite implements UserData {
|
||||
public void setCodeLink(String codeLink) {
|
||||
this.codeLink = codeLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public class InviteMapping {
|
||||
@Column(name = "message_limit")
|
||||
private Integer messageLimit;
|
||||
private String codeLink;
|
||||
private String url;
|
||||
private String defaultMessage;
|
||||
|
||||
/**
|
||||
@ -137,6 +138,20 @@ public class InviteMapping {
|
||||
this.codeLink = codeLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default message.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user