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.QBorrowItem;
|
||||||
import de.bstly.we.borrow.model.QBorrowItemManualSlot;
|
import de.bstly.we.borrow.model.QBorrowItemManualSlot;
|
||||||
import de.bstly.we.borrow.model.QBorrowItemPeriodSlot;
|
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.BorrowItemManualSlotRepository;
|
||||||
import de.bstly.we.borrow.repository.BorrowItemPeriodSlotRepository;
|
import de.bstly.we.borrow.repository.BorrowItemPeriodSlotRepository;
|
||||||
import de.bstly.we.borrow.repository.BorrowItemRepository;
|
import de.bstly.we.borrow.repository.BorrowItemRepository;
|
||||||
|
import de.bstly.we.borrow.repository.BorrowRequestRepository;
|
||||||
import de.bstly.we.businesslogic.UserManager;
|
import de.bstly.we.businesslogic.UserManager;
|
||||||
import de.bstly.we.email.businesslogic.EmailManager;
|
import de.bstly.we.email.businesslogic.EmailManager;
|
||||||
import de.bstly.we.model.User;
|
import de.bstly.we.model.User;
|
||||||
@ -43,6 +45,8 @@ public class BorrowItemManager {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private BorrowItemPeriodSlotRepository borrowItemPeriodSlotRepository;
|
private BorrowItemPeriodSlotRepository borrowItemPeriodSlotRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private BorrowRequestRepository borrowRequestRepository;
|
||||||
|
@Autowired
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmailManager emailManager;
|
private EmailManager emailManager;
|
||||||
@ -50,6 +54,7 @@ public class BorrowItemManager {
|
|||||||
private QBorrowItem qBorrowItem = QBorrowItem.borrowItem;
|
private QBorrowItem qBorrowItem = QBorrowItem.borrowItem;
|
||||||
private QBorrowItemManualSlot qBorrowItemManualSlot = QBorrowItemManualSlot.borrowItemManualSlot;
|
private QBorrowItemManualSlot qBorrowItemManualSlot = QBorrowItemManualSlot.borrowItemManualSlot;
|
||||||
private QBorrowItemPeriodSlot qBorrowItemPeriodSlot = QBorrowItemPeriodSlot.borrowItemPeriodSlot;
|
private QBorrowItemPeriodSlot qBorrowItemPeriodSlot = QBorrowItemPeriodSlot.borrowItemPeriodSlot;
|
||||||
|
private QBorrowRequest qBorrowRequest = QBorrowRequest.borrowRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exists.
|
* Exists.
|
||||||
@ -207,6 +212,8 @@ public class BorrowItemManager {
|
|||||||
.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
.findAll(qBorrowItemManualSlot.item.eq(borrowItem.getId())));
|
||||||
borrowItemPeriodSlotRepository.deleteAll(borrowItemPeriodSlotRepository
|
borrowItemPeriodSlotRepository.deleteAll(borrowItemPeriodSlotRepository
|
||||||
.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
.findAll(qBorrowItemPeriodSlot.item.eq(borrowItem.getId())));
|
||||||
|
borrowRequestRepository.deleteAll(
|
||||||
|
borrowRequestRepository.findAll(qBorrowRequest.item.eq(borrowItem.getId())));
|
||||||
|
|
||||||
borrowItemRepository.delete(borrowItem);
|
borrowItemRepository.delete(borrowItem);
|
||||||
}
|
}
|
||||||
@ -217,7 +224,10 @@ public class BorrowItemManager {
|
|||||||
* @param id the id
|
* @param id the id
|
||||||
*/
|
*/
|
||||||
public void delete(Long 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
|
* @param descending the descending
|
||||||
* @return the for user and stauts
|
* @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) {
|
int page, int size, String sortBy, boolean descending) {
|
||||||
return borrowRequestRepository.findAll(
|
return borrowRequestRepository.findAll(
|
||||||
qBorrowRequest.user.eq(userId).and(qBorrowRequest.status.eq(status)),
|
qBorrowRequest.user.eq(userId).and(qBorrowRequest.status.eq(status)),
|
||||||
|
@ -59,55 +59,29 @@ public class BorrowItemController extends BaseController {
|
|||||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||||
@RequestParam("sort") Optional<String> sortParameter,
|
@RequestParam("sort") Optional<String> sortParameter,
|
||||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
@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)
|
Page<BorrowItem> borrowItems;
|
||||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
|
||||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
borrowItemManager.applySlots(borrowItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (ownerParameter.isPresent() && ownerParameter.get().booleanValue()) {
|
||||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
||||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
borrowItems = borrowItemManager.getForUser(getCurrentUserId(), pageParameter.orElse(0),
|
||||||
Page<BorrowItem> borrowItems = borrowItemManager.getForUser(getCurrentUserId(),
|
sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
|
||||||
descParameter.orElse(false), searchParameter.orElse(null));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
for (BorrowItem borrowItem : borrowItems.getContent()) {
|
for (BorrowItem borrowItem : borrowItems.getContent()) {
|
||||||
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
||||||
@ -136,7 +110,7 @@ public class BorrowItemController extends BaseController {
|
|||||||
BorrowItem borrowItem = borrowItemManager.get(id);
|
BorrowItem borrowItem = borrowItemManager.get(id);
|
||||||
|
|
||||||
if (borrowItem == null) {
|
if (borrowItem == null) {
|
||||||
throw new EntityResponseStatusException(HttpStatus.NO_CONTENT);
|
throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
if (!borrowItem.getOwner().equals(getCurrentUserId())) {
|
||||||
|
@ -78,52 +78,29 @@ public class BorrowRequestController extends BaseController {
|
|||||||
@RequestParam("page") Optional<Integer> pageParameter,
|
@RequestParam("page") Optional<Integer> pageParameter,
|
||||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||||
@RequestParam("sort") Optional<String> sortParameter,
|
@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)
|
Page<BorrowRequest> borrowRequests;
|
||||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
|
||||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (ownerParameter.isPresent() && ownerParameter.get().booleanValue()) {
|
||||||
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
if (!permissionManager.hasPermission(getCurrentUserId(), BorrowPermissions.BORROW_ITEMS)
|
||||||
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
|| !permissionManager.isFullUser(getCurrentUserId())) {
|
||||||
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
throw new EntityResponseStatusException(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
borrowRequests = borrowRequestManager.getForOwner(getCurrentUserId(),
|
||||||
Page<BorrowRequest> borrowRequests = borrowRequestManager.getForOwner(getCurrentUserId(),
|
|
||||||
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
pageParameter.orElse(0), sizeParameter.orElse(10), sortParameter.orElse("id"),
|
||||||
descParameter.orElse(false));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
for (BorrowRequest borrowRequest : borrowRequests.getContent()) {
|
for (BorrowRequest borrowRequest : borrowRequests.getContent()) {
|
||||||
BorrowItem borrowItem = borrowItemManager.get(borrowRequest.getItem());
|
BorrowItem borrowItem = borrowItemManager.get(borrowRequest.getItem());
|
||||||
@ -294,7 +271,7 @@ public class BorrowRequestController extends BaseController {
|
|||||||
|
|
||||||
return signedJwt.getJWTClaimsSet().getClaims();
|
return signedJwt.getJWTClaimsSet().getClaims();
|
||||||
} catch (ParseException e) {
|
} 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");
|
errors.reject("INVALID");
|
||||||
return;
|
return;
|
||||||
} else if (claims.getNotBeforeTime().after(new Date())) {
|
} else if (claims.getNotBeforeTime().after(new Date())) {
|
||||||
errors.rejectValue("nbf", "UPCOMING");
|
errors.rejectValue("nbf", "UPCOMING", claims.getNotBeforeTime().toInstant().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (claims.getExpirationTime() == null) {
|
if (claims.getExpirationTime() == null) {
|
||||||
errors.reject("INVALID");
|
errors.reject("INVALID");
|
||||||
return;
|
return;
|
||||||
} else if (claims.getExpirationTime().before(new Date())) {
|
} else if (claims.getExpirationTime().before(new Date())) {
|
||||||
errors.rejectValue("exp", "EXPIRED");
|
errors.rejectValue("exp", "EXPIRED", claims.getExpirationTime().toInstant().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
package de.bstly.we.borrow.controller.validation;
|
package de.bstly.we.borrow.controller.validation;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.OffsetTime;
|
import java.time.LocalTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -130,7 +130,7 @@ public class BorrowRequestValidator implements Validator {
|
|||||||
BorrowItemPeriodSlot borrowItemPeriodSlot = (BorrowItemPeriodSlot) borrowItemSlot;
|
BorrowItemPeriodSlot borrowItemPeriodSlot = (BorrowItemPeriodSlot) borrowItemSlot;
|
||||||
if (borrowRequest.getStarts().atZone(ZoneOffset.UTC).getDayOfWeek()
|
if (borrowRequest.getStarts().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||||
.compareTo(borrowItemPeriodSlot.getStartDay()) >= 0
|
.compareTo(borrowItemPeriodSlot.getStartDay()) >= 0
|
||||||
&& OffsetTime
|
&& LocalTime
|
||||||
.ofInstant(borrowRequest.getStarts(),
|
.ofInstant(borrowRequest.getStarts(),
|
||||||
ZoneOffset.UTC)
|
ZoneOffset.UTC)
|
||||||
.compareTo(
|
.compareTo(
|
||||||
@ -139,7 +139,7 @@ public class BorrowRequestValidator implements Validator {
|
|||||||
}
|
}
|
||||||
if (borrowRequest.getEnds().atZone(ZoneOffset.UTC).getDayOfWeek()
|
if (borrowRequest.getEnds().atZone(ZoneOffset.UTC).getDayOfWeek()
|
||||||
.compareTo(borrowItemPeriodSlot.getEndDay()) <= 0
|
.compareTo(borrowItemPeriodSlot.getEndDay()) <= 0
|
||||||
&& OffsetTime
|
&& LocalTime
|
||||||
.ofInstant(borrowRequest.getEnds(), ZoneOffset.UTC)
|
.ofInstant(borrowRequest.getEnds(), ZoneOffset.UTC)
|
||||||
.compareTo(
|
.compareTo(
|
||||||
borrowItemPeriodSlot.getEndTime()) <= 0) {
|
borrowItemPeriodSlot.getEndTime()) <= 0) {
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
package de.bstly.we.borrow.model;
|
package de.bstly.we.borrow.model;
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
import java.time.DayOfWeek;
|
||||||
import java.time.OffsetTime;
|
import java.time.LocalTime;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,13 +20,15 @@ import javax.persistence.Table;
|
|||||||
public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
||||||
|
|
||||||
@Column(name = "start_day")
|
@Column(name = "start_day")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
private DayOfWeek startDay;
|
private DayOfWeek startDay;
|
||||||
@Column(name = "end_day")
|
|
||||||
private DayOfWeek endDay;
|
|
||||||
@Column(name = "start_time")
|
@Column(name = "start_time")
|
||||||
private OffsetTime startTime;
|
private LocalTime startTime;
|
||||||
|
@Column(name = "end_day")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private DayOfWeek endDay;
|
||||||
@Column(name = "end_time")
|
@Column(name = "end_time")
|
||||||
private OffsetTime endTime;
|
private LocalTime endTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the startDay
|
* @return the startDay
|
||||||
@ -40,6 +44,20 @@ public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
|||||||
this.startDay = startDay;
|
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
|
* @return the endDay
|
||||||
*/
|
*/
|
||||||
@ -54,31 +72,17 @@ public class BorrowItemPeriodSlot extends BorrowItemSlot {
|
|||||||
this.endDay = endDay;
|
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
|
* @return the endTime
|
||||||
*/
|
*/
|
||||||
public OffsetTime getEndTime() {
|
public LocalTime getEndTime() {
|
||||||
return endTime;
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param endTime the endTime to set
|
* @param endTime the endTime to set
|
||||||
*/
|
*/
|
||||||
public void setEndTime(OffsetTime endTime) {
|
public void setEndTime(LocalTime endTime) {
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,9 +170,12 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
*/
|
*/
|
||||||
public Permission update(Permission permission) {
|
public Permission update(Permission permission) {
|
||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
permissionRepository.exists(qPermission.target.eq(permission.getTarget())
|
permissionRepository.exists(qPermission.target
|
||||||
.and(qPermission.name.eq(permission.getName()))),
|
.eq(permission.getTarget()).and(qPermission.name.eq(permission.getName()))),
|
||||||
"Permission '" + permission.getName() + "' for target + '" + permission.getTarget()
|
"Permission '"
|
||||||
|
+ permission.getName()
|
||||||
|
+ "' for target + '"
|
||||||
|
+ permission.getTarget()
|
||||||
+ "' not exists!");
|
+ "' not exists!");
|
||||||
Permission updatePermission = permissionRepository.findOne(qPermission.target
|
Permission updatePermission = permissionRepository.findOne(qPermission.target
|
||||||
.eq(permission.getTarget()).and(qPermission.name.eq(permission.getName()))).get();
|
.eq(permission.getTarget()).and(qPermission.name.eq(permission.getName()))).get();
|
||||||
@ -215,7 +218,11 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
permissionRepository
|
permissionRepository
|
||||||
.exists(qPermission.target.eq(target).and(qPermission.name.eq(name))),
|
.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
|
Permission delete = permissionRepository
|
||||||
.findOne(qPermission.target.eq(target).and(qPermission.name.eq(name))).get();
|
.findOne(qPermission.target.eq(target).and(qPermission.name.eq(name))).get();
|
||||||
permissionRepository.delete(delete);
|
permissionRepository.delete(delete);
|
||||||
@ -247,8 +254,9 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
* @param answers the answers
|
* @param answers the answers
|
||||||
* @param start the start
|
* @param start the start
|
||||||
*/
|
*/
|
||||||
public void applyItem(Long target, Integer item, JsonArray answers, Instant start) {
|
public void applyItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||||
for (Permission permission : getForItem(target, item, answers, start)) {
|
Instant expires) {
|
||||||
|
for (Permission permission : getForItem(target, item, answers, starts, expires)) {
|
||||||
permissionRepository.save(permission);
|
permissionRepository.save(permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,22 +267,22 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
* @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 start the start
|
* @param starts the start
|
||||||
* @return the for item
|
* @return the for item
|
||||||
*/
|
*/
|
||||||
public List<Permission> getForItem(Long target, Integer item, JsonArray answers,
|
public List<Permission> getForItem(Long target, Integer item, JsonArray answers, Instant starts,
|
||||||
Instant start) {
|
Instant expires) {
|
||||||
List<Permission> permissions = Lists.newArrayList();
|
List<Permission> permissions = Lists.newArrayList();
|
||||||
|
|
||||||
if (start == null) {
|
|
||||||
start = Instant.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PermissionMapping permissionMapping : permissionMappingManager.getAllByItem(item)) {
|
for (PermissionMapping permissionMapping : permissionMappingManager.getAllByItem(item)) {
|
||||||
for (String name : permissionMapping.getNames()) {
|
for (String name : permissionMapping.getNames()) {
|
||||||
Instant starts = null;
|
Instant permissionStarts = starts;
|
||||||
Instant expires = InstantHelper.plus(start, permissionMapping.getLifetime(),
|
Instant permissionsExpires = expires;
|
||||||
permissionMapping.getLifetimeUnit());
|
|
||||||
|
if (permissionsExpires == null) {
|
||||||
|
permissionsExpires = InstantHelper.plus(
|
||||||
|
permissionStarts == null ? Instant.now() : permissionStarts,
|
||||||
|
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit());
|
||||||
|
}
|
||||||
|
|
||||||
boolean additional = true;
|
boolean additional = true;
|
||||||
|
|
||||||
@ -290,8 +298,8 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
.getAsString();
|
.getAsString();
|
||||||
if (StringUtils.hasText(dateTimeString)) {
|
if (StringUtils.hasText(dateTimeString)) {
|
||||||
dateTimeString = dateTimeString.replace(" ", "T");
|
dateTimeString = dateTimeString.replace(" ", "T");
|
||||||
starts = OffsetDateTime.parse(dateTimeString).toInstant();
|
permissionStarts = OffsetDateTime.parse(dateTimeString).toInstant();
|
||||||
expires = InstantHelper.plus(starts,
|
permissionsExpires = InstantHelper.plus(permissionStarts,
|
||||||
permissionMapping.getLifetime(),
|
permissionMapping.getLifetime(),
|
||||||
permissionMapping.getLifetimeUnit());
|
permissionMapping.getLifetimeUnit());
|
||||||
additional = false;
|
additional = false;
|
||||||
@ -307,7 +315,7 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
.getAsString();
|
.getAsString();
|
||||||
if (StringUtils.hasText(dateTimeString)) {
|
if (StringUtils.hasText(dateTimeString)) {
|
||||||
dateTimeString = dateTimeString.replace(" ", "T");
|
dateTimeString = dateTimeString.replace(" ", "T");
|
||||||
expires = InstantHelper.plus(
|
permissionsExpires = InstantHelper.plus(
|
||||||
OffsetDateTime.parse(dateTimeString).toInstant(),
|
OffsetDateTime.parse(dateTimeString).toInstant(),
|
||||||
permissionMapping.getLifetime(),
|
permissionMapping.getLifetime(),
|
||||||
permissionMapping.getLifetimeUnit());
|
permissionMapping.getLifetimeUnit());
|
||||||
@ -333,8 +341,8 @@ public class PermissionManager implements UserDataProvider {
|
|||||||
permission.setTarget(target);
|
permission.setTarget(target);
|
||||||
permission.setName(name);
|
permission.setName(name);
|
||||||
permission.setAddon(permissionMapping.isAddon());
|
permission.setAddon(permissionMapping.isAddon());
|
||||||
permission.setStarts(starts);
|
permission.setStarts(permissionStarts);
|
||||||
permission.setExpires(expires);
|
permission.setExpires(permissionsExpires);
|
||||||
} else {
|
} else {
|
||||||
permission.setExpires(InstantHelper.plus(permission.getExpires(),
|
permission.setExpires(InstantHelper.plus(permission.getExpires(),
|
||||||
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit()));
|
permissionMapping.getLifetime(), permissionMapping.getLifetimeUnit()));
|
||||||
|
@ -124,7 +124,10 @@ public class QuotaManager implements UserDataProvider {
|
|||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
quotaRepository.exists(
|
quotaRepository.exists(
|
||||||
qQuota.target.eq(quota.getTarget()).and(qQuota.name.eq(quota.getName()))),
|
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!");
|
+ "' not exists!");
|
||||||
Quota updateQuota = quotaRepository
|
Quota updateQuota = quotaRepository
|
||||||
.findOne(qQuota.target.eq(quota.getTarget()).and(qQuota.name.eq(quota.getName())))
|
.findOne(qQuota.target.eq(quota.getTarget()).and(qQuota.name.eq(quota.getName())))
|
||||||
@ -165,7 +168,11 @@ public class QuotaManager implements UserDataProvider {
|
|||||||
*/
|
*/
|
||||||
public void delete(Long target, String name) {
|
public void delete(Long target, String name) {
|
||||||
Assert.isTrue(quotaRepository.exists(qQuota.target.eq(target).and(qQuota.name.eq(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)))
|
Quota delete = quotaRepository.findOne(qQuota.target.eq(target).and(qQuota.name.eq(name)))
|
||||||
.get();
|
.get();
|
||||||
quotaRepository.delete(delete);
|
quotaRepository.delete(delete);
|
||||||
@ -189,6 +196,47 @@ public class QuotaManager implements UserDataProvider {
|
|||||||
quotaRepository.deleteAll(quotaRepository.findAll(qQuota.name.eq(name)));
|
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.
|
* Apply item.
|
||||||
*
|
*
|
||||||
|
@ -17,7 +17,6 @@ import com.google.common.collect.Lists;
|
|||||||
import de.bstly.we.businesslogic.QuotaManager;
|
import de.bstly.we.businesslogic.QuotaManager;
|
||||||
import de.bstly.we.controller.support.TokenSessionManager;
|
import de.bstly.we.controller.support.TokenSessionManager;
|
||||||
import de.bstly.we.model.Quota;
|
import de.bstly.we.model.Quota;
|
||||||
import de.bstly.we.model.QuotaMapping;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class QuotaController.
|
* The Class QuotaController.
|
||||||
@ -54,46 +53,12 @@ public class QuotaController extends BaseController {
|
|||||||
@GetMapping("/new")
|
@GetMapping("/new")
|
||||||
public List<Quota> getNewQuotas(HttpSession session) {
|
public List<Quota> getNewQuotas(HttpSession session) {
|
||||||
List<Quota> quotas = Lists.newArrayList();
|
List<Quota> quotas = Lists.newArrayList();
|
||||||
|
|
||||||
if (tokenSessionManager.getTokenFromSession(session).isEmpty()) {
|
if (tokenSessionManager.getTokenFromSession(session).isEmpty()) {
|
||||||
return quotas;
|
return quotas;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String token : tokenSessionManager.getTokenFromSession(session)) {
|
for (String token : tokenSessionManager.getTokenFromSession(session)) {
|
||||||
for (QuotaMapping quotaMapping : tokenSessionManager
|
tokenSessionManager.addQuotasForToken(getCurrentUserId(), token, quotas);
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return quotas;
|
return quotas;
|
||||||
|
@ -27,6 +27,7 @@ import de.bstly.we.businesslogic.QuotaMappingManager;
|
|||||||
import de.bstly.we.controller.model.ItemResultModel;
|
import de.bstly.we.controller.model.ItemResultModel;
|
||||||
import de.bstly.we.model.Permission;
|
import de.bstly.we.model.Permission;
|
||||||
import de.bstly.we.model.PermissionMapping;
|
import de.bstly.we.model.PermissionMapping;
|
||||||
|
import de.bstly.we.model.Quota;
|
||||||
import de.bstly.we.model.QuotaMapping;
|
import de.bstly.we.model.QuotaMapping;
|
||||||
import de.bstly.we.security.model.LocalUserDetails;
|
import de.bstly.we.security.model.LocalUserDetails;
|
||||||
import de.bstly.we.security.token.LocalAnonymousAuthenticationToken;
|
import de.bstly.we.security.token.LocalAnonymousAuthenticationToken;
|
||||||
@ -99,7 +100,7 @@ public class TokenSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
permissions.addAll(permissionManager.getForItem(userId, item,
|
permissions.addAll(permissionManager.getForItem(userId, item,
|
||||||
orderPosition.get("answers").getAsJsonArray(), lastPaymentDate));
|
orderPosition.get("answers").getAsJsonArray(), null, null));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
@ -132,6 +133,20 @@ public class TokenSessionManager {
|
|||||||
return quotaMappings;
|
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.
|
* Apply tokens.
|
||||||
*
|
*
|
||||||
@ -158,7 +173,7 @@ public class TokenSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
permissionManager.applyItem(userId, item,
|
permissionManager.applyItem(userId, item,
|
||||||
position.get("answers").getAsJsonArray(), lastPaymentDate);
|
position.get("answers").getAsJsonArray(), null, null);
|
||||||
permissionMappings.addAll(permissionMappingManager.getAllByItem(item));
|
permissionMappings.addAll(permissionMappingManager.getAllByItem(item));
|
||||||
quotaManager.applyItem(userId, item);
|
quotaManager.applyItem(userId, item);
|
||||||
quotaMappings.addAll(quotaMappingManager.getAllByItem(item));
|
quotaMappings.addAll(quotaMappingManager.getAllByItem(item));
|
||||||
@ -214,7 +229,8 @@ public class TokenSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.hasLength(tokens)) {
|
if (StringUtils.hasLength(tokens)) {
|
||||||
tokens += "," + secret;
|
tokens += ","
|
||||||
|
+ secret;
|
||||||
} else {
|
} else {
|
||||||
tokens = secret;
|
tokens = secret;
|
||||||
}
|
}
|
||||||
@ -238,7 +254,8 @@ public class TokenSessionManager {
|
|||||||
for (String token : ((String) sessionAttribute).split(",")) {
|
for (String token : ((String) sessionAttribute).split(",")) {
|
||||||
if (!token.equals(secret)) {
|
if (!token.equals(secret)) {
|
||||||
if (StringUtils.hasLength(tokens)) {
|
if (StringUtils.hasLength(tokens)) {
|
||||||
tokens += "," + secret;
|
tokens += ","
|
||||||
|
+ secret;
|
||||||
} else {
|
} else {
|
||||||
tokens = secret;
|
tokens = secret;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,6 @@ public class User implements UserData {
|
|||||||
private boolean locked;
|
private boolean locked;
|
||||||
@Column(name = "status", nullable = false)
|
@Column(name = "status", nullable = false)
|
||||||
private UserStatus status;
|
private UserStatus status;
|
||||||
@Column(name = "secret")
|
|
||||||
private String secret;
|
|
||||||
@Column(name = "reset_token")
|
@Column(name = "reset_token")
|
||||||
private String resetToken;
|
private String resetToken;
|
||||||
|
|
||||||
@ -148,24 +146,6 @@ public class User implements UserData {
|
|||||||
this.status = status;
|
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.
|
* Gets the reset token.
|
||||||
*
|
*
|
||||||
|
@ -99,7 +99,7 @@ public class InviteManager implements UserDataProvider {
|
|||||||
* @param redeemed the redeemed
|
* @param redeemed the redeemed
|
||||||
* @return the by owner
|
* @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) {
|
boolean descending, String search, String redeemed) {
|
||||||
PageRequest pageRequest = PageRequest.of(page, size,
|
PageRequest pageRequest = PageRequest.of(page, size,
|
||||||
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
descending ? Sort.by(sortBy).descending() : Sort.by(sortBy).ascending());
|
||||||
@ -107,8 +107,8 @@ public class InviteManager implements UserDataProvider {
|
|||||||
BooleanBuilder query = new BooleanBuilder();
|
BooleanBuilder query = new BooleanBuilder();
|
||||||
query.and(qInvite.owner.eq(owner));
|
query.and(qInvite.owner.eq(owner));
|
||||||
|
|
||||||
if (item != null) {
|
if (StringUtils.hasText(quota)) {
|
||||||
query.and(qInvite.item.eq(item));
|
query.and(qInvite.quota.eq(quota));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.hasText(search)) {
|
if (StringUtils.hasText(search)) {
|
||||||
@ -137,12 +137,12 @@ public class InviteManager implements UserDataProvider {
|
|||||||
* @param redeemed the redeemed
|
* @param redeemed the redeemed
|
||||||
* @return the others
|
* @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) {
|
String redeemed) {
|
||||||
|
|
||||||
BooleanBuilder query = new BooleanBuilder();
|
BooleanBuilder query = new BooleanBuilder();
|
||||||
query.and(qInvite.owner.ne(owner));
|
query.and(qInvite.owner.ne(owner));
|
||||||
query.and(qInvite.item.eq(item));
|
query.and(qInvite.quota.eq(quota));
|
||||||
|
|
||||||
if (StringUtils.hasText(search)) {
|
if (StringUtils.hasText(search)) {
|
||||||
query.and(qInvite.note.containsIgnoreCase(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!");
|
Assert.notNull(inviteMapping, "No mapping for item!");
|
||||||
if (StringUtils.hasLength(inviteMapping.getCodeLink())) {
|
if (StringUtils.hasLength(inviteMapping.getCodeLink())) {
|
||||||
invite.setCodeLink(String.format(inviteMapping.getCodeLink(), invite.getCode()));
|
invite.setCodeLink(String.format(inviteMapping.getCodeLink(), invite.getCode()));
|
||||||
@ -181,6 +182,8 @@ public class InviteManager implements UserDataProvider {
|
|||||||
invite.setCodeLink(null);
|
invite.setCodeLink(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invite.setUrl(inviteMapping.getUrl());
|
||||||
|
|
||||||
return inviteRepository.save(invite);
|
return inviteRepository.save(invite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +49,10 @@ public class InviteMappingManager {
|
|||||||
* @param item the item
|
* @param item the item
|
||||||
* @return the by item
|
* @return the by item
|
||||||
*/
|
*/
|
||||||
public InviteMapping getByItem(int item) {
|
public InviteMapping getByItemAndQuota(int item, String quota) {
|
||||||
return inviteMappingRepository.findOne(qInviteMapping.item.eq(item)).orElse(null);
|
return inviteMappingRepository
|
||||||
|
.findOne(qInviteMapping.item.eq(item).and(qInviteMapping.quota.eq(quota)))
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,6 +108,16 @@ public class InviteMappingManager {
|
|||||||
invite.setCodeLink(null);
|
invite.setCodeLink(null);
|
||||||
inviteRepository.save(invite);
|
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);
|
return inviteMappingRepository.save(inviteMapping);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package de.bstly.we.invite.controller;
|
package de.bstly.we.invite.controller;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -93,24 +94,43 @@ public class InviteController extends BaseController {
|
|||||||
invite.setNote(null);
|
invite.setNote(null);
|
||||||
invite.setOwner(null);
|
invite.setOwner(null);
|
||||||
} else if (!getCurrentUserId().equals(invite.getOwner())) {
|
} else if (!getCurrentUserId().equals(invite.getOwner())) {
|
||||||
if (permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
|
|
||||||
invite.setId(null);
|
invite.setId(null);
|
||||||
invite.setItem(null);
|
invite.setCode(null);
|
||||||
if (!StringUtils.hasText(invite.getNote())) {
|
invite.setCodeLink(null);
|
||||||
invite.setNote("...");
|
|
||||||
}
|
|
||||||
invite.setOwner(null);
|
invite.setOwner(null);
|
||||||
} else {
|
if (!permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
|
||||||
invite.setId(null);
|
|
||||||
invite.setItem(null);
|
|
||||||
invite.setNote(null);
|
invite.setNote(null);
|
||||||
invite.setOwner(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return invite;
|
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.
|
* Register.
|
||||||
*
|
*
|
||||||
@ -119,6 +139,11 @@ public class InviteController extends BaseController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public void register(@RequestBody UserModel userModel) {
|
public void register(@RequestBody UserModel userModel) {
|
||||||
Errors errors = new RequestBodyErrors(userModel);
|
Errors errors = new RequestBodyErrors(userModel);
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(userModel.getToken())) {
|
||||||
|
throw new EntityResponseStatusException(HttpStatus.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
Invite invite = inviteManager.getByCode(userModel.getToken());
|
Invite invite = inviteManager.getByCode(userModel.getToken());
|
||||||
|
|
||||||
if (invite == null) {
|
if (invite == null) {
|
||||||
@ -133,7 +158,7 @@ public class InviteController extends BaseController {
|
|||||||
boolean register = false;
|
boolean register = false;
|
||||||
|
|
||||||
for (Permission permission : permissionManager.getForItem(null, invite.getItem(),
|
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()) {
|
if (permission.getExpires().isAfter(Instant.now()) && !permission.isAddon()) {
|
||||||
register = true;
|
register = true;
|
||||||
break;
|
break;
|
||||||
@ -180,7 +205,7 @@ public class InviteController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
permissionManager.applyItem(user.getId(), invite.getItem(), new JsonArray(),
|
permissionManager.applyItem(user.getId(), invite.getItem(), new JsonArray(),
|
||||||
invite.getStarts());
|
invite.getStarts(), invite.getExpires());
|
||||||
quotaManager.applyItem(user.getId(), invite.getItem());
|
quotaManager.applyItem(user.getId(), invite.getItem());
|
||||||
|
|
||||||
invite.setRedeemed(true);
|
invite.setRedeemed(true);
|
||||||
@ -208,18 +233,11 @@ public class InviteController extends BaseController {
|
|||||||
@RequestParam("desc") Optional<Boolean> descParameter,
|
@RequestParam("desc") Optional<Boolean> descParameter,
|
||||||
@RequestParam("search") Optional<String> searchParameter,
|
@RequestParam("search") Optional<String> searchParameter,
|
||||||
@RequestParam("redeemed") Optional<String> redeemedParameter) {
|
@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),
|
return inviteManager.getByOwner(getCurrentUserId(), quotaParameter.orElse(""),
|
||||||
sizeParameter.orElse(10), sortParamater.orElse("id"), descParameter.orElse(false),
|
pageParameter.orElse(0), sizeParameter.orElse(10), sortParamater.orElse("id"),
|
||||||
searchParameter.orElse(null), redeemedParameter.orElse(null));
|
descParameter.orElse(false), searchParameter.orElse(null),
|
||||||
|
redeemedParameter.orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,7 +265,7 @@ public class InviteController extends BaseController {
|
|||||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
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),
|
pageParameter.orElse(0), sizeParameter.orElse(10), searchParameter.orElse(null),
|
||||||
redeemedParameter.orElse(null));
|
redeemedParameter.orElse(null));
|
||||||
for (Invite invite : page.getContent()) {
|
for (Invite invite : page.getContent()) {
|
||||||
@ -290,6 +308,7 @@ public class InviteController extends BaseController {
|
|||||||
invite.setExpires(inviteMapping.getExpires() != null ? inviteMapping.getExpires()
|
invite.setExpires(inviteMapping.getExpires() != null ? inviteMapping.getExpires()
|
||||||
: inviteModel.getExpires());
|
: inviteModel.getExpires());
|
||||||
invite.setItem(inviteMapping.getItem());
|
invite.setItem(inviteMapping.getItem());
|
||||||
|
invite.setQuota(inviteMapping.getQuota());
|
||||||
|
|
||||||
if (inviteMapping.getMessageLimit() != null && inviteMapping.getMessageLimit() > 0
|
if (inviteMapping.getMessageLimit() != null && inviteMapping.getMessageLimit() > 0
|
||||||
&& StringUtils.hasText(inviteModel.getMessage())
|
&& StringUtils.hasText(inviteModel.getMessage())
|
||||||
|
@ -66,7 +66,8 @@ public class InviteManagingController extends BaseController {
|
|||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Invite createOrUpdate(@RequestBody Invite invite) {
|
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);
|
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ public class Invite implements UserData {
|
|||||||
private Long owner;
|
private Long owner;
|
||||||
private String code;
|
private String code;
|
||||||
private Integer item;
|
private Integer item;
|
||||||
|
private String quota;
|
||||||
private Instant starts;
|
private Instant starts;
|
||||||
private Instant expires;
|
private Instant expires;
|
||||||
@Lob
|
@Lob
|
||||||
@ -36,6 +37,7 @@ public class Invite implements UserData {
|
|||||||
private String note;
|
private String note;
|
||||||
private boolean redeemed;
|
private boolean redeemed;
|
||||||
private String codeLink;
|
private String codeLink;
|
||||||
|
private String url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the id.
|
* Gets the id.
|
||||||
@ -109,6 +111,20 @@ public class Invite implements UserData {
|
|||||||
this.item = item;
|
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.
|
* Gets the starts.
|
||||||
*
|
*
|
||||||
@ -216,4 +232,19 @@ public class Invite implements UserData {
|
|||||||
public void setCodeLink(String codeLink) {
|
public void setCodeLink(String codeLink) {
|
||||||
this.codeLink = 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")
|
@Column(name = "message_limit")
|
||||||
private Integer messageLimit;
|
private Integer messageLimit;
|
||||||
private String codeLink;
|
private String codeLink;
|
||||||
|
private String url;
|
||||||
private String defaultMessage;
|
private String defaultMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,6 +138,20 @@ public class InviteMapping {
|
|||||||
this.codeLink = 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the default message.
|
* Gets the default message.
|
||||||
*
|
*
|
||||||
|
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
|||||||
<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>
|
||||||
<revision>1.2.0-SNAPSHOT</revision>
|
<revision>1.3.0-SNAPSHOT</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
Loading…
Reference in New Issue
Block a user