Add restrictions by number of users and resources

A new column in configuration has been added and it should me modified manually
to limit the number of users and resources.
This commit is contained in:
Manuel Rego Casasnovas 2012-10-01 12:22:04 +02:00
parent b7d612b655
commit b940c78826
7 changed files with 75 additions and 0 deletions

View file

@ -113,6 +113,18 @@ public class Configuration extends BaseEntity {
private PersonalTimesheetsPeriodicityEnum personalTimesheetsPeriodicity = PersonalTimesheetsPeriodicityEnum.MONTHLY;
/**
* Maximum users configurable directly in database for SaaS products. If
* zero it means that there isn't any limitation.
*/
private Integer maxUsers = 0;
/**
* Maximum resources configurable directly in database for SaaS products. If
* zero it means that there isn't any limitation.
*/
private Integer maxResources = 0;
public void setDefaultCalendar(BaseCalendar defaultCalendar) {
this.defaultCalendar = defaultCalendar;
}
@ -470,4 +482,12 @@ public class Configuration extends BaseEntity {
this.personalTimesheetsPeriodicity = personalTimesheetsPeriodicity;
}
public Integer getMaxUsers() {
return maxUsers;
}
public Integer getMaxResources() {
return maxResources;
}
}

View file

@ -1186,4 +1186,17 @@ public abstract class Resource extends IntegrationEntity implements
resource.getShortDescription());
}
@AssertTrue(message = "You have exceeded the maximum limit of users")
public boolean checkMaxUsers() {
Integer maxResources = Registry.getConfigurationDAO()
.getConfiguration().getMaxResources();
if (maxResources != null && maxResources > 0) {
List<Resource> resources = Registry.getResourceDAO().findAll();
if (resources.size() > maxResources) {
return false;
}
}
return true;
}
}

View file

@ -100,4 +100,6 @@ public interface IUserDAO extends IGenericDAO<User, Long>{
*/
void remove(User user) throws InstanceNotFoundException;
List<User> findAll();
}

View file

@ -173,4 +173,9 @@ public class UserDAO extends GenericDAOHibernate<User, Long>
super.remove(user.getId());
}
@Override
public List<User> findAll() {
return list(User.class);
}
}

View file

@ -24,6 +24,7 @@ package org.libreplan.business.users.entities;
import static org.libreplan.business.i18n.I18nHelper._;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.validator.AssertTrue;
@ -343,4 +344,18 @@ public class User extends BaseEntity implements IHumanIdentifiable{
return isLibrePlanUser().equals(Boolean.TRUE) ? _("Database")
: _("LDAP");
}
@AssertTrue(message = "You have exceeded the maximum limit of users")
public boolean checkMaxUsers() {
Integer maxUsers = Registry.getConfigurationDAO().getConfiguration()
.getMaxUsers();
if (maxUsers != null && maxUsers > 0) {
List<User> users = Registry.getUserDAO().findAll();
if (users.size() > maxUsers) {
return false;
}
}
return true;
}
}

View file

@ -56,4 +56,21 @@
referencedTableName="type_of_work_hours" referencedColumnNames="id" />
</changeSet>
<changeSet id="add-max_users-and-max_resources-columns-to-configuration"
author="mrego">
<comment>Add max_users and max_resources columns to configuration</comment>
<addColumn tableName="configuration">
<column name="max_users" type="INTEGER" />
</addColumn>
<addColumn tableName="configuration">
<column name="max_resources" type="INTEGER" />
</addColumn>
<update tableName="configuration">
<column name="max_users" value="0" />
</update>
<update tableName="configuration">
<column name="max_resources" value="0" />
</update>
</changeSet>
</databaseChangeLog>

View file

@ -88,6 +88,9 @@
</type>
</property>
<property name="maxUsers" column="max_users" />
<property name="maxResources" column="max_resources" />
<component name="ldapConfiguration" class="org.libreplan.business.common.entities.LDAPConfiguration">
<property name="ldapHost" column="ldap_host"/>
<property name="ldapPort" column="ldap_port"/>