Add new example users

FEA: ItEr76S30PermissionsEnhancements
This commit is contained in:
Manuel Rego Casasnovas 2012-06-20 13:33:54 +02:00
parent c3b5232d16
commit b26430979c
11 changed files with 307 additions and 17 deletions

View file

@ -79,6 +79,14 @@ public class Configuration extends BaseEntity {
private Boolean changedDefaultWssubcontractingPassword = false; private Boolean changedDefaultWssubcontractingPassword = false;
private Boolean changedDefaultManagerPassword = false;
private Boolean changedDefaultHresourcesPassword = false;
private Boolean changedDefaultOutsourcingPassword = false;
private Boolean changedDefaultReportsPassword = false;
private Boolean autocompleteLogin = true; private Boolean autocompleteLogin = true;
private ProgressType progressType = ProgressType.SPREAD_PROGRESS; private ProgressType progressType = ProgressType.SPREAD_PROGRESS;
@ -351,6 +359,46 @@ public class Configuration extends BaseEntity {
: false; : false;
} }
public void setChangedDefaultManagerPassword(
Boolean changedDefaultManagerPassword) {
this.changedDefaultManagerPassword = changedDefaultManagerPassword;
}
public Boolean getChangedDefaultManagerPassword() {
return changedDefaultManagerPassword != null ? changedDefaultManagerPassword
: false;
}
public void setChangedDefaultHresourcesPassword(
Boolean changedDefaultHresourcesPassword) {
this.changedDefaultHresourcesPassword = changedDefaultHresourcesPassword;
}
public Boolean getChangedDefaultHresourcesPassword() {
return changedDefaultHresourcesPassword != null ? changedDefaultHresourcesPassword
: false;
}
public void setChangedDefaultOutsourcingPassword(
Boolean changedDefaultOutsourcingPassword) {
this.changedDefaultOutsourcingPassword = changedDefaultOutsourcingPassword;
}
public Boolean getChangedDefaultOutsourcingPassword() {
return changedDefaultOutsourcingPassword != null ? changedDefaultOutsourcingPassword
: false;
}
public void setChangedDefaultReportsPassword(
Boolean changedDefaultReportsPassword) {
this.changedDefaultReportsPassword = changedDefaultReportsPassword;
}
public Boolean getChangedDefaultReportsPassword() {
return changedDefaultReportsPassword != null ? changedDefaultReportsPassword
: false;
}
public LDAPConfiguration getLdapConfiguration() { public LDAPConfiguration getLdapConfiguration() {
return ldapConfiguration; return ldapConfiguration;
} }

View file

@ -60,6 +60,8 @@ import static org.libreplan.business.users.entities.UserRole.ROLE_WORK_REPORT_LI
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import org.libreplan.business.common.Registry;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.users.entities.Profile; import org.libreplan.business.users.entities.Profile;
import org.libreplan.business.users.entities.UserRole; import org.libreplan.business.users.entities.UserRole;
@ -126,4 +128,12 @@ public enum PredefinedProfiles {
.create(name, new HashSet<UserRole>(Arrays.asList(roles))); .create(name, new HashSet<UserRole>(Arrays.asList(roles)));
} }
public Profile getFromDB() {
try {
return Registry.getProfileDAO().findByProfileName(name);
} catch (InstanceNotFoundException e) {
return null;
}
}
} }

View file

