use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class BrowseController method modifyAction.
/**
* Performs the action of modifying a collection
*
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "modify/action", method = RequestMethod.POST)
public String modifyAction(@ModelAttribute final CollectionOrDataObjectForm collForm, final RedirectAttributes redirectAttributes) throws DataGridException {
logger.info("modify/action starts...");
String previousPath = collForm.getPath();
String parentPath = previousPath.substring(0, previousPath.lastIndexOf("/"));
String newPath = String.format("%s/%s", parentPath, collForm.getCollectionName());
logger.info("previousPath: " + previousPath);
logger.info("parentPath: " + parentPath);
logger.info("newPath: " + newPath);
logger.info("Path values used to modify/action previousPath: {} to newPath: {}", previousPath, newPath);
boolean modificationSuccessful = cs.modifyCollectionAndDataObject(previousPath, newPath, collForm.getInheritOption());
// checking if the previousPath collection/dataobject was marked as favorite:
String username = irodsServices.getCurrentUser();
String zoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(username, zoneName);
boolean isMarkedFavorite = favoritesService.isPathFavoriteForUser(user, previousPath);
logger.info("Favorite status for previousPath: " + previousPath + " is: " + String.valueOf(isMarkedFavorite));
if (modificationSuccessful) {
logger.debug("Collection/Data Object {} modified to {}", previousPath, newPath);
if (isMarkedFavorite) {
Set<String> toAdd = new HashSet<String>();
Set<String> toRemove = new HashSet<String>();
toAdd.add(newPath);
toRemove.add(previousPath);
boolean operationResult = favoritesService.updateFavorites(user, toAdd, toRemove);
if (operationResult) {
logger.info("Favorite re-added successfully for: " + newPath);
} else {
logger.info("Error re-adding favorite to: " + newPath);
}
}
userBookmarkService.updateBookmark(previousPath, newPath);
groupBookmarkService.updateBookmark(previousPath, newPath);
redirectAttributes.addFlashAttribute("collectionModifiedSuccessfully", collForm.getCollectionName());
}
String template = "redirect:/collections" + parentPath;
logger.info("Returning after renaming :: " + template);
return "redirect:/collections?path=" + URLEncoder.encode(parentPath);
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class BrowseController method getCollBrowserView.
/**
* Finds all collections and data objects existing under a certain path
*
* @param model
* @param path
* path to get all directories and data objects from
* @return collections browser template that renders all items of certain path
* (parent)
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the grid.
*/
private String getCollBrowserView(final Model model, String path) throws JargonException, DataGridException {
logger.info("getCollBrowserView()");
logger.info("model:{}", model);
logger.info("path:{}", path);
logger.info("find collection by name:{}", path);
DataGridCollectionAndDataObject dataGridObj = null;
try {
dataGridObj = cs.findByName(path);
} catch (FileNotFoundException fnf) {
logger.warn("file not found for:{}", path);
// I don't have a path so use the user home
logger.info("no path, so using user home directory");
// TODO: refactor into something more elegant - mcc
model.addAttribute("invalidPath", path);
IRODSAccount irodsAccount = irodsServices.getCollectionAO().getIRODSAccount();
path = MiscIRODSUtils.buildIRODSUserHomeForAccountUsingDefaultScheme(irodsAccount);
}
if (path.endsWith("/") && path.compareTo("/") != 0) {
path = path.substring(0, path.length() - 1);
}
currentPath = path;
logger.info("currentPath:{}", currentPath);
DataGridUser user = loggedUserUtils.getLoggedDataGridUser();
if (zoneTrashPath == null || zoneTrashPath.isEmpty()) {
zoneTrashPath = String.format("/%s/trash", irodsServices.getCurrentUserZone());
}
// TODO: do I really need these permission path checks? I can let iRODS worry
// about permissions - mcc
CollectionOrDataObjectForm collectionForm = new CollectionOrDataObjectForm();
String permissionType = "none";
if (dataGridObj.isProxy()) {
logger.info("this is a proxy, so fake out the options");
collectionForm.setInheritOption(false);
permissionType = "read";
} else {
logger.info("this is not a proxy, so gather permission info");
permissionType = cs.getPermissionsForPath(path);
collectionForm.setInheritOption(cs.getInheritanceOptionForCollection(currentPath));
permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, user);
}
logger.debug("permission options are set");
boolean isPermissionOwn = "own".equals(permissionType);
boolean isTrash = path.contains(zoneTrashPath) && (isPermissionOwn || user.isAdmin());
boolean inheritanceDisabled = !isPermissionOwn && collectionForm.getInheritOption();
model.addAttribute("collectionAndDataObject", dataGridObj);
model.addAttribute("isTrash", isTrash);
model.addAttribute("permissionType", permissionType);
model.addAttribute("currentPath", currentPath);
model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
model.addAttribute("isCurrentPathCollection", cs.isCollection(path));
model.addAttribute("user", user);
model.addAttribute("trashColl", cs.getTrashForPath(currentPath));
model.addAttribute("collection", collectionForm);
model.addAttribute("inheritanceDisabled", inheritanceDisabled);
model.addAttribute("requestMapping", "/browse/add/action/");
model.addAttribute("parentPath", parentPath);
setBreadcrumbToModel(model, dataGridObj);
logger.info("forwarding to collections/collectionsBrowser");
return "collections/collectionsBrowser";
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class PermissionsController method addUserToCreationList.
@RequestMapping(value = "/addUserPermissions/")
@ResponseBody
public String addUserToCreationList(@RequestParam("permission") final String permission, @RequestParam("users") final String users, @RequestParam("path") final String path, @RequestParam("bookmark") final boolean bookmark, @RequestParam("recursive") final boolean recursive) throws DataGridConnectionRefusedException {
boolean operationResult = true;
String[] usernames = users.split(",");
DataGridPermType permType = DataGridPermType.valueOf(permission);
loggedUser = luu.getLoggedDataGridUser();
for (String username : usernames) {
if (us.findByUsername(username).isEmpty()) {
return REQUEST_ERROR;
}
}
for (String username : usernames) {
operationResult &= ps.setPermissionOnPath(permType, username, recursive, loggedUser.isAdmin(), path);
// Updating bookmarks for the recently-created permissions
if (bookmark) {
Set<String> bookmarks = new HashSet<String>();
bookmarks.add(path);
// Getting list of users and updating bookmarks
List<DataGridUser> dataGridUsers = us.findByUsername(username);
if (dataGridUsers != null && !dataGridUsers.isEmpty()) {
uBMS.updateBookmarks(dataGridUsers.get(0), bookmarks, null);
}
}
}
return operationResult ? REQUEST_OK : REQUEST_ERROR;
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class TemplateController method deleteTemplate.
@RequestMapping(value = "delete/")
public String deleteTemplate(final RedirectAttributes redirectAttributes) {
boolean deletionSuccessful = true;
for (Long templateId : selectedTemplates) {
logger.debug("Deleting template [{}]", templateId);
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
if (templateService.findById(templateId).getOwner().equalsIgnoreCase(loggedUser.getUsername())) {
deletionSuccessful &= templateService.deleteTemplate(templateId);
}
}
redirectAttributes.addFlashAttribute("templateRemovedSuccessfully", deletionSuccessful);
selectedTemplates.clear();
return "redirect:/templates/";
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class TicketClientController method index.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(final Model model, @RequestParam("ticketstring") final String ticketString, @RequestParam("ticketpath") final String path) throws DataGridConnectionRefusedException {
logger.info("Accessing ticket {} on {}", ticketString, path);
String objName = path.substring(path.lastIndexOf(IRODS_PATH_SEPARATOR) + 1, path.length());
model.addAttribute("objName", objName);
model.addAttribute("ticketString", ticketString);
model.addAttribute("path", path);
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
return loggedUser == null ? "tickets/ticketclient" : "tickets/ticketAuthAccess";
}
Aggregations