use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class GetUsersHandler method execute.
@Override
public CommandResult execute(GetUsers cmd, User currentUser) {
Database db = em.getReference(Database.class, cmd.getDatabaseId());
UserPermission currentUserPermission = PermissionOracle.using(em).getPermissionByUser(db, currentUser);
assertAuthorized(currentUserPermission);
String whereClause = "up.database.id = :dbId and " + "up.user.id <> :currentUserId and " + "up.allowView = true";
if (!currentUserPermission.isAllowManageAllUsers()) {
whereClause += " and up.partner.id = " + currentUserPermission.getPartner().getId();
}
TypedQuery<UserPermission> query = em.createQuery("select up from UserPermission up where " + whereClause + " " + composeOrderByClause(cmd), UserPermission.class).setParameter("dbId", cmd.getDatabaseId()).setParameter("currentUserId", currentUser.getId());
List<Folder> folders = em.createQuery("select f from Folder f where f.database.id = :dbId", Folder.class).setParameter("dbId", cmd.getDatabaseId()).getResultList();
Map<ResourceId, Folder> folderMap = new HashMap<>();
for (Folder folder : folders) {
folderMap.put(CuidAdapter.folderId(folder.getId()), folder);
}
if (cmd.getOffset() > 0) {
query.setFirstResult(cmd.getOffset());
}
if (cmd.getLimit() > 0) {
query.setMaxResults(cmd.getLimit());
}
List<UserPermissionDTO> models = new ArrayList<>();
for (UserPermission perm : query.getResultList()) {
UserPermissionDTO dto = new UserPermissionDTO();
dto.setEmail(perm.getUser().getEmail());
dto.setName(perm.getUser().getName());
dto.setOrganization(perm.getUser().getOrganization());
dto.setJobtitle(perm.getUser().getJobtitle());
dto.setAllowDesign(perm.isAllowDesign());
dto.setAllowView(perm.isAllowView());
dto.setAllowViewAll(perm.isAllowViewAll());
dto.setAllowEdit(perm.isAllowEdit());
dto.setAllowEditAll(perm.isAllowEditAll());
dto.setAllowManageUsers(perm.isAllowManageUsers());
dto.setAllowManageAllUsers(perm.isAllowManageAllUsers());
dto.setPartner(new PartnerDTO(perm.getPartner().getId(), perm.getPartner().getName()));
dto.setFolderLimitation(!Strings.isNullOrEmpty(perm.getModel()));
dto.setFolders(folderList(folderMap, perm));
models.add(dto);
}
return new UserResult(models, cmd.getOffset(), queryTotalCount(cmd, currentUser, whereClause));
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class CloneDatabaseHandler method createDefaultPartner.
private void createDefaultPartner(User user) {
Preconditions.checkNotNull(targetDb);
Preconditions.checkState(targetDb.getId() > 0);
PartnerDTO partner = new PartnerDTO();
partner.setName("Default");
new UpdatePartnerHandler(em).execute(new UpdatePartner(targetDb.getId(), partner), user);
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class SiteDTOs method newSite.
public static SiteDTO newSite() {
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setReportingPeriodId(new KeyGenerator().generateInt());
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setIndicatorValue(1, 996.0);
newSite.setIndicatorValue(2, null);
newSite.setAttributeValue(1, true);
newSite.setAttributeValue(2, false);
newSite.setComments("huba huba");
newSite.setProject(new ProjectDTO(1, "WoeiProject"));
return newSite;
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method setup.
@Before
public void setup() throws TemplateModelException {
NRC = new Partner();
NRC.setId(1);
NRC.setName("NRC");
NRC.setFullName("Norwegian Refugee Council");
db.persist(NRC);
IRC = new Partner();
IRC.setId(2);
IRC.setName("IRC");
IRC.setFullName("International Rescue Committee");
db.persist(IRC);
NRC_DTO = new PartnerDTO(1, "NRC");
TemplateModule templateModule = new TemplateModule();
mailer = new MailSenderStub(templateModule.provideConfiguration(Providers.of(Domain.DEFAULT)));
handler = new UpdateUserPermissionsHandler(db.getDAO(UserDatabaseDAO.class), db.getDAO(PartnerDAO.class), db.getDAO(UserDAO.class), db.getDAO(UserPermissionDAO.class), mailer);
owner = new User();
owner.setId(99);
owner.setName("Alex");
owner.setEmail("alex@bedatadriven.com");
db.persist(owner);
Database udb = new Database(1, "PEAR");
udb.setOwner(owner);
db.persist(udb);
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method testOwnerUpdate.
/**
* Verifies that the owner of a database can update an existing users permission
*/
@Test
@OnDataSet("/dbunit/schema1.db.xml")
public void testOwnerUpdate() throws CommandException {
setUser(1);
UserPermissionDTO user = new UserPermissionDTO();
user.setEmail("bavon@nrcdrc.org");
user.setPartner(new PartnerDTO(1, "NRC"));
user.setAllowView(true);
user.setAllowViewAll(false);
user.setAllowEdit(true);
user.setAllowEdit(false);
user.setAllowDesign(true);
execute(new UpdateUserPermissions(1, user));
UserResult result = execute(new GetUsers(1));
UserPermissionDTO reUser = result.getData().get(0);
assertThat(reUser.getEmail(), equalTo("bavon@nrcdrc.org"));
assertThat(reUser.getAllowDesign(), equalTo(true));
}
Aggregations