@ -83,10 +83,12 @@ public class User extends BaseEntity implements IHumanIdentifiable{
public User() { public User() {
} }
private User(String loginName, String password, Set<UserRole> roles) { private User(String loginName, String password, Set<UserRole> roles,
Set<Profile> profiles) {
this.loginName = loginName; this.loginName = loginName;
this.password = password; this.password = password;
this.roles = roles; this.roles = roles;
this.profiles = profiles;
} }
private User(String loginName, String password, String email) { private User(String loginName, String password, String email) {
@ -97,9 +99,12 @@ public class User extends BaseEntity implements IHumanIdentifiable{
public static User create(String loginName, String password, public static User create(String loginName, String password,
Set<UserRole> roles) { Set<UserRole> roles) {
return create(loginName, password, roles, new HashSet<Profile>());
}
return create(new User(loginName, password, roles)); public static User create(String loginName, String password,
Set<UserRole> roles, Set<Profile> profiles) {
return create(new User(loginName, password, roles, profiles));
} }
public static User create() { public static User create() {

View file

@ -578,4 +578,76 @@
columnName="changed_default_user_password" /> columnName="changed_default_user_password" />
</changeSet> </changeSet>
<changeSet id="add-new-column-changed_default_manager_password" author="mrego">
<comment>
Add new column changed_default_manager_password with
default value FALSE to configuration table
</comment>
<addColumn tableName="configuration">
<column name="changed_default_manager_password"
type="BOOLEAN" />
</addColumn>
<addDefaultValue tableName="configuration"
columnName="changed_default_manager_password"
defaultValueBoolean="FALSE" />
<addNotNullConstraint tableName="configuration"
columnName="changed_default_manager_password"
defaultNullValue="FALSE"
columnDataType="BOOLEAN" />
</changeSet>
<changeSet id="add-new-column-changed_default_hresources_password" author="mrego">
<comment>
Add new column changed_default_hresources_password with
default value FALSE to configuration table
</comment>
<addColumn tableName="configuration">
<column name="changed_default_hresources_password"
type="BOOLEAN" />
</addColumn>
<addDefaultValue tableName="configuration"
columnName="changed_default_hresources_password"
defaultValueBoolean="FALSE" />
<addNotNullConstraint tableName="configuration"
columnName="changed_default_hresources_password"
defaultNullValue="FALSE"
columnDataType="BOOLEAN" />
</changeSet>
<changeSet id="add-new-column-changed_default_outsourcing_password" author="mrego">
<comment>
Add new column changed_default_outsourcing_password with
default value FALSE to configuration table
</comment>
<addColumn tableName="configuration">
<column name="changed_default_outsourcing_password"
type="BOOLEAN" />
</addColumn>
<addDefaultValue tableName="configuration"
columnName="changed_default_outsourcing_password"
defaultValueBoolean="FALSE" />
<addNotNullConstraint tableName="configuration"
columnName="changed_default_outsourcing_password"
defaultNullValue="FALSE"
columnDataType="BOOLEAN" />
</changeSet>
<changeSet id="add-new-column-changed_default_reports_password" author="mrego">
<comment>
Add new column changed_default_reports_password with
default value FALSE to configuration table
</comment>
<addColumn tableName="configuration">
<column name="changed_default_reports_password"
type="BOOLEAN" />
</addColumn>
<addDefaultValue tableName="configuration"
columnName="changed_default_reports_password"
defaultValueBoolean="FALSE" />
<addNotNullConstraint tableName="configuration"
columnName="changed_default_reports_password"
defaultNullValue="FALSE"
columnDataType="BOOLEAN" />
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View file

@ -51,6 +51,14 @@
column="changed_default_wswriter_password" /> column="changed_default_wswriter_password" />
<property name="changedDefaultWssubcontractingPassword" not-null="true" <property name="changedDefaultWssubcontractingPassword" not-null="true"
column="changed_default_wssubcontracting_password" /> column="changed_default_wssubcontracting_password" />
<property name="changedDefaultManagerPassword" not-null="true"
column="changed_default_manager_password" />
<property name="changedDefaultHresourcesPassword" not-null="true"
column="changed_default_hresources_password" />
<property name="changedDefaultOutsourcingPassword" not-null="true"
column="changed_default_outsourcing_password" />
<property name="changedDefaultReportsPassword" not-null="true"
column="changed_default_reports_password" />
<property name="autocompleteLogin" not-null="true" <property name="autocompleteLogin" not-null="true"
column="enabled_autocomplete_login" /> column="enabled_autocomplete_login" />
<property name="checkNewVersionEnabled" not-null="true" <property name="checkNewVersionEnabled" not-null="true"

View file

@ -147,6 +147,22 @@ public class TemplateController extends GenericForwardComposer {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSSUBCONTRACTING); return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.WSSUBCONTRACTING);
} }
public String getDefaultPasswdManagerVisible() {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.MANAGER);
}
public String getDefaultPasswdHresourcesVisible() {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.HRESOURCES);
}
public String getDefaultPasswdOutsourcingVisible() {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.OUTSOURCING);
}
public String getDefaultPasswdReportsVisible() {
return notChangedPasswordWarningDisplayPropertyFor(MandatoryUser.REPORTS);
}
private String notChangedPasswordWarningDisplayPropertyFor( private String notChangedPasswordWarningDisplayPropertyFor(
MandatoryUser mandatoryUser) { MandatoryUser mandatoryUser) {
return asDisplayProperty(templateModel return asDisplayProperty(templateModel
@ -180,6 +196,23 @@ public class TemplateController extends GenericForwardComposer {
.getLoginName()); .getLoginName());
} }
public String getIdManagerUser() {
return templateModel.getIdUser(MandatoryUser.MANAGER.getLoginName());
}
public String getIdHresourcesUser() {
return templateModel.getIdUser(MandatoryUser.HRESOURCES.getLoginName());
}
public String getIdOutsourcingUser() {
return templateModel
.getIdUser(MandatoryUser.OUTSOURCING.getLoginName());
}
public String getIdReportsUser() {
return templateModel.getIdUser(MandatoryUser.REPORTS.getLoginName());
}
public boolean isUserAdmin() { public boolean isUserAdmin() {
return templateModel.isUserAdmin(); return templateModel.isUserAdmin();
} }

View file

@ -55,6 +55,26 @@ public class PasswordUtil {
clearPassword); clearPassword);
return; return;
} }
if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.MANAGER.getLoginName())) {
checkIfChangeDefaultPasswd(MandatoryUser.MANAGER, clearPassword);
return;
}
if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.HRESOURCES.getLoginName())) {
checkIfChangeDefaultPasswd(MandatoryUser.HRESOURCES, clearPassword);
return;
}
if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.OUTSOURCING.getLoginName())) {
checkIfChangeDefaultPasswd(MandatoryUser.OUTSOURCING, clearPassword);
return;
}
if (user.getLoginName().equalsIgnoreCase(
MandatoryUser.REPORTS.getLoginName())) {
checkIfChangeDefaultPasswd(MandatoryUser.REPORTS, clearPassword);
return;
}
} }
private static void checkIfChangeDefaultPasswd(MandatoryUser user, private static void checkIfChangeDefaultPasswd(MandatoryUser user,
@ -85,12 +105,24 @@ public class PasswordUtil {
.hasChangedDefaultPasswordOrDisabled(); .hasChangedDefaultPasswordOrDisabled();
boolean wssubcontractingNotDefaultPassword = MandatoryUser.WSSUBCONTRACTING boolean wssubcontractingNotDefaultPassword = MandatoryUser.WSSUBCONTRACTING
.hasChangedDefaultPasswordOrDisabled(); .hasChangedDefaultPasswordOrDisabled();
boolean managerNotDefaultPassword = MandatoryUser.MANAGER
.hasChangedDefaultPasswordOrDisabled();
boolean hresourcesNotDefaultPassword = MandatoryUser.HRESOURCES
.hasChangedDefaultPasswordOrDisabled();
boolean outsourcingNotDefaultPassword = MandatoryUser.OUTSOURCING
.hasChangedDefaultPasswordOrDisabled();
boolean reportsNotDefaultPassword = MandatoryUser.REPORTS
.hasChangedDefaultPasswordOrDisabled();
Clients.evalJavaScript("showOrHideDefaultPasswordWarnings(" Clients.evalJavaScript("showOrHideDefaultPasswordWarnings("
+ adminNotDefaultPassword + ", " + adminNotDefaultPassword + ", "
+ wsreaderNotDefaultPassword + ", " + wsreaderNotDefaultPassword + ", "
+ wswriterNotDefaultPassword + ", " + wswriterNotDefaultPassword + ", "
+ wssubcontractingNotDefaultPassword + ");"); + wssubcontractingNotDefaultPassword + ", "
+ managerNotDefaultPassword + ", "
+ hresourcesNotDefaultPassword + ", "
+ outsourcingNotDefaultPassword + ", "
+ reportsNotDefaultPassword + ");");
} }
} }

