Search in sources :

Example 11 with ProjectAnalysisSubmissionJoin

use of ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin in project irida by phac-nml.

the class ReadAnalysisSubmissionPermission method customPermissionAllowed.

/**
 * {@inheritDoc}
 */
@Override
protected boolean customPermissionAllowed(Authentication authentication, AnalysisSubmission analysisSubmission) {
    logger.trace("Testing permission for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
    User u = userRepository.loadUserByUsername(authentication.getName());
    if (analysisSubmission.getSubmitter().equals(u)) {
        logger.trace("Permission GRANTED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
        return true;
    }
    /*
		 * If the user isn't set it might be shared to a project they have
		 * access to. Check the shared projects.
		 */
    List<ProjectAnalysisSubmissionJoin> projectsForSubmission = pasRepository.getProjectsForSubmission(analysisSubmission);
    boolean canReadProject = projectsForSubmission.stream().anyMatch(p -> readProjectPermission.customPermissionAllowed(authentication, p.getSubject()));
    if (canReadProject) {
        logger.trace("Permission GRANTED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
        return true;
    }
    /*
		 * If the user isn't set it might be an automated submission. Check if
		 * this analysis is the auto assembly or sistr for a file and if they
		 * can read the file
		 */
    Set<SequencingObject> pairedInputFiles = sequencingObjectRepository.findSequencingObjectsForAnalysisSubmission(analysisSubmission);
    boolean anyMatch = pairedInputFiles.stream().filter(o -> {
        AnalysisSubmission a = o.getAutomatedAssembly();
        AnalysisSubmission s = o.getSistrTyping();
        // check auto assembly
        boolean allowed = false;
        if (a != null) {
            allowed = a.equals(analysisSubmission);
        }
        // if not check sistr
        if (!allowed && s != null) {
            allowed = s.equals(analysisSubmission);
        }
        return allowed;
    }).anyMatch(p -> seqObjectPermission.customPermissionAllowed(authentication, p));
    if (anyMatch) {
        logger.trace("Permission GRANTED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
        return true;
    }
    logger.trace("Permission DENIED for [" + authentication + "] on analysis submission [" + analysisSubmission + "]");
    return false;
}
Also used : UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectRepository(ca.corefacility.bioinformatics.irida.repositories.sequencefile.SequencingObjectRepository) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) ReadProjectPermission(ca.corefacility.bioinformatics.irida.security.permissions.project.ReadProjectPermission) List(java.util.List) Component(org.springframework.stereotype.Component) BasePermission(ca.corefacility.bioinformatics.irida.security.permissions.BasePermission) ReadSequencingObjectPermission(ca.corefacility.bioinformatics.irida.security.permissions.files.ReadSequencingObjectPermission) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectAnalysisSubmissionJoinRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.ProjectAnalysisSubmissionJoinRepository) Authentication(org.springframework.security.core.Authentication) AnalysisSubmissionRepository(ca.corefacility.bioinformatics.irida.repositories.analysis.submission.AnalysisSubmissionRepository) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) User(ca.corefacility.bioinformatics.irida.model.user.User) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)

Aggregations

ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 Project (ca.corefacility.bioinformatics.irida.model.project.Project)7 Test (org.junit.Test)6 User (ca.corefacility.bioinformatics.irida.model.user.User)5 Authentication (org.springframework.security.core.Authentication)5 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)2 Transactional (javax.transaction.Transactional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)1 ExecutionManagerException (ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException)1 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)1