mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1646: V1 REST API - cannot unset optional fields (eg. when updating person / site details ...) - minor fixes with tests (update person)
- ensure enabled & emailNotificationsEnabled cannot be null - null/empty company object should unset all fields (fix for empty case) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133351 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -526,10 +526,18 @@ public class PeopleImpl implements People
|
||||
{
|
||||
throw new InvalidArgumentException("Field '"+fieldName+"' is null, but is required.");
|
||||
}
|
||||
|
||||
// belts-and-braces - note: should not see empty string (since converted to null via custom json deserializer)
|
||||
if ((fieldValue instanceof String) && ((String)fieldValue).isEmpty())
|
||||
{
|
||||
throw new InvalidArgumentException("Field '"+fieldName+"' is empty, but is required.");
|
||||
}
|
||||
}
|
||||
|
||||
public Person update(String personId, final Person person)
|
||||
{
|
||||
validateUpdatePersonData(person);
|
||||
|
||||
boolean isAdmin = isAdminAuthority();
|
||||
|
||||
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
@@ -545,6 +553,18 @@ public class PeopleImpl implements People
|
||||
// if requested, update password
|
||||
updatePassword(isAdmin, personIdToUpdate, person);
|
||||
|
||||
if (person.isEnabled() != null)
|
||||
{
|
||||
if (isAdminAuthority(personIdToUpdate))
|
||||
{
|
||||
throw new PermissionDeniedException("Admin authority cannot be disabled.");
|
||||
}
|
||||
|
||||
// note: if current user is not an admin then permission denied exception is thrown
|
||||
MutableAuthenticationService mutableAuthenticationService = (MutableAuthenticationService) authenticationService;
|
||||
mutableAuthenticationService.setAuthenticationEnabled(personIdToUpdate, person.isEnabled());
|
||||
}
|
||||
|
||||
NodeRef personNodeRef = personService.getPerson(personIdToUpdate, false);
|
||||
if (person.wasSet(Person.PROP_PERSON_DESCRIPTION))
|
||||
{
|
||||
@@ -579,6 +599,29 @@ public class PeopleImpl implements People
|
||||
return getPerson(personId);
|
||||
}
|
||||
|
||||
private void validateUpdatePersonData(Person person)
|
||||
{
|
||||
if (person.wasSet(ContentModel.PROP_FIRSTNAME))
|
||||
{
|
||||
checkRequiredField("firstName", person.getFirstName());
|
||||
}
|
||||
|
||||
if (person.wasSet(ContentModel.PROP_EMAIL))
|
||||
{
|
||||
checkRequiredField("email", person.getEmail());
|
||||
}
|
||||
|
||||
if (person.wasSet(ContentModel.PROP_ENABLED) && (person.isEnabled() == null))
|
||||
{
|
||||
throw new IllegalArgumentException("'enabled' field cannot be empty.");
|
||||
}
|
||||
|
||||
if (person.wasSet(ContentModel.PROP_EMAIL_FEED_DISABLED) && (person.isEmailNotificationsEnabled() == null))
|
||||
{
|
||||
throw new IllegalArgumentException("'emailNotificationsEnabled' field cannot be empty.");
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePassword(boolean isAdmin, String personIdToUpdate, Person person)
|
||||
{
|
||||
MutableAuthenticationService mutableAuthenticationService = (MutableAuthenticationService) authenticationService;
|
||||
@@ -626,17 +669,6 @@ public class PeopleImpl implements People
|
||||
mutableAuthenticationService.setAuthentication(personIdToUpdate, newPassword);
|
||||
}
|
||||
}
|
||||
|
||||
if (person.isEnabled() != null)
|
||||
{
|
||||
if (isAdminAuthority(personIdToUpdate))
|
||||
{
|
||||
throw new PermissionDeniedException("Admin authority cannot be disabled.");
|
||||
}
|
||||
|
||||
mutableAuthenticationService.setAuthenticationEnabled(personIdToUpdate, person.isEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isAdminAuthority()
|
||||
|
@@ -493,50 +493,62 @@ public class Person
|
||||
if (wasSet(PROP_PERSON_COMPANY))
|
||||
{
|
||||
Company company = getCompany();
|
||||
|
||||
int setCount = 0;
|
||||
if (company != null)
|
||||
{
|
||||
if (company.wasSet(ContentModel.PROP_ORGANIZATION))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_ORGANIZATION, company.getOrganization());
|
||||
}
|
||||
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYADDRESS1))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS1, company.getAddress1());
|
||||
}
|
||||
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYADDRESS2))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS2, company.getAddress2());
|
||||
}
|
||||
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYADDRESS3))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS3, company.getAddress3());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYPOSTCODE))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYPOSTCODE, company.getPostcode());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYTELEPHONE))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYTELEPHONE, company.getTelephone());
|
||||
}
|
||||
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYFAX))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYFAX, company.getFax());
|
||||
}
|
||||
|
||||
if (company.wasSet(ContentModel.PROP_COMPANYEMAIL))
|
||||
{
|
||||
setCount++;
|
||||
properties.put(ContentModel.PROP_COMPANYEMAIL, company.getEmail());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (setCount == 0)
|
||||
{
|
||||
// company was null or {} (no individual properties set)
|
||||
properties.put(ContentModel.PROP_ORGANIZATION, null);
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS1, null);
|
||||
properties.put(ContentModel.PROP_COMPANYADDRESS2, null);
|
||||
|
Reference in New Issue
Block a user