use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class SignUpConfirmationController method addUserToDefaultDatabase.
protected void addUserToDefaultDatabase(User user) {
Database database = entityManager.find(Database.class, DEFAULT_DATABASE_ID);
if (database == null) {
LOGGER.severe("Default database " + DEFAULT_DATABASE_ID + " does not exist, unable to add user " + user.getEmail());
return;
}
Partner partner = entityManager.find(Partner.class, DEFAULT_PARTNER_ID);
if (partner == null) {
LOGGER.severe("Default partner " + DEFAULT_PARTNER_ID + " does not exist, unable to add user " + user.getEmail());
return;
}
UserPermission permission = new UserPermission(database, user);
permission.setPartner(partner);
permission.setAllowView(true);
permission.setAllowViewAll(true);
permission.setLastSchemaUpdate(new Date());
entityManager.persist(permission);
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class DesignAuthorizationHandler method isAuthorized.
@Override
public boolean isAuthorized(AuthenticatedUser requestingUser, SchemaElement entity) {
Preconditions.checkNotNull(requestingUser, "requestingUser");
Database database = entity.findOwningDatabase();
if (database.getOwner().getId() == requestingUser.getId()) {
return true;
}
for (UserPermission permission : database.getUserPermissions()) {
if (permission.getUser().getId() == requestingUser.getId() && permission.isAllowDesign()) {
return true;
}
}
return false;
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class GeoDigestModelBuilderTest method testFindDatabasesOwnerAndNotification.
@Test
public void testFindDatabasesOwnerAndNotification() throws Exception {
// owner & notification
User user = em.find(User.class, 1);
List<Database> dbs = geoDigestModelBuilder.findDatabases(user);
assertThat(dbs.size(), is(equalTo(2)));
assertTrue(dbs.contains(em.find(Database.class, 1)));
assertTrue(dbs.contains(em.find(Database.class, 2)));
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class GeoDigestModelBuilderTest method testFindDatabasesOwnerAndViewAndNotification.
@Test
public void testFindDatabasesOwnerAndViewAndNotification() throws Exception {
// owner & view & notification
User user = em.find(User.class, 100);
List<Database> dbs = geoDigestModelBuilder.findDatabases(user);
assertThat(dbs.size(), is(equalTo(2)));
assertTrue(dbs.contains(em.find(Database.class, 3)));
assertTrue(dbs.contains(em.find(Database.class, 100)));
}
use of org.activityinfo.server.database.hibernate.entity.Database in project activityinfo by bedatadriven.
the class GeoDigestModelBuilderTest method testFindDatabasesOnlyNotification.
@Test
public void testFindDatabasesOnlyNotification() throws Exception {
// only notification
User user = em.find(User.class, 7);
List<Database> dbs = geoDigestModelBuilder.findDatabases(user);
assertThat(dbs.size(), is(equalTo(0)));
}
Aggregations