update invite, keep public key

This commit is contained in:
2022-02-05 10:37:49 +01:00
parent e3a437bd76
commit 1db9257889
12 changed files with 142 additions and 57 deletions
@@ -46,7 +46,7 @@ public class InviteMappingManager {
/**
* Gets the by item and quota.
*
* @param item the item
* @param item the item
* @param quota the quota
* @return the by item and quota
*/
@@ -59,9 +59,9 @@ public class InviteMappingManager {
/**
* 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
*/
@@ -73,9 +73,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
*/
@@ -92,10 +92,12 @@ public class InviteController extends BaseController {
invite.setItem(null);
invite.setNote(null);
invite.setOwner(null);
invite.setRedeemedBy(null);
} else if (!getCurrentUserId().equals(invite.getOwner())) {
invite.setCode(null);
invite.setCodeLink(null);
invite.setOwner(null);
invite.setRedeemedBy(null);
if (!permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
invite.setNote(null);
}
@@ -201,6 +203,8 @@ public class InviteController extends BaseController {
User user = userManager.create(userModel.getUsername(), userModel.getPassword(),
userModel.getStatus());
Long userId = user.getId();
for (UserProfileField userProfileField : userModel.getProfileFields()) {
userProfileField.setTarget(user.getId());
if (userProfileField.getType() == null) {
@@ -214,11 +218,42 @@ public class InviteController extends BaseController {
userProfileField = userProfileFieldManager.save(userProfileField);
}
permissionManager.applyItem(user.getId(), invite.getItem(), new JsonArray(),
invite.getStarts(), invite.getExpires());
quotaManager.applyItem(user.getId(), invite.getItem());
permissionManager.applyItem(userId, invite.getItem(), new JsonArray(), invite.getStarts(),
invite.getExpires());
quotaManager.applyItem(userId, invite.getItem());
invite.setRedeemed(true);
invite.setRedeemedBy(userId);
inviteManager.save(invite);
}
/**
* Redeem.
*
* @param code the code
*/
@PreAuthorize("isAuthenticated()")
@PostMapping("redeem")
public void redeem(@RequestBody String code) {
Invite invite = inviteManager.getByCode(code);
if (invite == null) {
throw new EntityResponseStatusException(HttpStatus.NOT_ACCEPTABLE);
}
if (invite.isRedeemed()
|| invite.getExpires() != null && invite.getExpires().isBefore(Instant.now())) {
throw new EntityResponseStatusException(HttpStatus.GONE);
}
Long userId = getCurrentUserId();
permissionManager.applyItem(userId, invite.getItem(), new JsonArray(), invite.getStarts(),
invite.getExpires());
quotaManager.applyItem(userId, invite.getItem());
invite.setRedeemed(true);
invite.setRedeemedBy(userId);
inviteManager.save(invite);
}
@@ -283,6 +318,7 @@ public class InviteController extends BaseController {
invite.setCodeLink(null);
invite.setMessage(null);
invite.setOwner(null);
invite.setRedeemedBy(null);
}
return page;
@@ -36,6 +36,7 @@ public class Invite implements UserData {
private String message;
private String note;
private boolean redeemed;
private Long redeemedBy;
private String codeLink;
private String url;
@@ -219,6 +220,24 @@ public class Invite implements UserData {
this.redeemed = redeemed;
}
/**
* Gets the redeemed by.
*
* @return the redeemed by
*/
public Long getRedeemedBy() {
return redeemedBy;
}
/**
* Sets the redeemed by.
*
* @param redeemedBy the new redeemed by
*/
public void setRedeemedBy(Long redeemedBy) {
this.redeemedBy = redeemedBy;
}
/**
* Gets the code link.
*