Search in sources :

Example 1 with ProjectTask

use of com.google.gerrit.server.git.WorkQueue.ProjectTask in project gerrit by GerritCodeReview.

the class TasksCollection method parse.

@Override
public TaskResource parse(ConfigResource parent, IdString id) throws ResourceNotFoundException, AuthException, PermissionBackendException {
    CurrentUser user = self.get();
    if (!user.isIdentifiedUser()) {
        throw new AuthException("Authentication required");
    }
    int taskId;
    try {
        taskId = (int) Long.parseLong(id.get(), 16);
    } catch (NumberFormatException e) {
        throw new ResourceNotFoundException(id);
    }
    Task<?> task = workQueue.getTask(taskId);
    if (task instanceof ProjectTask) {
        try {
            permissionBackend.user(user).project(((ProjectTask<?>) task).getProjectNameKey()).check(ProjectPermission.ACCESS);
            return new TaskResource(task);
        } catch (AuthException e) {
        // Fall through and try view queue permission.
        }
    }
    if (task != null) {
        try {
            permissionBackend.user(user).check(GlobalPermission.VIEW_QUEUE);
            return new TaskResource(task);
        } catch (AuthException e) {
        // Fall through and return not found.
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : CurrentUser(com.google.gerrit.server.CurrentUser) AuthException(com.google.gerrit.extensions.restapi.AuthException) ProjectTask(com.google.gerrit.server.git.WorkQueue.ProjectTask) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Aggregations

AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 ProjectTask (com.google.gerrit.server.git.WorkQueue.ProjectTask)1