use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class DbUserEditorActions method delete.
public void delete() {
panel.setModified(true);
final UserPermissionDTO model = grid.getSelectionModel().getSelectedItem();
model.setAllowView(false);
model.setAllowViewAll(false);
model.setAllowEdit(false);
model.setAllowEditAll(false);
model.setAllowDesign(false);
model.setAllowManageAllUsers(false);
model.setAllowManageUsers(false);
dispatcher.execute(new UpdateUserPermissions(db.getId(), model), new MaskingAsyncMonitor(panel, I18N.CONSTANTS.deleting()), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
panel.setModified(false);
}
@Override
public void onSuccess(VoidResult result) {
store.remove(model);
panel.setModified(false);
}
});
}
use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class DbUserEditorActions method save.
public void save(final NavigationCallback callback) {
BatchCommand batch = new BatchCommand();
for (Record record : store.getModifiedRecords()) {
batch.add(new UpdateUserPermissions(db.getId(), (UserPermissionDTO) record.getModel()));
}
dispatcher.execute(batch, new MaskingAsyncMonitor(panel, I18N.CONSTANTS.saving()), new AsyncCallback<BatchResult>() {
@Override
public void onFailure(Throwable caught) {
// handled by monitor
if (callback != null) {
callback.onDecided(false);
}
}
@Override
public void onSuccess(BatchResult result) {
store.commitChanges();
panel.setModified(false);
if (callback != null) {
callback.onDecided(true);
}
}
});
}
use of org.activityinfo.legacy.shared.model.UserPermissionDTO in project activityinfo by bedatadriven.
the class MailingListDialog method createMailingList.
private String createMailingList(List<UserPermissionDTO> users) {
StringBuilder emails = new StringBuilder();
for (UserPermissionDTO dto : users) {
emails.append("\"" + dto.getName() + "\"");
emails.append(" ");
emails.append("<" + dto.getEmail() + ">,");
emails.append(" ");
}
return emails.toString();
}
use of org.activityinfo.legacy.shared.model.UserPermissionDTO 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.UserPermissionDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method testVerifyAuthorityForViewByOtherPartner.
@Test
public void testVerifyAuthorityForViewByOtherPartner() throws IllegalAccessCommandException {
UserPermission executingUserPermissions = new UserPermission();
executingUserPermissions.setPartner(IRC);
executingUserPermissions.setAllowManageUsers(true);
executingUserPermissions.setAllowManageAllUsers(true);
UserPermissionDTO dto = new UserPermissionDTO();
dto.setPartner(NRC_DTO);
dto.setAllowView(true);
dto.setAllowEdit(true);
UpdateUserPermissions cmd = new UpdateUserPermissions(1, dto);
UpdateUserPermissionsHandler.verifyAuthority(cmd, executingUserPermissions);
}
Aggregations