Search in sources :

Example 6 with Database

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);
}
Also used : Database(org.activityinfo.server.database.hibernate.entity.Database) Partner(org.activityinfo.server.database.hibernate.entity.Partner) Date(java.util.Date) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 7 with Database

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;
}
Also used : Database(org.activityinfo.server.database.hibernate.entity.Database) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 8 with Database

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)));
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Database(org.activityinfo.server.database.hibernate.entity.Database) Test(org.junit.Test)

Example 9 with Database

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)));
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Database(org.activityinfo.server.database.hibernate.entity.Database) Test(org.junit.Test)

Example 10 with Database

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)));
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Database(org.activityinfo.server.database.hibernate.entity.Database) Test(org.junit.Test)

Aggregations

Database (org.activityinfo.server.database.hibernate.entity.Database)19 User (org.activityinfo.server.database.hibernate.entity.User)6 UserPermission (org.activityinfo.server.database.hibernate.entity.UserPermission)5 Test (org.junit.Test)5 Date (java.util.Date)4 Partner (org.activityinfo.server.database.hibernate.entity.Partner)3 ArrayList (java.util.ArrayList)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)2 HashMap (java.util.HashMap)1 AddProject (org.activityinfo.legacy.shared.command.AddProject)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 GetSyncRegions (org.activityinfo.legacy.shared.command.GetSyncRegions)1 RemovePartner (org.activityinfo.legacy.shared.command.RemovePartner)1 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)1 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)1 RemoveFailedResult (org.activityinfo.legacy.shared.command.result.RemoveFailedResult)1 RemoveResult (org.activityinfo.legacy.shared.command.result.RemoveResult)1 SyncRegion (org.activityinfo.legacy.shared.command.result.SyncRegion)1 SyncRegions (org.activityinfo.legacy.shared.command.result.SyncRegions)1