Search in sources :

Example 16 with DataGridUser

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);
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with DataGridUser

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";
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionOrDataObjectForm(com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm)

Example 18 with DataGridUser

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;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridPermType(com.emc.metalnx.core.domain.entity.enums.DataGridPermType) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with DataGridUser

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/";
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with DataGridUser

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";
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 JargonException (org.irods.jargon.core.exception.JargonException)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)5 User (org.irods.jargon.core.pub.domain.User)5 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)4 HashMap (java.util.HashMap)4 Query (org.hibernate.Query)4 UserAO (org.irods.jargon.core.pub.UserAO)4 Authentication (org.springframework.security.core.Authentication)4 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)2 DataGridUserFavorite (com.emc.metalnx.core.domain.entity.DataGridUserFavorite)2 URLMap (com.emc.metalnx.modelattribute.enums.URLMap)2 GroupForm (com.emc.metalnx.modelattribute.group.GroupForm)2