code: protected Project filterProjectByPermission(final Project project, final User user,
        final Permission.Type type, final Map<String, Object> ret) {
      if (project == null) {
        if (ret != null) {
          ret.put("error", "Project 'null' not found.");
        }
      } else if (!hasPermission(project, user, type)) {
        if (ret != null) {
          ret.put("error",
              "User '" + user.getUserId() + "' doesn't have " + type.name()
                  + " permissions on " + project.getName());
        }
      } else {
        return project;
      }
  
      return null;
    }
docs: Filter Project based on user authorization
  
  @param project project
  @param user user
  @param type permission allowance
  @param ret return map for holding messages
  @return authorized project itself or null if the project is not authorized