parent
1221e957a2
commit
c865113bb6
|
|
@ -59,6 +59,7 @@ import javax.persistence.NamedQueries;
|
||||||
import javax.persistence.NamedQuery;
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.NamedSubgraph;
|
import javax.persistence.NamedSubgraph;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.OrderBy;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
@ -186,6 +187,7 @@ public class User extends Party implements Serializable, Exportable {
|
||||||
* Additional email addresses of the user.
|
* Additional email addresses of the user.
|
||||||
*/
|
*/
|
||||||
@ElementCollection(fetch = FetchType.EAGER)
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
|
@OrderBy("address")
|
||||||
@CollectionTable(name = "USER_EMAIL_ADDRESSES",
|
@CollectionTable(name = "USER_EMAIL_ADDRESSES",
|
||||||
schema = DB_SCHEMA,
|
schema = DB_SCHEMA,
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
|
|
@ -363,7 +365,8 @@ public class User extends Party implements Serializable, Exportable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonObjectBuilder buildJson() {
|
public JsonObjectBuilder buildJson() {
|
||||||
final JsonArrayBuilder emailAddressesArrayBuilder = Json.createArrayBuilder();
|
final JsonArrayBuilder emailAddressesArrayBuilder = Json
|
||||||
|
.createArrayBuilder();
|
||||||
|
|
||||||
emailAddresses
|
emailAddresses
|
||||||
.stream()
|
.stream()
|
||||||
|
|
@ -375,24 +378,24 @@ public class User extends Party implements Serializable, Exportable {
|
||||||
.add("givenName", givenName)
|
.add("givenName", givenName)
|
||||||
.add("familyName", familyName)
|
.add("familyName", familyName)
|
||||||
.add("primaryEmailAddress", primaryEmailAddress.buildJson())
|
.add("primaryEmailAddress", primaryEmailAddress.buildJson())
|
||||||
.add(
|
.add(
|
||||||
"emailAddresses",
|
"emailAddresses",
|
||||||
emailAddresses
|
emailAddresses
|
||||||
.stream()
|
.stream()
|
||||||
.map(EmailAddress::buildJson)
|
.map(EmailAddress::buildJson)
|
||||||
.map(JsonObjectBuilder::build)
|
.map(JsonObjectBuilder::build)
|
||||||
.collect(new JsonArrayCollector())
|
.collect(new JsonArrayCollector())
|
||||||
)
|
)
|
||||||
.add("banned", banned)
|
.add("banned", banned)
|
||||||
.add("passwordResetRequired", passwordResetRequired)
|
.add("passwordResetRequired", passwordResetRequired)
|
||||||
.add(
|
.add(
|
||||||
"groupMemberships",
|
"groupMemberships",
|
||||||
groupMemberships
|
groupMemberships
|
||||||
.stream()
|
.stream()
|
||||||
.map(GroupMembership::buildJson)
|
.map(GroupMembership::buildJson)
|
||||||
.map(JsonObjectBuilder::build)
|
.map(JsonObjectBuilder::build)
|
||||||
.collect(new JsonArrayCollector())
|
.collect(new JsonArrayCollector())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,9 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.mvc.Controller;
|
import javax.mvc.Controller;
|
||||||
import javax.mvc.Models;
|
import javax.mvc.Models;
|
||||||
import javax.mvc.binding.MvcBinding;
|
import javax.mvc.binding.BindingResult;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
@ -53,12 +50,16 @@ import javax.ws.rs.PathParam;
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Controller
|
@Controller
|
||||||
@Path("/users-groups-roles/users/{userIdentifier}/email-addresses")
|
@Path(
|
||||||
|
"/users-groups-roles/users/{userIdentifier}/email-addresses/{emailIdentifier}/save")
|
||||||
public class EmailFormController {
|
public class EmailFormController {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private AdminMessages adminMessages;
|
private AdminMessages adminMessages;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BindingResult bindingResult;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EmailFormModel emailFormModel;
|
private EmailFormModel emailFormModel;
|
||||||
|
|
||||||
|
|
@ -74,40 +75,27 @@ public class EmailFormController {
|
||||||
@Inject
|
@Inject
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
// MVC does not work with Krazo 1.1.0-M1
|
||||||
// @MvcBinding
|
// @MvcBinding
|
||||||
// @FormParam("address")
|
@FormParam("address")
|
||||||
// @NotBlank
|
// @NotBlank
|
||||||
// @Email
|
// @Email
|
||||||
// private String address;
|
private String address;
|
||||||
//
|
|
||||||
// @FormParam("bouncing")
|
|
||||||
// private boolean bouncing;
|
|
||||||
//
|
|
||||||
// @FormParam("verified")
|
|
||||||
// private boolean verified;
|
|
||||||
|
|
||||||
@GET
|
@FormParam("bouncing")
|
||||||
@Path("/new")
|
private String bouncingParam;
|
||||||
@AuthorizationRequired
|
|
||||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
@FormParam("verified")
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
private String verifiedParam;
|
||||||
public String getNewEmailAddressForm(
|
|
||||||
@PathParam("userIdentifier") final String userIdentifierParam
|
|
||||||
) {
|
|
||||||
emailFormModel.setUserIdentifier(userIdentifierParam);
|
|
||||||
emailFormModel.setAddress("example@example.org");
|
|
||||||
emailFormModel.setBouncing(false);
|
|
||||||
emailFormModel.setVerified(false);
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/new")
|
@Path("/")
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String addNewEmailAddress(
|
public String saveEmailAddress(
|
||||||
@PathParam("userIdentifier") final String userIdentifierParam
|
@PathParam("userIdentifier") final String userIdentifierParam,
|
||||||
|
@PathParam("emailIdentifier") final String emailIdentifierParam
|
||||||
) {
|
) {
|
||||||
final Identifier identifier = identifierParser.parseIdentifier(
|
final Identifier identifier = identifierParser.parseIdentifier(
|
||||||
userIdentifierParam
|
userIdentifierParam
|
||||||
|
|
@ -132,11 +120,86 @@ public class EmailFormController {
|
||||||
if (result.isPresent()) {
|
if (result.isPresent()) {
|
||||||
final User user = result.get();
|
final User user = result.get();
|
||||||
|
|
||||||
final EmailAddress emailAddress = new EmailAddress();
|
// MVC Binding does not work with Krazo 1.1.0-M1
|
||||||
emailAddress.setAddress(emailFormModel.getAddress());
|
// if (bindingResult.isFailed()) {
|
||||||
emailAddress.setBouncing(emailAddress.isBouncing());
|
// models.put("errors", bindingResult.getAllMessages());
|
||||||
emailAddress.setVerified(emailFormModel.isVerified());
|
// emailFormModel.setUserIdentifier(userIdentifierParam);
|
||||||
user.addEmailAddress(emailAddress);
|
// emailFormModel.setAddress(address);
|
||||||
|
// emailFormModel.setBouncing(bouncing);
|
||||||
|
// emailFormModel.setVerified(verified);
|
||||||
|
//
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
// }
|
||||||
|
if (address == null || address.matches("\\s*")) {
|
||||||
|
emailFormModel.addMessage(
|
||||||
|
new Message(
|
||||||
|
"usergroupsroles.users.user_details.email_addresses.errors.address_empty",
|
||||||
|
MessageType.DANGER)
|
||||||
|
);
|
||||||
|
emailFormModel.setUserIdentifier(userIdentifierParam);
|
||||||
|
emailFormModel.setAddress(address);
|
||||||
|
emailFormModel.setBouncing(bouncingParam != null);
|
||||||
|
emailFormModel.setVerified(verifiedParam != null);
|
||||||
|
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("new".equals(emailIdentifierParam)) {
|
||||||
|
return addEmailAddress(user);
|
||||||
|
} else {
|
||||||
|
return updateEmailAddress(
|
||||||
|
userIdentifierParam,
|
||||||
|
user,
|
||||||
|
Integer.parseInt(emailIdentifierParam)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
userDetailsModel.addMessage(
|
||||||
|
new Message(
|
||||||
|
adminMessages.getMessage(
|
||||||
|
"usersgroupsroles.users.not_found.message",
|
||||||
|
Arrays.asList(userIdentifierParam)
|
||||||
|
),
|
||||||
|
MessageType.WARNING
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String addEmailAddress(final User user) {
|
||||||
|
final EmailAddress emailAddress = new EmailAddress();
|
||||||
|
emailAddress.setAddress(address);
|
||||||
|
emailAddress.setBouncing(bouncingParam != null);
|
||||||
|
emailAddress.setVerified(verifiedParam != null);
|
||||||
|
user.addEmailAddress(emailAddress);
|
||||||
|
|
||||||
|
userRepository.save(user);
|
||||||
|
|
||||||
|
return String.format(
|
||||||
|
"redirect:/users-groups-roles/users/%s/details",
|
||||||
|
user.getName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String updateEmailAddress(
|
||||||
|
final String userIdentifierParam,
|
||||||
|
final User user,
|
||||||
|
final int emailId
|
||||||
|
) {
|
||||||
|
if (user.getEmailAddresses().size() <= emailId) {
|
||||||
|
models.put("error.userIdentifier", userIdentifierParam);
|
||||||
|
models.put("error.emailId", emailId);
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/email-not-found.xhtml";
|
||||||
|
} else {
|
||||||
|
final EmailAddress emailAddress = user
|
||||||
|
.getEmailAddresses()
|
||||||
|
.get(emailId);
|
||||||
|
|
||||||
|
emailAddress.setAddress(address);
|
||||||
|
emailAddress.setBouncing(bouncingParam != null);
|
||||||
|
emailAddress.setVerified(verifiedParam != null);
|
||||||
|
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
|
|
||||||
|
|
@ -144,143 +207,148 @@ public class EmailFormController {
|
||||||
"redirect:/users-groups-roles/users/%s/details",
|
"redirect:/users-groups-roles/users/%s/details",
|
||||||
user.getName()
|
user.getName()
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
userDetailsModel.addMessage(
|
|
||||||
new Message(
|
|
||||||
adminMessages.getMessage(
|
|
||||||
"usersgroupsroles.users.not_found.message",
|
|
||||||
Arrays.asList(userIdentifierParam)
|
|
||||||
),
|
|
||||||
MessageType.WARNING
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/{emailId}")
|
|
||||||
@AuthorizationRequired
|
|
||||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String getEditEmailAddressForm(
|
|
||||||
@PathParam("userIdentifier") final String userIdentifierParam,
|
|
||||||
@PathParam("emailId") final int emailId
|
|
||||||
) {
|
|
||||||
final Identifier identifier = identifierParser.parseIdentifier(
|
|
||||||
userIdentifierParam
|
|
||||||
);
|
|
||||||
final Optional<User> result;
|
|
||||||
switch (identifier.getType()) {
|
|
||||||
case ID:
|
|
||||||
result = userRepository.findById(
|
|
||||||
Long.parseLong(identifier.getIdentifier())
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case UUID:
|
|
||||||
result = userRepository.findByUuid(
|
|
||||||
identifier.getIdentifier()
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
result = userRepository.findByName(identifier.getIdentifier());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.isPresent()) {
|
|
||||||
final User user = result.get();
|
|
||||||
|
|
||||||
if (user.getEmailAddresses().size() <= emailId) {
|
|
||||||
models.put("error.userIdentifier", userIdentifierParam);
|
|
||||||
models.put("error.emailId", emailId);
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/email-not-found.xhtml";
|
|
||||||
} else {
|
|
||||||
final EmailAddress emailAddress = user
|
|
||||||
.getEmailAddresses()
|
|
||||||
.get(emailId);
|
|
||||||
emailFormModel.setEmailId(emailId);
|
|
||||||
emailFormModel.setAddress(emailAddress.getAddress());
|
|
||||||
emailFormModel.setBouncing(emailAddress.isBouncing());
|
|
||||||
emailFormModel.setVerified(emailAddress.isVerified());
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
userDetailsModel.addMessage(
|
|
||||||
new Message(
|
|
||||||
adminMessages.getMessage(
|
|
||||||
"usersgroupsroles.users.not_found.message",
|
|
||||||
Arrays.asList(userIdentifierParam)
|
|
||||||
),
|
|
||||||
MessageType.WARNING
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
|
||||||
@Path("/{emailId}")
|
|
||||||
@AuthorizationRequired
|
|
||||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String updateEmailAddress(
|
|
||||||
@PathParam("userIdentifier") final String userIdentifierParam,
|
|
||||||
@PathParam("emailId") final int emailId
|
|
||||||
) {
|
|
||||||
final Identifier identifier = identifierParser.parseIdentifier(
|
|
||||||
userIdentifierParam
|
|
||||||
);
|
|
||||||
final Optional<User> result;
|
|
||||||
switch (identifier.getType()) {
|
|
||||||
case ID:
|
|
||||||
result = userRepository.findById(
|
|
||||||
Long.parseLong(identifier.getIdentifier())
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case UUID:
|
|
||||||
result = userRepository.findByUuid(
|
|
||||||
identifier.getIdentifier()
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
result = userRepository.findByName(identifier.getIdentifier());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.isPresent()) {
|
|
||||||
final User user = result.get();
|
|
||||||
|
|
||||||
if (user.getEmailAddresses().size() <= emailId) {
|
|
||||||
models.put("error.userIdentifier", userIdentifierParam);
|
|
||||||
models.put("error.emailId", emailId);
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/email-not-found.xhtml";
|
|
||||||
} else {
|
|
||||||
final EmailAddress emailAddress = user
|
|
||||||
.getEmailAddresses()
|
|
||||||
.get(emailId);
|
|
||||||
|
|
||||||
emailAddress.setAddress(emailFormModel.getAddress());
|
|
||||||
emailAddress.setBouncing(emailFormModel.isBouncing());
|
|
||||||
emailAddress.setVerified(emailFormModel.isVerified());
|
|
||||||
|
|
||||||
userRepository.save(user);
|
|
||||||
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
userDetailsModel.addMessage(
|
|
||||||
new Message(
|
|
||||||
adminMessages.getMessage(
|
|
||||||
"usersgroupsroles.users.not_found.message",
|
|
||||||
Arrays.asList(userIdentifierParam)
|
|
||||||
),
|
|
||||||
MessageType.WARNING
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @POST
|
||||||
|
// @Path("/users-groups-roles/users/{userIdentifier}/email-addresses/new")
|
||||||
|
// @AuthorizationRequired
|
||||||
|
// @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||||
|
// @Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
// public String addNewEmailAddress(
|
||||||
|
// @PathParam("userIdentifier") final String userIdentifierParam
|
||||||
|
// ) {
|
||||||
|
// final Identifier identifier = identifierParser.parseIdentifier(
|
||||||
|
// userIdentifierParam
|
||||||
|
// );
|
||||||
|
// final Optional<User> result;
|
||||||
|
// switch (identifier.getType()) {
|
||||||
|
// case ID:
|
||||||
|
// result = userRepository.findById(
|
||||||
|
// Long.parseLong(identifier.getIdentifier())
|
||||||
|
// );
|
||||||
|
// break;
|
||||||
|
// case UUID:
|
||||||
|
// result = userRepository.findByUuid(
|
||||||
|
// identifier.getIdentifier()
|
||||||
|
// );
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// result = userRepository.findByName(identifier.getIdentifier());
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (result.isPresent()) {
|
||||||
|
// final User user = result.get();
|
||||||
|
//
|
||||||
|
// if (bindingResult.isFailed()) {
|
||||||
|
// models.put("errors", bindingResult.getAllMessages());
|
||||||
|
// emailFormModel.setUserIdentifier(userIdentifierParam);
|
||||||
|
// emailFormModel.setAddress(address);
|
||||||
|
// emailFormModel.setBouncing(bouncing);
|
||||||
|
// emailFormModel.setVerified(verified);
|
||||||
|
//
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// final EmailAddress emailAddress = new EmailAddress();
|
||||||
|
// emailAddress.setAddress(address);
|
||||||
|
// emailAddress.setBouncing(bouncing);
|
||||||
|
// emailAddress.setVerified(verified);
|
||||||
|
// user.addEmailAddress(emailAddress);
|
||||||
|
//
|
||||||
|
// userRepository.save(user);
|
||||||
|
//
|
||||||
|
// return String.format(
|
||||||
|
// "redirect:/users-groups-roles/users/%s/details",
|
||||||
|
// user.getName()
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// userDetailsModel.addMessage(
|
||||||
|
// new Message(
|
||||||
|
// adminMessages.getMessage(
|
||||||
|
// "usersgroupsroles.users.not_found.message",
|
||||||
|
// Arrays.asList(userIdentifierParam)
|
||||||
|
// ),
|
||||||
|
// MessageType.WARNING
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @POST
|
||||||
|
// @Path("/users-groups-roles/users/{userIdentifier}/email-addresses/{emailId}")
|
||||||
|
// @AuthorizationRequired
|
||||||
|
// @RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||||
|
// @Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
// public String updateEmailAddress(
|
||||||
|
// @PathParam("userIdentifier") final String userIdentifierParam,
|
||||||
|
// @PathParam("emailId") final int emailId
|
||||||
|
// ) {
|
||||||
|
// final Identifier identifier = identifierParser.parseIdentifier(
|
||||||
|
// userIdentifierParam
|
||||||
|
// );
|
||||||
|
// final Optional<User> result;
|
||||||
|
// switch (identifier.getType()) {
|
||||||
|
// case ID:
|
||||||
|
// result = userRepository.findById(
|
||||||
|
// Long.parseLong(identifier.getIdentifier())
|
||||||
|
// );
|
||||||
|
// break;
|
||||||
|
// case UUID:
|
||||||
|
// result = userRepository.findByUuid(
|
||||||
|
// identifier.getIdentifier()
|
||||||
|
// );
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// result = userRepository.findByName(identifier.getIdentifier());
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (result.isPresent()) {
|
||||||
|
// final User user = result.get();
|
||||||
|
//
|
||||||
|
// if (bindingResult.isFailed()) {
|
||||||
|
// models.put("errors", bindingResult.getAllMessages());
|
||||||
|
// emailFormModel.setUserIdentifier(userIdentifierParam);
|
||||||
|
// emailFormModel.setEmailId(emailId);
|
||||||
|
// emailFormModel.setAddress(address);
|
||||||
|
// emailFormModel.setBouncing(bouncing);
|
||||||
|
// emailFormModel.setVerified(verified);
|
||||||
|
//
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (user.getEmailAddresses().size() <= emailId) {
|
||||||
|
// models.put("error.userIdentifier", userIdentifierParam);
|
||||||
|
// models.put("error.emailId", emailId);
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/email-not-found.xhtml";
|
||||||
|
// } else {
|
||||||
|
// final EmailAddress emailAddress = user
|
||||||
|
// .getEmailAddresses()
|
||||||
|
// .get(emailId);
|
||||||
|
//
|
||||||
|
// emailAddress.setAddress(address);
|
||||||
|
// emailAddress.setBouncing(bouncing);
|
||||||
|
// emailAddress.setVerified(verified);
|
||||||
|
//
|
||||||
|
// userRepository.save(user);
|
||||||
|
//
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// userDetailsModel.addMessage(
|
||||||
|
// new Message(
|
||||||
|
// adminMessages.getMessage(
|
||||||
|
// "usersgroupsroles.users.not_found.message",
|
||||||
|
// Arrays.asList(userIdentifierParam)
|
||||||
|
// ),
|
||||||
|
// MessageType.WARNING
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@
|
||||||
package org.libreccm.ui.admin.usersgroupsroles;
|
package org.libreccm.ui.admin.usersgroupsroles;
|
||||||
|
|
||||||
import org.libreccm.core.EmailAddress;
|
import org.libreccm.core.EmailAddress;
|
||||||
|
import org.libreccm.ui.Message;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
@ -41,6 +46,24 @@ public class EmailFormModel {
|
||||||
|
|
||||||
private boolean verified;
|
private boolean verified;
|
||||||
|
|
||||||
|
private List<Message> messages;
|
||||||
|
|
||||||
|
public EmailFormModel() {
|
||||||
|
this.messages = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Message> getMessages() {
|
||||||
|
return Collections.unmodifiableList(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMessage(final Message message) {
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessages(final List<Message> messages) {
|
||||||
|
this.messages = new ArrayList<>(messages);
|
||||||
|
}
|
||||||
|
|
||||||
public void setEmailAddress(
|
public void setEmailAddress(
|
||||||
final String userIdentifier,
|
final String userIdentifier,
|
||||||
final int emailId,
|
final int emailId,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package org.libreccm.ui.admin.usersgroupsroles;
|
||||||
import org.libreccm.api.Identifier;
|
import org.libreccm.api.Identifier;
|
||||||
import org.libreccm.api.IdentifierParser;
|
import org.libreccm.api.IdentifierParser;
|
||||||
import org.libreccm.core.CoreConstants;
|
import org.libreccm.core.CoreConstants;
|
||||||
|
import org.libreccm.core.EmailAddress;
|
||||||
import org.libreccm.security.AuthorizationRequired;
|
import org.libreccm.security.AuthorizationRequired;
|
||||||
import org.libreccm.security.RequiresPrivilege;
|
import org.libreccm.security.RequiresPrivilege;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
|
|
@ -35,6 +36,7 @@ import java.util.Optional;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.mvc.Controller;
|
import javax.mvc.Controller;
|
||||||
|
import javax.mvc.Models;
|
||||||
import javax.mvc.MvcContext;
|
import javax.mvc.MvcContext;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
|
|
@ -57,9 +59,15 @@ public class UsersController {
|
||||||
@Inject
|
@Inject
|
||||||
private AdminMessages adminMessages;
|
private AdminMessages adminMessages;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EmailFormModel emailFormModel;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private IdentifierParser identifierParser;
|
private IdentifierParser identifierParser;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Models models;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private MvcContext mvc;
|
private MvcContext mvc;
|
||||||
|
|
||||||
|
|
@ -233,6 +241,80 @@ public class UsersController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{userIdentifier}/email-addresses/new")
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String getNewEmailAddressForm(
|
||||||
|
@PathParam("userIdentifier") final String userIdentifierParam
|
||||||
|
) {
|
||||||
|
emailFormModel.setUserIdentifier(userIdentifierParam);
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{userIdentifier}/email-addresses/{emailId}")
|
||||||
|
@AuthorizationRequired
|
||||||
|
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public String getEditEmailAddressForm(
|
||||||
|
@PathParam("userIdentifier") final String userIdentifierParam,
|
||||||
|
@PathParam("emailId") final int emailId
|
||||||
|
) {
|
||||||
|
final Identifier identifier = identifierParser.parseIdentifier(
|
||||||
|
userIdentifierParam
|
||||||
|
);
|
||||||
|
final Optional<User> result;
|
||||||
|
switch (identifier.getType()) {
|
||||||
|
case ID:
|
||||||
|
result = userRepository.findById(
|
||||||
|
Long.parseLong(identifier.getIdentifier())
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case UUID:
|
||||||
|
result = userRepository.findByUuid(
|
||||||
|
identifier.getIdentifier()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result = userRepository.findByName(identifier.getIdentifier());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.isPresent()) {
|
||||||
|
final User user = result.get();
|
||||||
|
|
||||||
|
if (user.getEmailAddresses().size() <= emailId) {
|
||||||
|
models.put("errorUserIdentifier", userIdentifierParam);
|
||||||
|
models.put("errorEmailId", emailId);
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/email-not-found.xhtml";
|
||||||
|
} else {
|
||||||
|
final EmailAddress emailAddress = user
|
||||||
|
.getEmailAddresses()
|
||||||
|
.get(emailId);
|
||||||
|
emailFormModel.setUserIdentifier(userIdentifierParam);
|
||||||
|
emailFormModel.setEmailId(emailId);
|
||||||
|
emailFormModel.setAddress(emailAddress.getAddress());
|
||||||
|
emailFormModel.setBouncing(emailAddress.isBouncing());
|
||||||
|
emailFormModel.setVerified(emailAddress.isVerified());
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/email-form.xhtml";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userDetailsModel.addMessage(
|
||||||
|
new Message(
|
||||||
|
adminMessages.getMessage(
|
||||||
|
"usersgroupsroles.users.not_found.message",
|
||||||
|
Arrays.asList(userIdentifierParam)
|
||||||
|
),
|
||||||
|
MessageType.WARNING
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return "org/libreccm/ui/admin/users-groups-roles/user-not-found.xhtml";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/{userIdentifier}/email-addresses/{emailId}/remove")
|
@Path("/{userIdentifier}/email-addresses/{emailId}/remove")
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<ui:param name="activePage" value="usersgroupsroles" />
|
<ui:param name="activePage" value="usersgroupsroles" />
|
||||||
<ui:param name="activePanel" value="users" />
|
<ui:param name="activePanel" value="users" />
|
||||||
<ui:param name="title"
|
<ui:param name="title"
|
||||||
value="#{EmailFormModel.new ? AdminMessages.getMessage('usersgroupsroles.users.email.edit.title', [UserDetailsModel.name]) : AdminMessages['usersgroupsroles.users.email.add.title']}" />
|
value="#{EmailFormModel.new ? AdminMessages['usersgroupsroles.users.email.add.title'] : AdminMessages.getMessage('usersgroupsroles.users.email.edit.title', [UserDetailsModel.name])}" />
|
||||||
|
|
||||||
<ui:define name="breadcrumb">
|
<ui:define name="breadcrumb">
|
||||||
<li class="breadcrumb-item">
|
<li class="breadcrumb-item">
|
||||||
|
|
@ -36,7 +36,12 @@
|
||||||
#{error}
|
#{error}
|
||||||
</div>
|
</div>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
<form action="#{EmailFormModel.new ? mvc.uri('EmailFormController#addNewEmailAddress', {'userIdentifier': EmailFormModel.userIdentifier }) : mvc.uri('EmailFormController#updateEmailAddress', { 'userIdentifier': EmailFormController.userIdentifier, 'emailId': EmailFormModel.emailId })}"
|
<c:forEach items="#{EmailFormModel.messages}" var="message">
|
||||||
|
<div class="alert alert-#{message.messageType}" role="alert">
|
||||||
|
#{AdminMessages[message]}
|
||||||
|
</div>
|
||||||
|
</c:forEach>
|
||||||
|
<form action="#{EmailFormModel.new ? mvc.uri('EmailFormController#saveEmailAddress', {'userIdentifier': EmailFormModel.userIdentifier, 'emailIdentifier': 'new' }) : mvc.uri('EmailFormController#saveEmailAddress', { 'userIdentifier': EmailFormController.userIdentifier, 'emailIdentifier': EmailFormModel.emailId })}"
|
||||||
method="post">
|
method="post">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="address">
|
<label for="address">
|
||||||
|
|
@ -46,6 +51,7 @@
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="address"
|
id="address"
|
||||||
name="address"
|
name="address"
|
||||||
|
required="required"
|
||||||
value="#{EmailFormModel.address}"
|
value="#{EmailFormModel.address}"
|
||||||
type="email" />
|
type="email" />
|
||||||
<small class="form-text text-muted"
|
<small class="form-text text-muted"
|
||||||
|
|
@ -54,7 +60,8 @@
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input"
|
<input checked="#{EmailFormModel.bouncing ? 'checked' : ''}"
|
||||||
|
class="form-check-input"
|
||||||
id="bouncing"
|
id="bouncing"
|
||||||
name="bouncing"
|
name="bouncing"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|
@ -64,11 +71,11 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input"
|
<input checked="#{EmailFormModel.verified ? 'checked' : ''}"
|
||||||
|
class="form-check-input"
|
||||||
id="verified"
|
id="verified"
|
||||||
name="verified"
|
name="verified"
|
||||||
type="checkbox"
|
type="checkbox" />
|
||||||
value="#{EmailFormModel.verified}" />
|
|
||||||
<label for="verified">
|
<label for="verified">
|
||||||
#{AdminMessages['usersgroupsroles.users.email.form.verified.label']}
|
#{AdminMessages['usersgroupsroles.users.email.form.verified.label']}
|
||||||
</label>
|
</label>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<ui:param name="activePage" value="usersgroupsroles" />
|
<ui:param name="activePage" value="usersgroupsroles" />
|
||||||
<ui:param name="activePanel" value="users" />
|
<ui:param name="activePanel" value="users" />
|
||||||
<ui:param name="title"
|
<ui:param name="title"
|
||||||
value="#{AdminMessages('usersgroupsroles.users.email.not_found.title')}" />
|
value="#{AdminMessages['usersgroupsroles.users.email.not_found.title']}" />
|
||||||
|
|
||||||
<ui:define name="breadcrumb">
|
<ui:define name="breadcrumb">
|
||||||
<li class="breadcrumb-item">
|
<li class="breadcrumb-item">
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
<ui:define name="panel">
|
<ui:define name="panel">
|
||||||
|
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
#{AdminMessages.getMessage('usersgroupsroles.users.email.not_found.message', [models['errors.userIdentifier'], models['errors.emailId']])}
|
#{AdminMessages.getMessage('usersgroupsroles.users.email.not_found.message', [errorUserIdentifier, errorEmailId])}
|
||||||
</div>
|
</div>
|
||||||
</ui:define>
|
</ui:define>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@
|
||||||
</h2>
|
</h2>
|
||||||
<div>
|
<div>
|
||||||
<a class="btn btn-primary"
|
<a class="btn btn-primary"
|
||||||
href="#{mvc.uri('EmailFormController#getNewEmailAddressForm', {'userIdentifier': UserDetailsModel.name })}">
|
href="#{mvc.uri('UsersController#getNewEmailAddressForm', {'userIdentifier': UserDetailsModel.name })}">
|
||||||
<svg class="bi"
|
<svg class="bi"
|
||||||
width="1em"
|
width="1em"
|
||||||
height="1em"
|
height="1em"
|
||||||
|
|
@ -195,7 +195,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-info"
|
<a class="btn btn-info"
|
||||||
href="#{mvc.uri('UsersController#removeEmailAddress', { 'userIdentifier': UserDetailsModel.name, 'emailId': status.index })}">
|
href="#{mvc.uri('UsersController#getEditEmailAddressForm', { 'userIdentifier': UserDetailsModel.name, 'emailId': status.index })}">
|
||||||
<svg class="bi"
|
<svg class="bi"
|
||||||
width="1em"
|
width="1em"
|
||||||
height="1em"
|
height="1em"
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
<ui:define name="panel">
|
<ui:define name="panel">
|
||||||
<c:forEach items="#{UserDetailsModel.messages}" var="message">
|
<c:forEach items="#{UserDetailsModel.messages}" var="message">
|
||||||
<div class="alert alert-#{message.type}" role="alert">
|
<div class="alert alert-#{message.messageType}" role="alert">
|
||||||
#{message}
|
#{message}
|
||||||
</div>
|
</div>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
|
|
||||||
|
|
@ -128,3 +128,4 @@ usersgroupsroles.users.user_details.roles.dialog.title=Edit role memberships
|
||||||
usersgroupsroles.users.user_details.roles.dialog.close=Cancel
|
usersgroupsroles.users.user_details.roles.dialog.close=Cancel
|
||||||
usersgroupsroles.users.user_details.groups.dialog.save=Save
|
usersgroupsroles.users.user_details.groups.dialog.save=Save
|
||||||
usergroupsroles.users.user_details.family_name=Family Name
|
usergroupsroles.users.user_details.family_name=Family Name
|
||||||
|
usergroupsroles.users.user_details.email_addresses.errors.address_empty=Address can't be empty
|
||||||
|
|
|
||||||
|
|
@ -128,3 +128,4 @@ usersgroupsroles.users.user_details.roles.dialog.title=Rollenmitgliedschaften be
|
||||||
usersgroupsroles.users.user_details.roles.dialog.close=Abbrechen
|
usersgroupsroles.users.user_details.roles.dialog.close=Abbrechen
|
||||||
usersgroupsroles.users.user_details.groups.dialog.save=Anwenden
|
usersgroupsroles.users.user_details.groups.dialog.save=Anwenden
|
||||||
usergroupsroles.users.user_details.family_name=Familienname
|
usergroupsroles.users.user_details.family_name=Familienname
|
||||||
|
usergroupsroles.users.user_details.email_addresses.errors.address_empty=Die Addresse kann nicht leer sein
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue