r1713 - in trunk: wao-persistence/src/main/java/fr/ifremer/wao/entity wao-services/src/main/java/fr/ifremer/wao/services/service wao-services/src/main/resources/i18n wao-web/src/main/java/fr/ifremer/wao/web/action/administration wao-web/src/main/resources/i18n wao-web/src/main/webapp/WEB-INF/content/administration
Author: bleny Date: 2014-03-05 12:21:54 +0100 (Wed, 05 Mar 2014) New Revision: 1713 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1713 Log: refs #4560 start users management Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommand.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommandPasswordStrategy.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoUsersService.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/DeleteWaoUserAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/EditWaoUserAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/WaoUsersAction.java trunk/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/UserRole.java trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties trunk/wao-web/src/main/webapp/WEB-INF/content/administration/companies.jsp Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/UserRole.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/UserRole.java 2014-03-05 11:21:07 UTC (rev 1712) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/UserRole.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -77,11 +77,12 @@ /** for a given program, return the roles that can be assigned by someone * who own the role <code>userRole</code> + * * @param obsProgram available roles depends on the program * @param userRole role of the user who want to grant rights * @return roles that the user can affect */ - public static UserRole[] getAllowedRoles(ObsProgram obsProgram, UserRole userRole) { + public static List<UserRole> getAllowedRoles(ObsProgram obsProgram, UserRole userRole) { List<UserRole> allowedRoles = new ArrayList<UserRole>(); allowedRoles.add(UserRole.COORDINATOR); allowedRoles.add(UserRole.OBSERVER); @@ -94,7 +95,6 @@ allowedRoles.add(UserRole.PROFESSIONAL); } } - UserRole[] result = allowedRoles.toArray(new UserRole[allowedRoles.size()]); - return result; + return allowedRoles; } } Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommand.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommand.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommand.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,209 @@ +package fr.ifremer.wao.services.service; + +import com.google.common.collect.ImmutableMap; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.UserProfile; +import fr.ifremer.wao.entity.UserProfileImpl; +import fr.ifremer.wao.entity.UserRole; +import fr.ifremer.wao.entity.WaoUser; +import org.apache.commons.lang3.StringUtils; + +public class UpdateWaoUserCommand { + + protected ObsProgram obsProgram; + + protected WaoUser waoUser; + + protected String clearPassword; + + protected String clearPasswordConfirmation; + + protected UpdateWaoUserCommandPasswordStrategy passwordStrategy; + + protected ImmutableMap<String, Company> allCompanies; + + public String getCompanyId() { + String companyId = null; + if (waoUser.getCompany() != null) { + companyId = waoUser.getCompany().getTopiaId(); + } + return companyId; + } + + public void setCompanyId(String companyId) { + if (StringUtils.isBlank(companyId)) { + waoUser.setCompany(null); + } else { + Company company = allCompanies.get(companyId); + waoUser.setCompany(company); + } + } + + public ImmutableMap<String, Company> getAllCompanies() { + return allCompanies; + } + + public void setAllCompanies(ImmutableMap<String, Company> allCompanies) { + this.allCompanies = allCompanies; + } + + protected UserProfile getUserProfile(UserRole userRole, boolean readOnly) { + if (waoUser.isUserProfileNotEmpty()) { + for (UserProfile userProfile : waoUser.getUserProfile(obsProgram)) { + if (userRole.equals(userProfile.getUserRole()) && readOnly == userProfile.isReadOnly()) { + return userProfile; + } + } + } + return null; + } + + protected void updateUserProfile(UserRole userRole, boolean readOnly, boolean userMustHaveProfile) { + UserProfile userProfile = getUserProfile(userRole, readOnly); + if (userMustHaveProfile) { + if (userProfile == null) { + // on l'ajoute + userProfile = new UserProfileImpl(); + userProfile.setUserRole(userRole); + userProfile.setCanWrite(!readOnly); + userProfile.setObsProgram(obsProgram); + waoUser.addUserProfile(userProfile); + } else { + // il l'a déjà + } + } else { + if (userProfile == null) { + // il ne l'a pas + } else { + // on le retire + waoUser.removeUserProfile(userProfile); + } + } + } + + protected boolean hasProfile(UserRole userRole, boolean readOnly) { + boolean hasProfile = getUserProfile(userRole, readOnly) != null; + return hasProfile; + } + + public boolean isAdmin() { + return hasProfile(UserRole.ADMIN, false); + } + + public void setAdmin(boolean admin) { + updateUserProfile(UserRole.ADMIN, false, admin); + } + + public boolean isCoordinator() { + return hasProfile(UserRole.COORDINATOR, false); + } + + public void setCoordinator(boolean coordinator) { + updateUserProfile(UserRole.COORDINATOR, false, coordinator); + } + + public boolean isObserver() { + return hasProfile(UserRole.OBSERVER, false); + } + + public void setObserver(boolean observer) { + updateUserProfile(UserRole.OBSERVER, false, observer); + } + + public boolean isGuest() { + return hasProfile(UserRole.GUEST, false); + } + + public void setGuest(boolean guest) { + updateUserProfile(UserRole.GUEST, false, guest); + } + + public boolean isProfessional() { + return hasProfile(UserRole.PROFESSIONAL, false); + } + + public void setProfessional(boolean professional) { + updateUserProfile(UserRole.PROFESSIONAL, false, professional); + } + + public boolean isAdminReadOnly() { + return hasProfile(UserRole.ADMIN, true); + } + + public void setAdminReadOnly(boolean adminReadOnly) { + updateUserProfile(UserRole.ADMIN, true, adminReadOnly); + } + + public boolean isCoordinatorReadOnly() { + return hasProfile(UserRole.COORDINATOR, true); + } + + public void setCoordinatorReadOnly(boolean coordinatorReadOnly) { + updateUserProfile(UserRole.COORDINATOR, true, coordinatorReadOnly); + } + + public boolean isObserverReadOnly() { + return hasProfile(UserRole.OBSERVER, true); + } + + public void setObserverReadOnly(boolean observerReadOnly) { + updateUserProfile(UserRole.OBSERVER, true, observerReadOnly); + } + + public boolean isGuestReadOnly() { + return hasProfile(UserRole.GUEST, true); + } + + public void setGuestReadOnly(boolean guestReadOnly) { + updateUserProfile(UserRole.GUEST, true, guestReadOnly); + } + + public boolean isProfessionalReadOnly() { + return hasProfile(UserRole.PROFESSIONAL, true); + } + + public void setProfessionalReadOnly(boolean professionalReadOnly) { + updateUserProfile(UserRole.ADMIN, true, professionalReadOnly); + } + + public UpdateWaoUserCommandPasswordStrategy getPasswordStrategy() { + return passwordStrategy; + } + + public void setPasswordStrategy(UpdateWaoUserCommandPasswordStrategy passwordStrategy) { + this.passwordStrategy = passwordStrategy; + } + + public String getClearPassword() { + return clearPassword; + } + + public void setClearPassword(String clearPassword) { + this.clearPassword = clearPassword; + } + + public String getClearPasswordConfirmation() { + return clearPasswordConfirmation; + } + + public void setClearPasswordConfirmation(String clearPasswordConfirmation) { + this.clearPasswordConfirmation = clearPasswordConfirmation; + } + + public WaoUser getWaoUser() { + return waoUser; + } + + public void setWaoUser(WaoUser waoUser) { + this.waoUser = waoUser; + } + + public ObsProgram getObsProgram() { + return obsProgram; + } + + public void setObsProgram(ObsProgram obsProgram) { + this.obsProgram = obsProgram; + } +} Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommandPasswordStrategy.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommandPasswordStrategy.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateWaoUserCommandPasswordStrategy.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,30 @@ +package fr.ifremer.wao.services.service; + +import org.nuiton.i18n.I18n; + +public enum UpdateWaoUserCommandPasswordStrategy { + + KEEP_SAME_PASSWORD(I18n.n("UpdateWaoUserCommandPasswordStrategy.KEEP_SAME_PASSWORD")), + + GENERATE_NEW_PASSWORD(I18n.n("UpdateWaoUserCommandPasswordStrategy.GENERATE_NEW_PASSWORD")), + + DEFINE_PASSWORD(I18n.n("UpdateWaoUserCommandPasswordStrategy.DEFINE_PASSWORD")); + + protected String i18nKey; + + UpdateWaoUserCommandPasswordStrategy(String i18nKey) { + this.i18nKey = i18nKey; + } + + public String getI18nKey() { + return i18nKey; + } + + public boolean isDefinePassword() { + return this == DEFINE_PASSWORD; + } + + public boolean isGeneratePassword() { + return this == GENERATE_NEW_PASSWORD; + } +} Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoUsersService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoUsersService.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoUsersService.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,143 @@ +package fr.ifremer.wao.services.service; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.entity.WaoUserImpl; +import fr.ifremer.wao.entity.WaoUserTopiaDao; +import org.apache.commons.lang3.RandomStringUtils; +import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; +import org.nuiton.util.StringUtil; + +import java.util.List; +import java.util.Map; + +public class WaoUsersService extends WaoServiceSupport { + + public List<WaoUser> getWaoUsers(Optional<String> optionalCompanyId) { + + WaoUserTopiaDao dao = getWaoUserDao(); + + TopiaQueryBuilderAddCriteriaOrRunQueryStep<WaoUser> query = dao.newQueryBuilder(); + + if (optionalCompanyId.isPresent()) { + query.addTopiaIdEquals(WaoUser.PROPERTY_COMPANY, optionalCompanyId.get()); + } + + query.setOrderByArguments(WaoUser.PROPERTY_ACTIVE + " desc", WaoUser.PROPERTY_LOGIN); + + List<WaoUser> waoUsers = query.findAll(); + + return waoUsers; + + } + + public WaoUser getWaoUser(String waoUserId) { + + WaoUserTopiaDao dao = getWaoUserDao(); + + WaoUser waouser = dao.findByTopiaId(waoUserId); + + return waouser; + + } + + public WaoUser newWaoUser() { + + WaoUserImpl newWaoUser = new WaoUserImpl(); + + newWaoUser.setActive(true); + + return newWaoUser; + + } + + public UpdateWaoUserCommand newUpdateWaoUserCommand(ObsProgram obsProgram, Optional<String> optionalUserId) { + + UpdateWaoUserCommand updateWaoUserCommand = new UpdateWaoUserCommand(); + + updateWaoUserCommand.setObsProgram(obsProgram); + + ImmutableMap<String, Company> allCompanies = Maps.uniqueIndex( + getCompaniesService().getCompanies(), + TopiaEntities.getTopiaIdFunction()); + + updateWaoUserCommand.setAllCompanies(allCompanies); + + if (optionalUserId.isPresent()) { + + updateWaoUserCommand.setWaoUser(getWaoUser(optionalUserId.get())); + + updateWaoUserCommand.setPasswordStrategy(UpdateWaoUserCommandPasswordStrategy.KEEP_SAME_PASSWORD); + + } else { + + updateWaoUserCommand.setWaoUser(newWaoUser()); + + updateWaoUserCommand.setPasswordStrategy(UpdateWaoUserCommandPasswordStrategy.GENERATE_NEW_PASSWORD); + + } + + return updateWaoUserCommand; + + } + + public void save(UpdateWaoUserCommand updateWaoUserCommand) { + + WaoUser waoUser = updateWaoUserCommand.getWaoUser(); + + String newPassword; + switch (updateWaoUserCommand.getPasswordStrategy()) { + case GENERATE_NEW_PASSWORD: + newPassword = RandomStringUtils.random(8); + break; + case DEFINE_PASSWORD: + newPassword = updateWaoUserCommand.getClearPassword(); + break; + default: + newPassword = null; + } + + if (newPassword != null) { + String hashedNewPassword = StringUtil.encodeMD5(newPassword); + waoUser.setPassword(hashedNewPassword); + } + + if (updateWaoUserCommand.getPasswordStrategy().isGeneratePassword()) { + // TODO brendan 04/03/14 envoyer le mot de passe par mail + } + + WaoUserTopiaDao dao = getWaoUserDao(); + if (waoUser.isPersisted()) { + dao.update(waoUser); + } else { + dao.create(waoUser); + } + commit(); + + } + + public void deleteWaoUser(String waoUserId) throws IllegalDeletionException { + + WaoUserTopiaDao dao = getWaoUserDao(); + + WaoUser waoUser = dao.findByTopiaId(waoUserId); + + Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(waoUser); + + if (allUsages.isEmpty()) { + dao.delete(waoUser); + } else { + throw new IllegalDeletionException(allUsages.keySet()); + } + + commit(); + + } + +} Modified: trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties =================================================================== --- trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-03-05 11:21:07 UTC (rev 1712) +++ trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-03-05 11:21:54 UTC (rev 1713) @@ -1,3 +1,6 @@ +UpdateWaoUserCommandPasswordStrategy.DEFINE_PASSWORD=Manually define the password +UpdateWaoUserCommandPasswordStrategy.GENERATE_NEW_PASSWORD=Generate a new password +UpdateWaoUserCommandPasswordStrategy.KEEP_SAME_PASSWORD=Keep the same password csv.import.error.missingMandatoryHeaders=The mandatory fields %s are missing csv.import.error.unableToParseValue=Unable to parse value '%s' (column '%s', line %s) csv.import.error.unableToReadField=Unable to read value of column '%s' at line %s Modified: trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties =================================================================== --- trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-03-05 11:21:07 UTC (rev 1712) +++ trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-03-05 11:21:54 UTC (rev 1713) @@ -1,3 +1,6 @@ +UpdateWaoUserCommandPasswordStrategy.DEFINE_PASSWORD=Définir le mot de passe manuellement +UpdateWaoUserCommandPasswordStrategy.GENERATE_NEW_PASSWORD=Générer un nouveau mot de passe +UpdateWaoUserCommandPasswordStrategy.KEEP_SAME_PASSWORD=Conserver le mot de passe actuel csv.import.error.missingMandatoryHeaders=Les champs obligatoires %s sont manquants csv.import.error.unableToParseValue=Erreur lors de l'interprétation de la valeur '%s' (colonne '%s', ligne %s) csv.import.error.unableToReadField=Impossible de lire la colonne '%s' à la ligne %s Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/DeleteWaoUserAction.java (from rev 1710, trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/DeleteCompanyAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/DeleteWaoUserAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/DeleteWaoUserAction.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,49 @@ +package fr.ifremer.wao.web.action.administration; + +import fr.ifremer.wao.services.service.IllegalDeletionException; +import fr.ifremer.wao.services.service.WaoUsersService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="error", type="redirectAction", params = { "actionName", "wao-users" }), + @Result(name="success", type="redirectAction", params = { "actionName", "wao-users" }) +}) +public class DeleteWaoUserAction extends WaoJspActionSupport { + + protected WaoUsersService service; + + protected String waoUserId; + + public void setService(WaoUsersService service) { + this.service = service; + } + + public void setWaoUserId(String waoUserId) { + this.waoUserId = waoUserId; + } + + @Override + public String execute() { + + try { + + service.deleteWaoUser(waoUserId); + + session.addMessage(t("wao.ui.action.deleteWaoUser.success")); + + return SUCCESS; + + } catch (IllegalDeletionException e) { + + // TODO brendan 04/03/14 préciser le problème + session.addErrorMessages(t("wao.ui.action.deleteWaoUser.failure")); + + return ERROR; + + } + + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/EditWaoUserAction.java (from rev 1710, trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/EditCompanyAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/EditWaoUserAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/EditWaoUserAction.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,103 @@ +package fr.ifremer.wao.web.action.administration; + +import com.google.common.base.Optional; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.services.service.UpdateWaoUserCommand; +import fr.ifremer.wao.services.service.UpdateWaoUserCommandPasswordStrategy; +import fr.ifremer.wao.services.service.WaoUsersService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "wao-users", "companyId", "%{companyId}" }) +}) +public class EditWaoUserAction extends WaoJspActionSupport implements Preparable { + + protected WaoUsersService service; + + protected Optional<String> optionalWaoUserId = Optional.absent(); + + protected Optional<String> optionalCompanyId = Optional.absent(); + + protected UpdateWaoUserCommand updateWaoUserCommand; + + public void setService(WaoUsersService service) { + this.service = service; + } + + public void setWaoUserId(String waoUserId) { + this.optionalWaoUserId = Optional.fromNullable(Strings.emptyToNull(waoUserId)); + } + + public void setCompanyId(String companyId) { + this.optionalCompanyId = Optional.fromNullable(Strings.emptyToNull(companyId)); + } + + @Override + public void prepare() { + + updateWaoUserCommand = service.newUpdateWaoUserCommand(getObsProgram(), optionalWaoUserId); + + if (optionalCompanyId.isPresent()) { + updateWaoUserCommand.setCompanyId(optionalCompanyId.get()); + } + + } + + @Override + public void validate() { + + if (updateWaoUserCommand.getPasswordStrategy().isDefinePassword()) { + if (StringUtils.isEmpty(updateWaoUserCommand.getClearPassword())) { + addFieldError("updateWaoUserCommand.clearPassword", t("wao.ui.form.updateWaoUserCommand.missingPassword")); + } + if ( ! updateWaoUserCommand.getClearPassword().equals(updateWaoUserCommand.getClearPasswordConfirmation())) { + addFieldError("updateWaoUserCommand.clearPasswordConfirmation", t("wao.ui.form.updateWaoUserCommand.passwordMismatch")); + } + } + + if (updateWaoUserCommand.getCompanyId() == null) { + addFieldError("updateWaoUserCommand.companyId", t("wao.ui.form.updateWaoUserCommand.requiredCompany")); + } else { + } + + } + + @Override + public String execute() { + + service.save(updateWaoUserCommand); + + session.addMessage(t("wao.ui.form.updateWaoUserCommand.success", updateWaoUserCommand.getWaoUser().getLogin())); + + // for redirection + setCompanyId(updateWaoUserCommand.getWaoUser().getCompany().getTopiaId()); + + return SUCCESS; + + } + + public String getWaoUserId() { + return optionalWaoUserId.orNull(); + } + + public String getCompanyId() { + return optionalCompanyId.orNull(); + } + + public UpdateWaoUserCommand getUpdateWaoUserCommand() { + if (updateWaoUserCommand == null) { + return service.newUpdateWaoUserCommand(getObsProgram(), optionalWaoUserId); + } + return updateWaoUserCommand; + } + + public ImmutableSet<UpdateWaoUserCommandPasswordStrategy> getUpdateWaoUserCommandPasswordStrategies() { + return ImmutableSet.copyOf(UpdateWaoUserCommandPasswordStrategy.values()); + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/WaoUsersAction.java (from rev 1710, trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/CompaniesAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/WaoUsersAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/WaoUsersAction.java 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,38 @@ +package fr.ifremer.wao.web.action.administration; + +import com.google.common.base.Optional; +import com.google.common.base.Strings; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.services.service.WaoUsersService; +import fr.ifremer.wao.web.WaoJspActionSupport; + +import java.util.List; + +public class WaoUsersAction extends WaoJspActionSupport implements Preparable { + + protected WaoUsersService service; + + protected Optional<String> optionalCompanyId = Optional.absent(); + + protected List<WaoUser> waoUsers; + + public void setService(WaoUsersService service) { + this.service = service; + } + + public void setCompanyId(String companyId) { + this.optionalCompanyId = Optional.fromNullable(Strings.emptyToNull(companyId)); + } + + @Override + public void prepare() { + + waoUsers = service.getWaoUsers(optionalCompanyId); + + } + + public List<WaoUser> getWaoUsers() { + return waoUsers; + } +} Modified: trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties =================================================================== --- trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-03-05 11:21:07 UTC (rev 1712) +++ trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-03-05 11:21:54 UTC (rev 1713) @@ -25,10 +25,12 @@ wao.ui.action.contactAdmin=Contact an admin wao.ui.action.create=Create wao.ui.action.createCompany=Create a company -wao.ui.action.createUser=Create a user +wao.ui.action.createWaoUser=Create a user wao.ui.action.delete=Delete wao.ui.action.deleteCompany=Delete company wao.ui.action.deleteCompany.confirm=Are you sure you want to delete this company ? +wao.ui.action.deleteCompany.failure=The company cannot be deleted +wao.ui.action.deleteCompany.success=Company deleted successfully wao.ui.action.deleteContact=Delete contact wao.ui.action.deleteContact.confirm=Are you sure you want to delete this contact ? wao.ui.action.deleteNews=Delete this news @@ -37,6 +39,8 @@ wao.ui.action.deleteSampleRow.confirm=Are you sure your want to delete this sample row ? wao.ui.action.deleteUser=Delete this user wao.ui.action.deleteUser.confirm=Are your sure you want to delete this user ? +wao.ui.action.deleteWaoUser.failure=The user cannot be deleted +wao.ui.action.deleteWaoUser.success=User deleted successfully wao.ui.action.edit=Edit wao.ui.action.enlargeView=Enlarge view wao.ui.action.exportBoats=Export boats with private infos @@ -54,10 +58,12 @@ wao.ui.action.runImport=Run import wao.ui.action.runSearch=Run search wao.ui.action.save=Save +wao.ui.action.save.success=Modifications saved wao.ui.action.showDetails=Show details wao.ui.action.showFilters=Show filters wao.ui.action.unvalidateContact=Unvalidate contact wao.ui.action.viewBoatsForRow=View the boats for this sample row +wao.ui.action.viewCompanyWaoUsers=View users for this company wao.ui.action.viewIndicatorsHistory=View indicators historic wao.ui.actions=Actions wao.ui.boatList=List of %s boats @@ -106,7 +112,13 @@ wao.ui.field.BoatDistrict.code=District code wao.ui.field.BoatInfos.dup=Capacity of the ship in specialized staff wao.ui.field.Company.active=Active +wao.ui.field.Company.address1=Address +wao.ui.field.Company.address2=Address ( +wao.ui.field.Company.city=City +wao.ui.field.Company.email=E-mail wao.ui.field.Company.name=Name +wao.ui.field.Company.phoneNumber=Phone number +wao.ui.field.Company.postalCode=Post code wao.ui.field.Contact.beginDate=Observation start wao.ui.field.Contact.comment=Observer comment wao.ui.field.Contact.commentAdmin=Program comment @@ -171,8 +183,12 @@ wao.ui.field.User.lastName=Last name wao.ui.field.User.login=Login wao.ui.field.UserProfile.userRole=Role +wao.ui.field.WaoUser.active=Active wao.ui.field.WaoUser.canReadBoats=Restraint view to boats -wao.ui.field.WaoUser.login=Identifier +wao.ui.field.WaoUser.firstName=First name +wao.ui.field.WaoUser.fullName=Name +wao.ui.field.WaoUser.lastName=Last name +wao.ui.field.WaoUser.login=Login wao.ui.field.WaoUser.mammalsNotifications=Receive notifications about mammals captures wao.ui.field.WaoUser.password=Password wao.ui.filters.filters=Search filters @@ -183,6 +199,10 @@ wao.ui.form.SampleRow.missingBeginDate=Begin date missing to generate line code wao.ui.form.SampleRow.others=Others data of the sample row wao.ui.form.SampleRow.program=Associated program and observation effort by months +wao.ui.form.WaoUser.credentials=Credentials +wao.ui.form.WaoUser.identity=Identity +wao.ui.form.WaoUser.preferences=Preferences +wao.ui.form.WaoUser.rights=Rights wao.ui.form.addComment=Add a comment wao.ui.form.addRole=Add this ru00F4le wao.ui.form.boardingFrom=Boardings since @@ -208,6 +228,21 @@ wao.ui.form.repeatPassword=Repeat password wao.ui.form.roles=Roles wao.ui.form.sortByTideBegin=Sort by observation begin date +wao.ui.form.updateWaoUserCommand.admin=Administrator +wao.ui.form.updateWaoUserCommand.adminReadOnly=Administrator (read-only) +wao.ui.form.updateWaoUserCommand.coordinator=Coordinator +wao.ui.form.updateWaoUserCommand.coordinatorReadOnly=Coordinator (read-only) +wao.ui.form.updateWaoUserCommand.guest=Guest +wao.ui.form.updateWaoUserCommand.guestReadOnly=Guest (read-only) +wao.ui.form.updateWaoUserCommand.missingPassword=The password is missing +wao.ui.form.updateWaoUserCommand.observer=Observer +wao.ui.form.updateWaoUserCommand.observerReadOnly=Observer (read-only) +wao.ui.form.updateWaoUserCommand.passwordMismatch=Provided passwords don't match +wao.ui.form.updateWaoUserCommand.passwordStrategy=Password modification +wao.ui.form.updateWaoUserCommand.professional=Professional +wao.ui.form.updateWaoUserCommand.professionalReadOnly=Professional (read-only) +wao.ui.form.updateWaoUserCommand.requiredCompany=The company is required +wao.ui.form.updateWaoUserCommand.success=Modifications about %s saved wao.ui.import.boatDistrictLabel=of the coordinates of boat districts wao.ui.import.boatGroupsLabel=of the boat groups wao.ui.import.boatsLabel=of boats @@ -292,6 +327,7 @@ wao.ui.page.Synthesis.title=Synthesis wao.ui.page.UserProfileForm.title=Profile management wao.ui.page.companies.title=Companies +wao.ui.page.waoUsers.title=Users wao.ui.publishedByProgram=Pusblished by program wao.ui.publishedByYourCompany=Published by company wao.ui.sampleRow.creation=Creation of a sample row Modified: trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties =================================================================== --- trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-03-05 11:21:07 UTC (rev 1712) +++ trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-03-05 11:21:54 UTC (rev 1713) @@ -25,10 +25,12 @@ wao.ui.action.contactAdmin=Contacter un responsable ObsMer wao.ui.action.create=Créer wao.ui.action.createCompany=Créer une société -wao.ui.action.createUser=Créer un utilisateur +wao.ui.action.createWaoUser=Créer un utilisateur wao.ui.action.delete=Supprimer wao.ui.action.deleteCompany=Supprimer la société wao.ui.action.deleteCompany.confirm=Êtes-vous sûr de vouloir supprimer la société ? +wao.ui.action.deleteCompany.failure=La suppression de la société a échoué +wao.ui.action.deleteCompany.success=La société a bien été supprimée wao.ui.action.deleteContact=Supprimer le contact wao.ui.action.deleteContact.confirm=Êtes-vous sûr de vouloir supprimer définitivement ce contact ? wao.ui.action.deleteNews=Supprimer la nouvelle @@ -37,6 +39,8 @@ wao.ui.action.deleteSampleRow.confirm=Êtes-vous sûr de vouloir supprimer la ligne %s du plan ? wao.ui.action.deleteUser=Supprimer l'utilisateur wao.ui.action.deleteUser.confirm=Êtes-vous sûr de vouloir supprimer l'utilisateur ? +wao.ui.action.deleteWaoUser.failure=La suppression de l'utilisateur a échoué +wao.ui.action.deleteWaoUser.success=L'utilisateur a bien été supprimé wao.ui.action.edit=Modifier wao.ui.action.enlargeView=Agrandir la vue wao.ui.action.exportBoats=Exporter les $s navires avec leurs informations privées @@ -54,10 +58,12 @@ wao.ui.action.runImport=Lancer l'import wao.ui.action.runSearch=Lancer la recherche wao.ui.action.save=Enregistrer +wao.ui.action.save.success=Les informations ont bien été enregistrées wao.ui.action.showDetails=Voir les détails wao.ui.action.showFilters=Afficher les filtres wao.ui.action.unvalidateContact=Invalider le contact wao.ui.action.viewBoatsForRow=Voir les navires présentis pour cette ligne +wao.ui.action.viewCompanyWaoUsers=Voir les utilisateurs associés à cette société wao.ui.action.viewIndicatorsHistory=Voir l'historique des modifications des indicateurs wao.ui.actions=Actions wao.ui.boatList=Liste de %s navires @@ -106,7 +112,13 @@ wao.ui.field.BoatDistrict.code=Code du quartier maritime wao.ui.field.BoatInfos.dup=Capacité d'accueil du navire en personnels spécialisés wao.ui.field.Company.active=Active +wao.ui.field.Company.address1=Adresse +wao.ui.field.Company.address2=Complément d'adresse +wao.ui.field.Company.city=Ville +wao.ui.field.Company.email=E-mail wao.ui.field.Company.name=Nom +wao.ui.field.Company.phoneNumber=N° de téléphone +wao.ui.field.Company.postalCode=Code postal wao.ui.field.Contact.beginDate=Début d'observation wao.ui.field.Contact.comment=Commentaire observateur wao.ui.field.Contact.commentAdmin=Commentaire programme @@ -171,7 +183,11 @@ wao.ui.field.User.lastName=Nom wao.ui.field.User.login=Identifiant wao.ui.field.UserProfile.userRole=Rôle +wao.ui.field.WaoUser.active=Actif wao.ui.field.WaoUser.canReadBoats=Restreindre la vue aux navires +wao.ui.field.WaoUser.firstName=Prénom +wao.ui.field.WaoUser.fullName=Nom +wao.ui.field.WaoUser.lastName=Nom wao.ui.field.WaoUser.login=Identifiant wao.ui.field.WaoUser.mammalsNotifications=Recevoir les notifications de captures accidentelles wao.ui.field.WaoUser.password=Mot de passe @@ -183,6 +199,10 @@ wao.ui.form.SampleRow.missingBeginDate=Date de début manquante pour générer le code de la ligne \! wao.ui.form.SampleRow.others=Autres données de la ligne d'échantillonnage wao.ui.form.SampleRow.program=Programme de rattachement et effort d'observation par mois +wao.ui.form.WaoUser.credentials=Informations d'authentification +wao.ui.form.WaoUser.identity=Identité +wao.ui.form.WaoUser.preferences=Préférences +wao.ui.form.WaoUser.rights=Droits wao.ui.form.addComment=Ajouter un commentaire wao.ui.form.addRole=Ajouter ce rôle wao.ui.form.boardingFrom=Sollicitations du navire depuis le @@ -208,6 +228,21 @@ wao.ui.form.repeatPassword=Répéter le mot de passe wao.ui.form.roles=Rôles wao.ui.form.sortByTideBegin=Trier par date de début d'observation (du plus récent au plus ancien) +wao.ui.form.updateWaoUserCommand.admin=Administrateur +wao.ui.form.updateWaoUserCommand.adminReadOnly=Administrateur (lecture seule) +wao.ui.form.updateWaoUserCommand.coordinator=Coordinateur +wao.ui.form.updateWaoUserCommand.coordinatorReadOnly=Coordinateur (lecture seule) +wao.ui.form.updateWaoUserCommand.guest=Invité +wao.ui.form.updateWaoUserCommand.guestReadOnly=Invité (lecture seule) +wao.ui.form.updateWaoUserCommand.missingPassword=Il faut renseigner un mot de passe +wao.ui.form.updateWaoUserCommand.observer=Observateur +wao.ui.form.updateWaoUserCommand.observerReadOnly=Observateur (lecture seule) +wao.ui.form.updateWaoUserCommand.passwordMismatch=La confirmation du mot de passe ne correspond pas au mot de passe indiqué +wao.ui.form.updateWaoUserCommand.passwordStrategy=Changement du mot de passe +wao.ui.form.updateWaoUserCommand.professional=Professionel +wao.ui.form.updateWaoUserCommand.professionalReadOnly=Professionel (lecture seule) +wao.ui.form.updateWaoUserCommand.requiredCompany=Il faut associer l'utilisateur à une société +wao.ui.form.updateWaoUserCommand.success=Les modifications concernant l'utilisateur %s ont bien été enregistrées wao.ui.import.boatDistrictLabel=des coordonnées des quartiers des navires wao.ui.import.boatGroupsLabel=des strates des navires wao.ui.import.boatsLabel=des navires @@ -292,6 +327,7 @@ wao.ui.page.Synthesis.title=Synthèse wao.ui.page.UserProfileForm.title=Gestion du profil wao.ui.page.companies.title=Sociétés +wao.ui.page.waoUsers.title=Utilisateurs wao.ui.publishedByProgram=Publiée par le programme wao.ui.publishedByYourCompany=Publiée par la société wao.ui.sampleRow.creation=Création d'une ligne du plan d'échantillonnage Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/administration/companies.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/administration/companies.jsp 2014-03-05 11:21:07 UTC (rev 1712) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/administration/companies.jsp 2014-03-05 11:21:54 UTC (rev 1713) @@ -55,6 +55,13 @@ <s:a href="%{deleteCompanyUrl}"> <i class="icon-trash"></i> <s:text name="wao.ui.action.delete" /> </s:a> + + <s:url action="wao-users" id="waoUsersUrl"> + <s:param name="companyId" value="topiaId" /> + </s:url> + <s:a href="%{waoUsersUrl}"> + <i class="icon-list"></i> <s:text name="wao.ui.action.viewCompanyWaoUsers" /> + </s:a> </td> </tr> </s:iterator> Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp (from rev 1710, trunk/wao-web/src/main/webapp/WEB-INF/content/administration/edit-company.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,103 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + <head> + <script> + $(document).ready(function () { + + var showHideDefinePasswordFunction = function () { + var $definePassword = $('#definePassword'); + var $definePasswordInput = $('input[value="DEFINE_PASSWORD"]'); + if ($definePasswordInput.prop('checked')) { + $definePassword.show(); + } else { + $definePassword.hide(); + } + } + + $('input[name="updateWaoUserCommand\\.passwordStrategy"]').change(showHideDefinePasswordFunction); + + showHideDefinePasswordFunction(); + + }); + </script> + </head> + + <s:form> + + <s:hidden name="waoUserId" value="%{waoUserId}" /> + + <fieldset> + + <legend><s:text name="wao.ui.form.WaoUser.identity" /></legend> + + <s:textfield name="updateWaoUserCommand.waoUser.firstName" label="%{getText('wao.ui.field.WaoUser.firstName')}" /> + <s:textfield name="updateWaoUserCommand.waoUser.lastName" label="%{getText('wao.ui.field.WaoUser.lastName')}" /> + <s:select name="updateWaoUserCommand.companyId" + label="%{getText('wao.ui.entity.Company')}" + list="updateWaoUserCommand.allCompanies" + listValue="%{value.name}" /> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.WaoUser.credentials" /></legend> + + <s:textfield name="updateWaoUserCommand.waoUser.login" label="%{getText('wao.ui.field.WaoUser.login')}" requiredLabel="true" cssClass="input-xlarge" /> + + <s:radio name="updateWaoUserCommand.passwordStrategy" + label="%{getText('wao.ui.form.updateWaoUserCommand.passwordStrategy')}" + listValue="%{getText(top.i18nKey)}" + list="updateWaoUserCommandPasswordStrategies" + requiredLabel="true" /> + + <div id="definePassword"> + <s:textfield type="password" name="updateWaoUserCommand.clearPassword" label="%{getText('wao.ui.field.WaoUser.password')}" /> + <s:textfield type="password" name="updateWaoUserCommand.clearPasswordConfirmation" label="%{getText('wao.ui.form.repeatPassword')}" /> + </div> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.WaoUser.rights" /></legend> + + <s:checkbox name="updateWaoUserCommand.waoUser.active" label="%{getText('wao.ui.field.WaoUser.active')}" /> + + <s:checkbox name="updateWaoUserCommand.admin" label="%{getText('wao.ui.form.updateWaoUserCommand.admin')}" /> + <s:checkbox name="updateWaoUserCommand.adminReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.adminReadOnly')}" /> + <s:checkbox name="updateWaoUserCommand.coordinator" label="%{getText('wao.ui.form.updateWaoUserCommand.coordinator')}" /> + <s:checkbox name="updateWaoUserCommand.coordinatorReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.coordinatorReadOnly')}" /> + <s:checkbox name="updateWaoUserCommand.observer" label="%{getText('wao.ui.form.updateWaoUserCommand.observer')}" /> + <s:checkbox name="updateWaoUserCommand.observerReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.observerReadOnly')}" /> + <s:checkbox name="updateWaoUserCommand.guest" label="%{getText('wao.ui.form.updateWaoUserCommand.guest')}" /> + <s:checkbox name="updateWaoUserCommand.guestReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.guestReadOnly')}" /> + <s:checkbox name="updateWaoUserCommand.professional" label="%{getText('wao.ui.form.updateWaoUserCommand.professional')}" /> + <s:checkbox name="updateWaoUserCommand.professionalReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.professionalReadOnly')}" /> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.WaoUser.preferences" /></legend> + + <s:checkbox name="updateWaoUserCommand.waoUser.mammalsNotifications" label="%{getText('wao.ui.field.WaoUser.mammalsNotifications')}" /> + + </fieldset> + + <div class="form-actions"> + <s:url action="companies" id="companiesUrl" /> + <s:a href="%{companiesUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel" /> + </s:a> + + <s:submit type="button" cssClass="btn"> + <i class="icon-ok"></i> <s:text name="wao.ui.action.save" /> + </s:submit> + </div> + + </s:form> + +</html> Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp (from rev 1709, trunk/wao-web/src/main/webapp/WEB-INF/content/administration/companies.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp 2014-03-05 11:21:54 UTC (rev 1713) @@ -0,0 +1,74 @@ +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + + <head> + + </head> + + <h1><s:text name="wao.ui.page.waoUsers.title" /></h1> + + <table class="table table-bordered"> + <tr> + <th> + <s:text name="wao.ui.field.WaoUser.login" /> + </th> + <th> + <s:text name="wao.ui.field.WaoUser.fullName" /> + </th> + <th> + <s:text name="wao.ui.field.WaoUser.active" /> + </th> + <th> + <s:text name="wao.ui.actions" /> + </th> + </tr> + <s:iterator value="waoUsers"> + <tr> + <td> + <s:if test="active"> + <s:property value="login" /> + </s:if> + <s:else> + <del> + <s:property value="login" /> + </del> + </s:else> + </td> + <td> + <s:property value="fullName" /> + </td> + <td> + <s:if test="active"> + <s:text name="wao.ui.misc.yes" /> + </s:if> + <s:else> + <s:text name="wao.ui.misc.no" /> + </s:else> + </td> + <td> + <s:url action="edit-wao-user!input" id="editWaoUserUrl"> + <s:param name="waoUserId" value="topiaId" /> + </s:url> + <s:a href="%{editWaoUserUrl}"> + <i class="icon-edit"></i> <s:text name="wao.ui.action.edit" /> + </s:a> + + <s:url action="delete-wao-user" id="deleteWaoUserUrl"> + <s:param name="waoUserId" value="topiaId" /> + </s:url> + <s:a href="%{deleteWaoUserUrl}"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.delete" /> + </s:a> + </td> + </tr> + </s:iterator> + </table> + + <s:url action="edit-wao-user!input" id="createWaoUserUrl" /> + <s:a href="%{createWaoUserUrl}"> + <i class="icon-plus"></i> <s:text name="wao.ui.action.createWaoUser" /> + </s:a> + +</html>
participants (1)
-
bleny@users.forge.codelutin.com