mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ETHREEOH-158 - invite different users with same email addresses
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13979 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -104,6 +104,9 @@ public class InvitationServiceImpl implements InvitationService
|
||||
// does not already belong to an existing person
|
||||
public static final int MAX_NUM_INVITEE_USER_NAME_GEN_TRIES = 10;
|
||||
|
||||
private int maxUserNameGenRetries = MAX_NUM_INVITEE_USER_NAME_GEN_TRIES;
|
||||
|
||||
|
||||
/**
|
||||
* Checks that all necessary properties and services have been provided.
|
||||
*/
|
||||
@@ -915,7 +918,7 @@ public class InvitationServiceImpl implements InvitationService
|
||||
inviteeUserName = usernameGenerator.generateUserName();
|
||||
i++;
|
||||
} while (this.personService.personExists(inviteeUserName)
|
||||
&& (i < MAX_NUM_INVITEE_USER_NAME_GEN_TRIES));
|
||||
&& (i < getMaxUserNameGenRetries()));
|
||||
|
||||
// if after 10 tries is not able to generate a user name for a
|
||||
// person who doesn't already exist, then throw a web script exception
|
||||
@@ -1125,52 +1128,75 @@ public class InvitationServiceImpl implements InvitationService
|
||||
// if a person already exists who has the given invitee email address
|
||||
//
|
||||
// 1) obtain invitee user name from first person found having the
|
||||
// invitee email address (there
|
||||
// should only be one)
|
||||
// 2) handle error conditions - (invitee already has an invitation in
|
||||
// progress for the given site,
|
||||
// invitee email address, first name and last name
|
||||
// 2) handle error conditions -
|
||||
// (invitee already has an invitation in progress for the given site,
|
||||
// or he/she is already a member of the given site
|
||||
//
|
||||
if (inviteeUserName == null || inviteeUserName.trim().length() == 0) {
|
||||
|
||||
inviteeUserName = null;
|
||||
|
||||
Set<NodeRef> peopleWithInviteeEmail = this.personService
|
||||
.getPeopleFilteredByProperty(ContentModel.PROP_EMAIL,
|
||||
inviteeEmail);
|
||||
if (peopleWithInviteeEmail.isEmpty() == false) {
|
||||
// get person already existing who has the given
|
||||
// invitee email address (there should only be one, so just take
|
||||
// the first from the set of people).
|
||||
NodeRef person = (NodeRef) peopleWithInviteeEmail.toArray()[0];
|
||||
|
||||
if (peopleWithInviteeEmail.size() > 0) {
|
||||
// get person already existing who has the given
|
||||
// invitee email address
|
||||
for(NodeRef personRef : peopleWithInviteeEmail)
|
||||
{
|
||||
Serializable firstNameVal = this.getNodeService().getProperty(personRef, ContentModel.PROP_FIRSTNAME);
|
||||
Serializable lastNameVal = this.getNodeService().getProperty(personRef, ContentModel.PROP_LASTNAME);
|
||||
|
||||
String personFirstName = DefaultTypeConverter.INSTANCE.convert(
|
||||
String.class, firstNameVal);
|
||||
String personLastName = DefaultTypeConverter.INSTANCE.convert(
|
||||
String.class, lastNameVal);
|
||||
|
||||
if(personFirstName != null && personFirstName.equalsIgnoreCase(inviteeFirstName))
|
||||
{
|
||||
if(personLastName != null && personLastName.equalsIgnoreCase(inviteeLastName))
|
||||
{
|
||||
// got a match on email, lastname, firstname
|
||||
// get invitee user name of that person
|
||||
Serializable userNamePropertyVal = this.getNodeService()
|
||||
.getProperty(person, ContentModel.PROP_USERNAME);
|
||||
.getProperty(personRef, ContentModel.PROP_USERNAME);
|
||||
inviteeUserName = DefaultTypeConverter.INSTANCE.convert(
|
||||
String.class, userNamePropertyVal);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger
|
||||
.debug("not explictly passed username - found matching email, resolved inviteeUserName="
|
||||
{
|
||||
logger.debug("not explictly passed username - found matching email, resolved inviteeUserName="
|
||||
+ inviteeUserName);
|
||||
}
|
||||
// else there are no existing people who have the given invitee
|
||||
// email address
|
||||
// so create invitee person
|
||||
else
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(inviteeUserName == null )
|
||||
{
|
||||
// else there are no existing people who have the given invitee
|
||||
// email address so create new person
|
||||
inviteeUserName = createInviteePerson(inviteeFirstName,
|
||||
inviteeLastName, inviteeEmail);
|
||||
inviteeLastName,
|
||||
inviteeEmail);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger
|
||||
.debug("not explictly passed username - created new person, inviteeUserName="
|
||||
{
|
||||
logger.debug("not explictly passed username - created new person, inviteeUserName="
|
||||
+ inviteeUserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO MER - Is the code block neccessary - seems to do nothing ?
|
||||
// inviteeUserName was specified
|
||||
NodeRef person = this.personService.getPerson(inviteeUserName);
|
||||
|
||||
//TODO
|
||||
Serializable firstNameVal = this.getNodeService().getProperty(person, ContentModel.PROP_FIRSTNAME);
|
||||
Serializable lastNameVal = this.getNodeService().getProperty(person, ContentModel.PROP_LASTNAME);
|
||||
Serializable emailVal = this.getNodeService().getProperty(person, ContentModel.PROP_EMAIL);
|
||||
@@ -1383,4 +1409,16 @@ public class InvitationServiceImpl implements InvitationService
|
||||
throw new InvitationExceptionUserError("invitation.error.invalid_inviteId_format", objs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum number of attempts to generate a user name
|
||||
* @param maxUserNameGenRetries
|
||||
*/
|
||||
private void setMaxUserNameGenRetries(int maxUserNameGenRetries) {
|
||||
this.maxUserNameGenRetries = maxUserNameGenRetries;
|
||||
}
|
||||
|
||||
private int getMaxUserNameGenRetries() {
|
||||
return maxUserNameGenRetries;
|
||||
}
|
||||
}
|
||||
|
@@ -270,6 +270,106 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
||||
siteService.removeMembership(resourceName, inviteeUserName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test nominated user - new user
|
||||
*
|
||||
* Creates two separate users with two the same email address.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testNominatedInvitationNewUserSameEmails() throws Exception
|
||||
{
|
||||
Date startDate = new java.util.Date();
|
||||
|
||||
String inviteeAFirstName = "John";
|
||||
String inviteeALastName = "Smith";
|
||||
|
||||
String inviteeBFirstName = "Jane";
|
||||
String inviteeBLastName = "Smith";
|
||||
|
||||
String inviteeEmail = "123@alfrescotesting.com";
|
||||
String inviteeAUserName = null;
|
||||
String inviteeBUserName = null;
|
||||
|
||||
Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
|
||||
String resourceName = SITE_SHORT_NAME_INVITE;
|
||||
String inviteeRole = SiteModel.SITE_COLLABORATOR;
|
||||
String serverPath = "wibble";
|
||||
String acceptUrl = "froob";
|
||||
String rejectUrl = "marshmallow";
|
||||
|
||||
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||
|
||||
NominatedInvitation nominatedInvitationA = invitationService.inviteNominated(
|
||||
inviteeAFirstName,
|
||||
inviteeALastName,
|
||||
inviteeEmail,
|
||||
resourceType,
|
||||
resourceName,
|
||||
inviteeRole,
|
||||
serverPath,
|
||||
acceptUrl,
|
||||
rejectUrl) ;
|
||||
|
||||
assertNotNull("nominated invitation is null", nominatedInvitationA);
|
||||
String inviteAId = nominatedInvitationA.getInviteId();
|
||||
assertEquals("first name wrong", inviteeAFirstName, nominatedInvitationA.getInviteeFirstName());
|
||||
assertEquals("last name wrong", inviteeALastName, nominatedInvitationA.getInviteeLastName());
|
||||
assertEquals("email name wrong", inviteeEmail, nominatedInvitationA.getInviteeEmail());
|
||||
|
||||
// Generated User Name should be returned
|
||||
inviteeAUserName = nominatedInvitationA.getInviteeUserName();
|
||||
assertNotNull("generated user name is null", inviteeAUserName);
|
||||
|
||||
NominatedInvitation nominatedInvitationB = invitationService.inviteNominated(
|
||||
inviteeBFirstName,
|
||||
inviteeBLastName,
|
||||
inviteeEmail,
|
||||
resourceType,
|
||||
resourceName,
|
||||
inviteeRole,
|
||||
serverPath,
|
||||
acceptUrl,
|
||||
rejectUrl) ;
|
||||
|
||||
assertNotNull("nominated invitation is null", nominatedInvitationB);
|
||||
String inviteBId = nominatedInvitationB.getInviteId();
|
||||
assertEquals("first name wrong", inviteeBFirstName, nominatedInvitationB.getInviteeFirstName());
|
||||
assertEquals("last name wrong", inviteeBLastName, nominatedInvitationB.getInviteeLastName());
|
||||
assertEquals("email name wrong", inviteeEmail, nominatedInvitationB.getInviteeEmail());
|
||||
|
||||
// Generated User Name should be returned
|
||||
inviteeBUserName = nominatedInvitationB.getInviteeUserName();
|
||||
assertNotNull("generated user name is null", inviteeBUserName);
|
||||
assertFalse("generated user names are the same", inviteeAUserName.equals(inviteeBUserName));
|
||||
|
||||
/**
|
||||
* Now accept the invitation
|
||||
*/
|
||||
NominatedInvitation acceptedInvitationA = (NominatedInvitation)invitationService.accept(inviteAId, nominatedInvitationA.getTicket());
|
||||
assertEquals("invite id wrong", inviteAId, acceptedInvitationA.getInviteId());
|
||||
assertEquals("first name wrong", inviteeAFirstName, acceptedInvitationA.getInviteeFirstName());
|
||||
assertEquals("last name wrong", inviteeALastName, acceptedInvitationA.getInviteeLastName());
|
||||
assertEquals("user name wrong", inviteeAUserName, acceptedInvitationA.getInviteeUserName());
|
||||
|
||||
NominatedInvitation acceptedInvitationB = (NominatedInvitation)invitationService.accept(inviteBId, nominatedInvitationB.getTicket());
|
||||
assertEquals("invite id wrong", inviteBId, acceptedInvitationB.getInviteId());
|
||||
assertEquals("first name wrong", inviteeBFirstName, acceptedInvitationB.getInviteeFirstName());
|
||||
assertEquals("last name wrong", inviteeBLastName, acceptedInvitationB.getInviteeLastName());
|
||||
assertEquals("user name wrong", inviteeBUserName, acceptedInvitationB.getInviteeUserName());
|
||||
|
||||
|
||||
/**
|
||||
* Now verify access control list
|
||||
*/
|
||||
String roleNameA = siteService.getMembersRole(resourceName, inviteeAUserName);
|
||||
assertEquals("role name wrong", roleNameA, inviteeRole);
|
||||
String roleNameB = siteService.getMembersRole(resourceName, inviteeBUserName);
|
||||
assertEquals("role name wrong", roleNameB, inviteeRole);
|
||||
siteService.removeMembership(resourceName, inviteeAUserName);
|
||||
siteService.removeMembership(resourceName, inviteeBUserName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Nominated Invitation (for existing user, USER_ONE)
|
||||
|
Reference in New Issue
Block a user