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 changedDefaultManagerPassword = false;
private Boolean changedDefaultHresourcesPassword = false;
private Boolean changedDefaultOutsourcingPassword = false;
private Boolean changedDefaultReportsPassword = false;
private Boolean autocompleteLogin = true;
private ProgressType progressType = ProgressType.SPREAD_PROGRESS;
@ -351,6 +359,46 @@ public class Configuration extends BaseEntity {
: 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() {
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.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.UserRole;
@ -126,4 +128,12 @@ public enum PredefinedProfiles {
.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() {
}
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.password = password;
this.roles = roles;
this.profiles = profiles;
}
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,
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() {

View file

@ -578,4 +578,76 @@
columnName="changed_default_user_password" />
</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>

View file

@ -51,6 +51,14 @@
column="changed_default_wswriter_password" />
<property name="changedDefaultWssubcontractingPassword" not-null="true"
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"
column="enabled_autocomplete_login" />
<property name="checkNewVersionEnabled" not-null="true"

View file

@ -147,6 +147,22 @@ public class TemplateController extends GenericForwardComposer {
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(
MandatoryUser mandatoryUser) {
return asDisplayProperty(templateModel
@ -180,6 +196,23 @@ public class TemplateController extends GenericForwardComposer {
.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() {
return templateModel.isUserAdmin();
}

View file

@ -55,6 +55,26 @@ public class PasswordUtil {
clearPassword);
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,
@ -85,12 +105,24 @@ public class PasswordUtil {
.hasChangedDefaultPasswordOrDisabled();
boolean wssubcontractingNotDefaultPassword = MandatoryUser.WSSUBCONTRACTING
.hasChangedDefaultPasswordOrDisabled();
boolean managerNotDefaultPassword = MandatoryUser.MANAGER
.hasChangedDefaultPasswordOrDisabled();
boolean hresourcesNotDefaultPassword = MandatoryUser.HRESOURCES
.hasChangedDefaultPasswordOrDisabled();
boolean outsourcingNotDefaultPassword = MandatoryUser.OUTSOURCING
.hasChangedDefaultPasswordOrDisabled();
boolean reportsNotDefaultPassword = MandatoryUser.REPORTS
.hasChangedDefaultPasswordOrDisabled();
Clients.evalJavaScript("showOrHideDefaultPasswordWarnings("
+ adminNotDefaultPassword + ", "
+ wsreaderNotDefaultPassword + ", "
+ 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.Registry;
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;
/**
@ -76,6 +78,37 @@ public enum MandatoryUser {
return getConfiguration()
.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() {
@ -98,13 +131,25 @@ public enum MandatoryUser {
.getConfigurationWithReadOnlyTransaction();
}
private Set<UserRole> initialRoles;
private Set<UserRole> initialRoles = new HashSet<UserRole>();
private Set<Profile> initialProfiles = new HashSet<Profile>();
private final boolean userDisabled;
private MandatoryUser(Collection<UserRole> initialUserRoles,
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;
}
@ -130,6 +175,10 @@ public enum MandatoryUser {
return initialRoles;
}
public Set<Profile> getInitialProfiles() {
return initialProfiles;
}
public static EnumSet<MandatoryUser> allExcept(MandatoryUser mandatoryUser) {
return EnumSet.complementOf(EnumSet.of(mandatoryUser));
}

View file

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

View file

@ -39,6 +39,10 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
idWsreader = templateController.getIdWsreaderUser();
idWswriter = templateController.getIdWswriterUser();
idWssubcontracting = templateController.getIdWssubcontractingUser();
idManager = templateController.getIdManagerUser();
idHresources = templateController.getIdHresourcesUser();
idOutsourcing = templateController.getIdOutsourcingUser();
idReports = templateController.getIdReportsUser();
]]>
</zscript>
@ -143,14 +147,26 @@ signature="java.lang.Boolean isDefaultPasswordsControl()"?>
style="display:${templateCtrl.defaultPasswdVisible}">
<div>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWsreader}"
id="warningDefaultPasswdwsreader"
id="warningDefaultPasswdWsreader"
style="display:${templateCtrl.defaultPasswdWsreaderVisible}">[wsreader]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWswriter}"
id="warningDefaultPasswdwswriter"
id="warningDefaultPasswdWswriter"
style="display:${templateCtrl.defaultPasswdWswriterVisible}">[wswriter]</n:a>
<n:a href="${contextPath}/users/users.zul#edit%3D${idWssubcontracting}"
id="warningDefaultPasswdwssubcontracting"
id="warningDefaultPasswdWssubcontracting"
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">
${i18n:_('default password were not changed')}.
</n:span>

View file

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