update invite, keep public key
This commit is contained in:
@@ -85,6 +85,8 @@ public class PermissionMappingManager {
|
|||||||
* @param lifetimeRound the lifetime round
|
* @param lifetimeRound the lifetime round
|
||||||
* @param addon the addon
|
* @param addon the addon
|
||||||
* @param product the product
|
* @param product the product
|
||||||
|
* @param starts the starts
|
||||||
|
* @param expires the expires
|
||||||
* @param startsQuestion the starts question
|
* @param startsQuestion the starts question
|
||||||
* @param expiresQuestion the expires question
|
* @param expiresQuestion the expires question
|
||||||
* @return the permission mapping
|
* @return the permission mapping
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ public class SystemPropertyManager {
|
|||||||
systemPropertyRepository.save(systemProperty);
|
systemPropertyRepository.save(systemProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
public void set(String key, String value) {
|
public void set(String key, String value) {
|
||||||
if (systemPropertyRepository.existsById(key)) {
|
if (systemPropertyRepository.existsById(key)) {
|
||||||
update(key, value);
|
update(key, value);
|
||||||
|
|||||||
@@ -267,6 +267,7 @@ public class UserManager implements UserDataProvider {
|
|||||||
* @param outputStream the output stream
|
* @param outputStream the output stream
|
||||||
*/
|
*/
|
||||||
public void passwordReset(User user, ServletOutputStream outputStream) {
|
public void passwordReset(User user, ServletOutputStream outputStream) {
|
||||||
|
// TODO: change to public key profile field
|
||||||
String resetToken = RandomStringUtils.random(64, true, true);
|
String resetToken = RandomStringUtils.random(64, true, true);
|
||||||
String command = "echo \""
|
String command = "echo \""
|
||||||
+ resetToken
|
+ resetToken
|
||||||
|
|||||||
@@ -100,7 +100,11 @@ public class UserProfileFieldManager implements UserDataProvider {
|
|||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
userProfileFieldRepository.exists(
|
userProfileFieldRepository.exists(
|
||||||
qUserProfileField.target.eq(target).and(qUserProfileField.name.eq(name))),
|
qUserProfileField.target.eq(target).and(qUserProfileField.name.eq(name))),
|
||||||
"ProfileField '" + name + "' for target + '" + target + "' not exists!");
|
"ProfileField '"
|
||||||
|
+ name
|
||||||
|
+ "' for target + '"
|
||||||
|
+ target
|
||||||
|
+ "' not exists!");
|
||||||
UserProfileField delete = userProfileFieldRepository
|
UserProfileField delete = userProfileFieldRepository
|
||||||
.findOne(qUserProfileField.target.eq(target).and(qUserProfileField.name.eq(name)))
|
.findOne(qUserProfileField.target.eq(target).and(qUserProfileField.name.eq(name)))
|
||||||
.get();
|
.get();
|
||||||
@@ -143,8 +147,10 @@ public class UserProfileFieldManager implements UserDataProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void purgeUserData(Long userId) {
|
public void purgeUserData(Long userId) {
|
||||||
for (UserProfileField userProfileField : getAllByTarget(userId)) {
|
for (UserProfileField userProfileField : getAllByTarget(userId)) {
|
||||||
|
if (!userProfileField.getName().equals(UserProfileFields.PROFILE_FIELD_PUBLIC_KEY)) {
|
||||||
userProfileFieldRepository.delete(userProfileField);
|
userProfileFieldRepository.delete(userProfileField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package de.bstly.we.businesslogic;
|
|||||||
public interface UserProfileFields {
|
public interface UserProfileFields {
|
||||||
|
|
||||||
public static final String PROFILE_FIELD_EMAIL = "email";
|
public static final String PROFILE_FIELD_EMAIL = "email";
|
||||||
|
public static final String PROFILE_FIELD_PUBLIC_KEY = "publicKey";
|
||||||
public static final String PROFILE_FIELD_EMAIL_PRIMARY = "primaryEmail";
|
public static final String PROFILE_FIELD_EMAIL_PRIMARY = "primaryEmail";
|
||||||
public static final String PROFILE_FIELD_LOCALE = "locale";
|
public static final String PROFILE_FIELD_LOCALE = "locale";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,10 +103,10 @@ public class PermissionManagementController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update permission.
|
* Update permissions.
|
||||||
*
|
*
|
||||||
* @param permission the permission
|
* @param permissions the permissions
|
||||||
* @return the permission
|
* @return the list
|
||||||
*/
|
*/
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
@PatchMapping("list")
|
@PatchMapping("list")
|
||||||
|
|||||||
@@ -206,6 +206,8 @@ public class PermissionMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the starts.
|
||||||
|
*
|
||||||
* @return the starts
|
* @return the starts
|
||||||
*/
|
*/
|
||||||
public Instant getStarts() {
|
public Instant getStarts() {
|
||||||
@@ -213,13 +215,17 @@ public class PermissionMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param starts the starts to set
|
* Sets the starts.
|
||||||
|
*
|
||||||
|
* @param starts the new starts
|
||||||
*/
|
*/
|
||||||
public void setStarts(Instant starts) {
|
public void setStarts(Instant starts) {
|
||||||
this.starts = starts;
|
this.starts = starts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the expires.
|
||||||
|
*
|
||||||
* @return the expires
|
* @return the expires
|
||||||
*/
|
*/
|
||||||
public Instant getExpires() {
|
public Instant getExpires() {
|
||||||
@@ -227,7 +233,9 @@ public class PermissionMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param expires the expires to set
|
* Sets the expires.
|
||||||
|
*
|
||||||
|
* @param expires the new expires
|
||||||
*/
|
*/
|
||||||
public void setExpires(Instant expires) {
|
public void setExpires(Instant expires) {
|
||||||
this.expires = expires;
|
this.expires = expires;
|
||||||
@@ -275,6 +283,9 @@ public class PermissionMapping {
|
|||||||
@Converter
|
@Converter
|
||||||
public static class ChronoUnitConverter implements AttributeConverter<ChronoUnit, String> {
|
public static class ChronoUnitConverter implements AttributeConverter<ChronoUnit, String> {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object)
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.
|
* @see javax.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.
|
||||||
* Object)
|
* Object)
|
||||||
@@ -284,6 +295,9 @@ public class PermissionMapping {
|
|||||||
return chronoUnit.name();
|
return chronoUnit.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object)
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.
|
* @see javax.persistence.AttributeConverter#convertToEntityAttribute(java.lang.
|
||||||
* Object)
|
* Object)
|
||||||
|
|||||||
@@ -92,10 +92,12 @@ public class InviteController extends BaseController {
|
|||||||
invite.setItem(null);
|
invite.setItem(null);
|
||||||
invite.setNote(null);
|
invite.setNote(null);
|
||||||
invite.setOwner(null);
|
invite.setOwner(null);
|
||||||
|
invite.setRedeemedBy(null);
|
||||||
} else if (!getCurrentUserId().equals(invite.getOwner())) {
|
} else if (!getCurrentUserId().equals(invite.getOwner())) {
|
||||||
invite.setCode(null);
|
invite.setCode(null);
|
||||||
invite.setCodeLink(null);
|
invite.setCodeLink(null);
|
||||||
invite.setOwner(null);
|
invite.setOwner(null);
|
||||||
|
invite.setRedeemedBy(null);
|
||||||
if (!permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
|
if (!permissionManager.hasPermission(getCurrentUserId(), Permissions.ROLE_MEMBER)) {
|
||||||
invite.setNote(null);
|
invite.setNote(null);
|
||||||
}
|
}
|
||||||
@@ -201,6 +203,8 @@ public class InviteController extends BaseController {
|
|||||||
User user = userManager.create(userModel.getUsername(), userModel.getPassword(),
|
User user = userManager.create(userModel.getUsername(), userModel.getPassword(),
|
||||||
userModel.getStatus());
|
userModel.getStatus());
|
||||||
|
|
||||||
|
Long userId = user.getId();
|
||||||
|
|
||||||
for (UserProfileField userProfileField : userModel.getProfileFields()) {
|
for (UserProfileField userProfileField : userModel.getProfileFields()) {
|
||||||
userProfileField.setTarget(user.getId());
|
userProfileField.setTarget(user.getId());
|
||||||
if (userProfileField.getType() == null) {
|
if (userProfileField.getType() == null) {
|
||||||
@@ -214,11 +218,42 @@ public class InviteController extends BaseController {
|
|||||||
userProfileField = userProfileFieldManager.save(userProfileField);
|
userProfileField = userProfileFieldManager.save(userProfileField);
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionManager.applyItem(user.getId(), invite.getItem(), new JsonArray(),
|
permissionManager.applyItem(userId, invite.getItem(), new JsonArray(), invite.getStarts(),
|
||||||
invite.getStarts(), invite.getExpires());
|
invite.getExpires());
|
||||||
quotaManager.applyItem(user.getId(), invite.getItem());
|
quotaManager.applyItem(userId, invite.getItem());
|
||||||
|
|
||||||
invite.setRedeemed(true);
|
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);
|
inviteManager.save(invite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,6 +318,7 @@ public class InviteController extends BaseController {
|
|||||||
invite.setCodeLink(null);
|
invite.setCodeLink(null);
|
||||||
invite.setMessage(null);
|
invite.setMessage(null);
|
||||||
invite.setOwner(null);
|
invite.setOwner(null);
|
||||||
|
invite.setRedeemedBy(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class Invite implements UserData {
|
|||||||
private String message;
|
private String message;
|
||||||
private String note;
|
private String note;
|
||||||
private boolean redeemed;
|
private boolean redeemed;
|
||||||
|
private Long redeemedBy;
|
||||||
private String codeLink;
|
private String codeLink;
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@@ -219,6 +220,24 @@ public class Invite implements UserData {
|
|||||||
this.redeemed = redeemed;
|
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.
|
* Gets the code link.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>11</java.version>
|
<java.version>11</java.version>
|
||||||
<log4j2.version>2.17.1</log4j2.version>
|
<log4j2.version>2.17.1</log4j2.version>
|
||||||
<revision>1.6.0-SNAPSHOT</revision>
|
<revision>1.6.1-SNAPSHOT</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|||||||
Reference in New Issue
Block a user