Skip to content

Commit

Permalink
SAK-26158 Added the property to control if must duplicate email in di…
Browse files Browse the repository at this point in the history
…fferent accounts is allowed
  • Loading branch information
sinmsinm committed Feb 18, 2015
1 parent 3ac79c2 commit 44019e2
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ User addUser(String id, String eid, String firstName, String lastName, String em
*/
User getCurrentUser();

/**
* Check if the email is used by an user
* @param user
* The UserEdit to check the email
* @return true if email is duplicated false in other case
*
*/
public boolean checkDuplicatedEmail(User user);

/**
* Access a user object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ public static boolean allowAddUser()

return service.allowAddUser();
}

public static boolean checkDuplicatedEmail(org.sakaiproject.user.api.User param0)
{
org.sakaiproject.user.api.UserDirectoryService service = getInstance();
if (service == null) return false;

return service.checkDuplicatedEmail(param0);
}


public static org.sakaiproject.user.api.UserEdit addUser(java.lang.String param0, java.lang.String param1)
throws org.sakaiproject.user.api.UserIdInvalidException, org.sakaiproject.user.api.UserAlreadyDefinedException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,28 @@ protected void checkAndEnsureMappedIdForProvidedUser(UserEdit user)
ensureMappedIdForProvidedUser(user);
}
}

public boolean checkDuplicatedEmail (User user)
{
//Check if another user has the same email
String email = StringUtils.trimToNull (user.getEmail());

M_log.debug("commitEdit(): Check for mail " + email);

if (email!=null)
{
Collection <User> usersByMail = findUsersByEmail(email);
for (User userToCheck : usersByMail)
{
if (!StringUtils.equals(userToCheck.getId(),user.getId()))
{
return true;
}
}
}

return false;
}

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public String getUserId(String arg0) throws UserNotDefinedException {
return (new FakeUser()).getId();
}

public boolean checkDuplicatedEmail(User user) {
//TODO Not used in the tests
return false;
}

public List getUsers() {
// TODO Auto-generated method stub
return null;
Expand Down
1 change: 1 addition & 0 deletions user/user-tool/tool/src/bundle/admin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ useact.newuse = New User
useact.remuse = Remove User
useact.remuse.list.summary = List of users to be removed. First column: user ID. Second column: user name. Third column: user email.
useact.theuseid1 = The user id is already in use
useact.theuseemail1 = The user email is already in use
useact.theuseid2 = The user id is invalid
useact.use_notfou = User {0} not found
useact.youdonot1 = You do not have permission to edit User {0}
Expand Down
1 change: 1 addition & 0 deletions user/user-tool/tool/src/bundle/admin_ca.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ useact.search = Cerca els usuaris
useact.somels = Alg\u00FA altre est\u00E0 editant aquest usuari actualment: {0}
useact.theuseid1 = L'identificador d'usuari ja est\u00E0 en \u00FAs
useact.theuseid2 = L'identificador d'usuari no \u00E9s v\u00E0lid
useact.theuseemail1 = L'adre\u00e7a de correu ja est\u00e0 en \u00fas
useact.tryloginagain = S'ha creat el compte, per\u00F2 no es pot processar l'inici de sessi\u00F3. Torneu a provar d'iniciar la sessi\u00F3.
useact.use_notfou = L''usuari {0} no s''ha trobat
useact.youdonot1 = No teniu autoritzaci\u00F3 per editar l''usuari {0}
Expand Down
1 change: 1 addition & 0 deletions user/user-tool/tool/src/bundle/admin_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ useact.remuse=Borrar usuario
useact.remuse.list.summary=Lista de usuarios que se borrar\u00e1n. Primera columna\: ID de usuario. Segunda columna\: nombre de usuario. Tercera columna\: correo electr\u00f3nico del usuario.
useact.theuseid1=El ID de usuario est\u00e1 actualmente en uso
useact.theuseid2=El ID de usuario no es v\u00e1lido
useact.theuseemail1 = La direcci\u00f3n de correo electr\u00f3nico est\u00e1 actualmente en uso
useact.use_notfou=El usuario {0} no se encuentra.
useact.youdonot1=No tiene permiso para editar el usuario {0}
useact.youdonot2=No tiene permisos para borrar al usuario {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public TempUser(String eid, String email, String firstName, String lastName, Str
@Override public String getDisplayId() { return null; }
@Override public String getDisplayName() { return null; }
@Override public String getEid() { return null; }
@Override public String getEmail() { return null; }
@Override public String getFirstName() { return null; }
@Override public String getLastName() { return null; }
@Override public String getReference() { return null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,25 @@ public void doImport(RunData data, Context context)

List<ImportedUser> users = (List<ImportedUser>)state.getAttribute("importedUsers");
if(users !=null && users.size() > 0) {

//Check if the email is duplicated
boolean allowEmailDuplicates = ServerConfigurationService.getBoolean("user.email.allowduplicates",true);


for(ImportedUser user: users) {
try {

TempUser tempUser = new TempUser(user.getEid(), user.getEmail(), null, null, user.getEid(), user.getPassword(), null);

if (!allowEmailDuplicates && UserDirectoryService.checkDuplicatedEmail(tempUser)){
addAlert(state, rb.getString("useact.theuseemail1") + ":" + tempUser.getEmail());

//Try to import the rest
continue;
}

User newUser = UserDirectoryService.addUser(null, user.getEid(), user.getFirstName(), user.getLastName(), user.getEmail(), user.getPassword(), user.getType(), user.getProperties());


}
catch (UserAlreadyDefinedException e){
//ok, just skip
Expand Down Expand Up @@ -859,10 +874,21 @@ public void doSave(RunData data, Context context)
// read the form - if rejected, leave things as they are
if (!readUserForm(data, state)) return;



// commit the change
UserEdit edit = (UserEdit) state.getAttribute("user");
if (edit != null)
{

//Check if the email is duplicated
boolean allowEmailDuplicates = ServerConfigurationService.getBoolean("user.email.allowduplicates",true);

if (!allowEmailDuplicates && UserDirectoryService.checkDuplicatedEmail(edit)){
addAlert(state, rb.getString("useact.theuseemail1"));
return;
}

try
{
UserDirectoryService.commitEdit(edit);
Expand Down Expand Up @@ -1289,11 +1315,20 @@ else if ((mode != null) && (mode.equalsIgnoreCase("edit")) && (!singleUser))
}

// SAK-23568 - make sure password meets policy requirements
TempUser tempUser = new TempUser(eid, null, null, null, eid, pw, null);
TempUser tempUser = new TempUser(eid, email, null, null, eid, pw, null);
if (!validatePassword(pw, tempUser, state)) {
return false;
}

//Check if the email is duplicated
boolean allowEmailDuplicates = ServerConfigurationService.getBoolean("user.email.allowduplicates",true);

if (!allowEmailDuplicates && UserDirectoryService.checkDuplicatedEmail(tempUser)){
addAlert(state, rb.getString("useact.theuseemail1"));
return false;
}


try
{
// add the user in one step so that all you need is add not update permission
Expand Down

0 comments on commit 44019e2

Please sign in to comment.