private static boolean userHasPermissionToCustomFieldProjects(final CustomField customField, final Set<String> browsableProjects) { if (customField.isAllProjects()) { return true; } else { final List<Project> projects = customField.getAssociatedProjectObjects(); if (projects == null) { return false; } for (final Project project : projects) { if (browsableProjects.contains(project.getKey())) { return true; } } } return false; }
private boolean hasCustomFieldAccess(final CustomField customField) { final ApplicationUser user = authenticationContext.getUser(); if (customField.isAllProjects()) { // if custom field is attached to all projects // check if current user can access any projects return permissionManager.hasProjects(BROWSE_PROJECTS, user); } // from all projects associated with this CF // find any that may be browsed by current user return Iterables.any(customField.getAssociatedProjectObjects(), new Predicate<Project>() { @Override public boolean apply(Project project) { return permissionManager.hasPermission(BROWSE_PROJECTS, project, user); } }); }
/** * Does the user have permission to at least one project that falls under this custom field. If the custom field * has not been configured for anything, it won't return true either * * @param customField custom field * @param user user * @return true if user has permission to at least one project that falls under this custom field, false otherwise */ public static boolean isUserHasPermissionToProjects(final CustomField customField, final ApplicationUser user) { if (customField.isAllProjects()) { return true; } else { final List<Project> projects = customField.getAssociatedProjectObjects(); if ((projects != null) && !projects.isEmpty()) { for (final Project project : projects) { if (ComponentAccessor.getComponent(PermissionManager.class).hasPermission(BROWSE_PROJECTS, project, user)) { return true; } } } } return false; }
public boolean isGlobalAvailable() { if (!getCustomField().isAllProjects()) { return true; } else { return (getFieldConfigScheme() != null) && getFieldConfigScheme().isAllProjects(); } }