use of org.activityinfo.legacy.shared.model.FolderDTO in project activityinfo by bedatadriven.
the class GetUsersHandler method createFolderDTO.
private FolderDTO createFolderDTO(Folder folder) {
FolderDTO dto = new FolderDTO();
dto.setId(folder.getId());
dto.setDatabaseId(folder.getDatabase().getId());
dto.setName(folder.getName());
return dto;
}
use of org.activityinfo.legacy.shared.model.FolderDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandler method constructModel.
private UserPermissionModel constructModel(UserPermission perm, UserPermissionDTO dto) {
List<GrantModel> grants = new ArrayList<>();
for (FolderDTO folderDTO : dto.getFolders()) {
GrantModel grant = new GrantModel.Builder().setResourceId(CuidAdapter.folderId(folderDTO.getId())).build();
grants.add(grant);
}
return new UserPermissionModel(perm.getUser().getId(), perm.getDatabase().getId(), grants);
}
use of org.activityinfo.legacy.shared.model.FolderDTO in project activityinfo by bedatadriven.
the class DesignTreeDropTarget method showFeedback.
@Override
protected void showFeedback(DNDEvent event) {
final TreePanel.TreeNode overItem = tree.findNode(event.getTarget());
if (overItem == null) {
clearStyles(event);
}
ModelData sourceModel = tree.getSelectionModel().getSelectedItem();
ModelData overModel = null;
if (overItem != null) {
overModel = overItem.getModel();
// Dropping a node onto itself? Abort.
if (overModel == sourceModel) {
clearStyles(event);
return;
}
// Dropping a node into one of its children? Nope.
List<ModelData> children = tree.getStore().getChildren(sourceModel, true);
if (children.contains(overItem.getModel())) {
clearStyles(event);
return;
}
}
// Now decide whether this move is legal
// insert = insert after the overItem as a sibling
// append = append to the overItem's children
boolean insert = false;
boolean append = false;
// For most items, we will only allow inserting within the same parent
if (overModel != null && tree.getStore().getParent(sourceModel) == tree.getStore().getParent(overModel)) {
insert = true;
}
// Activities/Forms can be moved into other folders
if (sourceModel instanceof ActivityDTO) {
if (overModel == null || overModel instanceof FolderDTO) {
insert = true;
append = true;
}
if (overModel instanceof ActivityDTO) {
insert = true;
}
}
// which operation is allowed.
if (append) {
setFeedback(DND.Feedback.BOTH);
} else {
setFeedback(DND.Feedback.INSERT);
}
if (append && overItem == null) {
handleAppend(event, overItem);
} else if (insert) {
handleInsert(event, overItem);
} else if (append) {
handleAppend(event, overItem);
} else {
if (activeItem != null) {
tree.getView().onDropChange(activeItem, false);
}
status = -1;
activeItem = null;
appendItem = null;
Insert.get().hide();
event.getStatus().setStatus(false);
}
}
use of org.activityinfo.legacy.shared.model.FolderDTO in project activityinfo by bedatadriven.
the class GetUsersHandler method folderList.
private List<FolderDTO> folderList(Map<ResourceId, Folder> folderMap, UserPermission perm) {
if (Strings.isNullOrEmpty(perm.getModel())) {
// Include all folders, as user has access to all
List<FolderDTO> folderList = new ArrayList<>(folderMap.size());
folderMap.values().forEach(folder -> folderList.add(createFolderDTO(folder)));
return folderList;
}
try {
UserPermissionModel model = UserPermissionModel.fromJson(Json.parse(perm.getModel()));
List<FolderDTO> folderList = new ArrayList<>();
for (GrantModel grantModel : model.getGrants()) {
Folder folder = folderMap.get(grantModel.getResourceId());
if (folder != null) {
folderList.add(createFolderDTO(folder));
}
}
return folderList;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Permissions model: " + perm.getModel());
LOGGER.log(Level.SEVERE, "Failed to parse permissions model", e);
return null;
}
}
use of org.activityinfo.legacy.shared.model.FolderDTO in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandlerTest method testFolderLevelUpdate.
@Test
@OnDataSet("/dbunit/schema3.db.xml")
public void testFolderLevelUpdate() {
setUser(1);
UserPermissionDTO newUser = new UserPermissionDTO();
newUser.setName("Bavon");
newUser.setEmail("bavon@nrcdrc.org");
newUser.setPartner(new PartnerDTO(1, "NRC"));
newUser.setAllowView(true);
newUser.setAllowViewAll(false);
newUser.setAllowEdit(true);
newUser.setAllowEdit(false);
newUser.setAllowDesign(true);
FolderDTO health = new FolderDTO();
health.setId(3);
newUser.setFolders(Arrays.asList(health));
newUser.setFolderLimitation(true);
execute(new UpdateUserPermissions(1, newUser));
UserResult users = execute(new GetUsers(1));
UserPermissionDTO bavon = users.getData().get(0);
assertThat(bavon.hasFolderLimitation(), equalTo(true));
}
Aggregations