View file

@ -30,6 +30,8 @@ import java.util.Set;
import org.libreplan.business.common.Configuration; import org.libreplan.business.common.Configuration;
import org.libreplan.business.common.Registry; import org.libreplan.business.common.Registry;
import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.InstanceNotFoundException;
import org.libreplan.business.users.bootstrap.PredefinedProfiles;
import org.libreplan.business.users.entities.Profile;
import org.libreplan.business.users.entities.UserRole; import org.libreplan.business.users.entities.UserRole;
/** /**
@ -76,6 +78,37 @@ public enum MandatoryUser {
return getConfiguration() return getConfiguration()
.getChangedDefaultWssubcontractingPassword(); .getChangedDefaultWssubcontractingPassword();
} }
},
MANAGER(null,
Arrays.asList(PredefinedProfiles.PROJECT_MANAGER.getFromDB()),
Configuration.isExampleUsersDisabled()) {
@Override
public boolean hasChangedDefaultPassword() {
return getConfiguration()
.getChangedDefaultManagerPassword();
}
},
HRESOURCES(null, Arrays
.asList(PredefinedProfiles.HUMAN_RESOURCES_AND_COSTS_MANAGER
.getFromDB()), Configuration.isExampleUsersDisabled()) {
@Override
public boolean hasChangedDefaultPassword() {
return getConfiguration().getChangedDefaultManagerPassword();
}
},
OUTSOURCING(null, Arrays.asList(PredefinedProfiles.OUTSOURCING_MANAGER
.getFromDB()), Configuration.isExampleUsersDisabled()) {
@Override
public boolean hasChangedDefaultPassword() {
return getConfiguration().getChangedDefaultManagerPassword();
}
},
REPORTS(null, Arrays.asList(PredefinedProfiles.REPORTS_RESPONSIBLE
.getFromDB()), Configuration.isExampleUsersDisabled()) {
@Override
public boolean hasChangedDefaultPassword() {
return getConfiguration().getChangedDefaultManagerPassword();
}
}; };
public static boolean adminChangedAndSomeOtherNotChanged() { public static boolean adminChangedAndSomeOtherNotChanged() {
@ -98,13 +131,25 @@ public enum MandatoryUser {
.getConfigurationWithReadOnlyTransaction(); .getConfigurationWithReadOnlyTransaction();
} }
private Set<UserRole> initialRoles; private Set<UserRole> initialRoles = new HashSet<UserRole>();
private Set<Profile> initialProfiles = new HashSet<Profile>();
private final boolean userDisabled; private final boolean userDisabled;
private MandatoryUser(Collection<UserRole> initialUserRoles, private MandatoryUser(Collection<UserRole> initialUserRoles,
boolean userDisabled) { boolean userDisabled) {
this.initialRoles = new HashSet<UserRole>(initialUserRoles); this(initialUserRoles, null, userDisabled);
}
private MandatoryUser(Collection<UserRole> initialUserRoles,
Collection<Profile> initialProfiles, boolean userDisabled) {
if (initialUserRoles != null) {
this.initialRoles = new HashSet<UserRole>(initialUserRoles);
}
if (initialProfiles != null) {
this.initialProfiles = new HashSet<Profile>(initialProfiles);
}
this.userDisabled = userDisabled; this.userDisabled = userDisabled;
} }
@ -130,6 +175,10 @@ public enum MandatoryUser {
return initialRoles; return initialRoles;
} }
public Set<Profile> getInitialProfiles() {
return initialProfiles;
}
public static EnumSet<MandatoryUser> allExcept(MandatoryUser mandatoryUser) { public static EnumSet<MandatoryUser> allExcept(MandatoryUser mandatoryUser) {
return EnumSet.complementOf(EnumSet.of(mandatoryUser)); return EnumSet.complementOf(EnumSet.of(mandatoryUser));
} }

View file

@ -61,7 +61,7 @@ public class UsersBootstrapInDB implements IUsersBootstrapInDB {
if (!userDAO.existsByLoginName(u.getLoginName())) { if (!userDAO.existsByLoginName(u.getLoginName())) {
User user = User.create(u.getLoginName(), getEncodedPassword(u), User user = User.create(u.getLoginName(), getEncodedPassword(u),
u.getInitialRoles()); u.getInitialRoles(), u.getInitialProfiles());
user.setDisabled(u.isUserDisabled()); user.setDisabled(u.isUserDisabled());
userDAO.save(user); userDAO.save(user);

View file

@ -39,6 +39,10 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
idWsreader = templateController.getIdWsreaderUser(); idWsreader = templateController.getIdWsreaderUser();
idWswriter = templateController.getIdWswriterUser(); idWswriter = templateController.getIdWswriterUser();
idWssubcontracting = templateController.getIdWssubcontractingUser(); idWssubcontracting = templateController.getIdWssubcontractingUser();
idManager = templateController.getIdManagerUser();
idHresources = templateController.getIdHresourcesUser();
idOutsourcing = templateController.getIdOutsourcingUser();
idReports = templateController.getIdReportsUser();
]]> ]]>
</zscript> </zscript>
@ -143,14 +147,26 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
style="display:${templateCtrl.defaultPasswdVisible}"> style="display:${templateCtrl.defaultPasswdVisible}">
<div> <div>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWsreader}" <n:a href="${contextPath}/users/users.zul#edit%3D${idWsreader}"
id="warningDefaultPasswdwsreader" id="warningDefaultPasswdWsreader"
style="display:${templateCtrl.defaultPasswdWsreaderVisible}">[wsreader]</n:a> style="display:${templateCtrl.defaultPasswdWsreaderVisible}">[wsreader]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWswriter}" <n:a href="${contextPath}/users/users.zul#edit%3D${idWswriter}"
id="warningDefaultPasswdwswriter" id="warningDefaultPasswdWswriter"
style="display:${templateCtrl.defaultPasswdWswriterVisible}">[wswriter]</n:a> style="display:${templateCtrl.defaultPasswdWswriterVisible}">[wswriter]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWssubcontracting}" <n:a href="${contextPath}/users/users.zul#edit%3D${idWssubcontracting}"
id="warningDefaultPasswdwssubcontracting" id="warningDefaultPasswdWssubcontracting"
style="display:${templateCtrl.defaultPasswdWssubcontractingVisible}">[wssubcontracting]</n:a> style="display:${templateCtrl.defaultPasswdWssubcontractingVisible}">[wssubcontracting]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idManager}"
id="warningDefaultPasswdManager"
style="display:${templateCtrl.defaultPasswdManagerVisible}">[manager]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idHresources}"
id="warningDefaultPasswdHresources"
style="display:${templateCtrl.defaultPasswdHresourcesVisible}">[hresources]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idOutsourcing}"
id="warningDefaultPasswdOutsourcing"
style="display:${templateCtrl.defaultPasswdOutsourcingVisible}">[outsourcing]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idReports}"
id="warningDefaultPasswdReports"
style="display:${templateCtrl.defaultPasswdReportsVisible}">[reports]</n:a>
<n:span class="footer-messages-area"> <n:span class="footer-messages-area">
${i18n:_('default password were not changed')}. ${i18n:_('default password were not changed')}.
</n:span> </n:span>

View file

@ -21,24 +21,41 @@ function showOrHideDefaultPasswordWarnings(
adminNotDefaultPassword, adminNotDefaultPassword,
wsreaderNotDefaultPassword, wsreaderNotDefaultPassword,
wswriterNotDefaultPassword, wswriterNotDefaultPassword,
wssubcontractingNotDefaultPassword) { wssubcontractingNotDefaultPassword,
managerNotDefaultPassword,
hresourcesNotDefaultPassword,
outsourcingNotDefaultPassword,
reportsNotDefaultPassword) {
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdadmin"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdadmin"),
adminNotDefaultPassword); adminNotDefaultPassword);
var otherDefaultPassword = adminNotDefaultPassword && var otherDefaultPassword = adminNotDefaultPassword && (
(!wsreaderNotDefaultPassword || !wsreaderNotDefaultPassword ||
!wswriterNotDefaultPassword || !wssubcontractingNotDefaultPassword); !wswriterNotDefaultPassword ||
!wssubcontractingNotDefaultPassword ||
!managerNotDefaultPassword ||
!hresourcesNotDefaultPassword ||
!outsourcingNotDefaultPassword ||
!reportsNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdOthers"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdOthers"),
!otherDefaultPassword); !otherDefaultPassword);
if (otherDefaultPassword) { if (otherDefaultPassword) {
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwsreader"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdWsreader"),
wsreaderNotDefaultPassword); wsreaderNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwswriter"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdWswriter"),
wswriterNotDefaultPassword); wswriterNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwssubcontracting"), setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdWssubcontracting"),
wssubcontractingNotDefaultPassword); wssubcontractingNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdManager"),
managerNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdHresources"),
hresourcesNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdOutsourcing"),
outsourcingNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdReports"),
reportsNotDefaultPassword);
} }
} }