Ejemplo n.º 1
0
def unassign(obj):
    """Check permission against parent worksheet
    """
    mtool = getToolByName(obj, "portal_membership")
    if not isBasicTransitionAllowed(obj):
        return False
    ws = obj.getBackReferences("WorksheetAnalysis")
    if not ws:
        return False
    ws = ws[0]
    if isBasicTransitionAllowed(ws):
        if mtool.checkPermission(Unassign, ws):
            return True
    return False
Ejemplo n.º 2
0
def unassign(obj):
    """Check permission against parent worksheet
    """
    mtool = getToolByName(obj, "portal_membership")
    if not isBasicTransitionAllowed(obj):
        return False
    ws = obj.getBackReferences("WorksheetAnalysis")
    if not ws:
        return False
    ws = ws[0]
    if isBasicTransitionAllowed(ws):
        if mtool.checkPermission(Unassign, ws):
            return True
    return False
Ejemplo n.º 3
0
def new_verify(obj):
    """
    Checks if the verify transition can be performed to the Analysis passed in
    by the current user depending on the user roles, the current status of the
    object and the number of verifications already performed.
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    nmvers = obj.getNumberOfVerifications()
    if nmvers == 0:
        # No verification has been done yet.
        # The analysis can only be verified it all its dependencies have
        # already been verified
        for dep in obj.getDependencies():
            if not verify(dep):
                return False

    revers = obj.getNumberOfRequiredVerifications()
    if revers - nmvers == 1:
        # All verifications performed except the last one. Check if the user
        # can perform the verification and if so, then allow the analysis to
        # be transitioned to the definitive "verified" state (otherwise will
        # remain in "to_be_verified" until all remmaining verifications - 1 are
        # performed
        mtool = getToolByName(obj, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        return obj.isUserAllowedToVerify(member)

    return False
Ejemplo n.º 4
0
def new_verify(obj):
    """
    Checks if the verify transition can be performed to the Analysis passed in
    by the current user depending on the user roles, the current status of the
    object and the number of verifications already performed.
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    nmvers = obj.getNumberOfVerifications()
    if nmvers == 0:
        # No verification has been done yet.
        # The analysis can only be verified it all its dependencies have
        # already been verified
        for dep in obj.getDependencies():
            if not verify(dep):
                return False

    revers = obj.getNumberOfRequiredVerifications()
    if revers - nmvers == 1:
        # All verifications performed except the last one. Check if the user
        # can perform the verification and if so, then allow the analysis to
        # be transitioned to the definitive "verified" state (otherwise will
        # remain in "to_be_verified" until all remmaining verifications - 1 are
        # performed
        mtool = getToolByName(obj, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        return obj.isUserAllowedToVerify(member)

    return False
Ejemplo n.º 5
0
def prepublish(obj):
    """Returns True if 'prepublish' transition can be applied to the Analysis
    Request passed in.
    Returns true if the Analysis Request is active (not in a cancelled/inactive
    state), the 'publish' transition cannot be performed yet, and at least one
    of its analysis is under to_be_verified state or has been already verified.
    As per default DC workflow definition in bika_ar_workflow, note that
    prepublish does not transitions the Analysis Request to any other state
    different from the actual one, neither its children. This 'fake' transition
    is only used for the prepublish action to be displayed when the Analysis
    Request' status is other than verified, so the labman can generate a
    provisional report, also if results are not yet definitive.
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    if isTransitionAllowed(obj, 'publish'):
        return False

    analyses = obj.getAnalyses(full_objects=True)
    for an in analyses:
        # If the analysis is not active, omit
        if not isActive(an):
            continue

        # Check if the current state is 'verified'
        status = getCurrentState(an)
        if status in ['verified', 'to_be_verified']:
            return True

    # This analysis request has no single result ready to be verified or
    # verified yet. In this situation, it doesn't make sense to publish a
    # provisional results reports without a single result to display
    return False
Ejemplo n.º 6
0
def prepublish(obj):
    """Returns True if 'prepublish' transition can be applied to the Analysis
    Request passed in.
    Returns true if the Analysis Request is active (not in a cancelled/inactive
    state), the 'publish' transition cannot be performed yet, and at least one
    of its analysis is under to_be_verified state or has been already verified.
    As per default DC workflow definition in bika_ar_workflow, note that
    prepublish does not transitions the Analysis Request to any other state
    different from the actual one, neither its children. This 'fake' transition
    is only used for the prepublish action to be displayed when the Analysis
    Request' status is other than verified, so the labman can generate a
    provisional report, also if results are not yet definitive.
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    if isTransitionAllowed(obj, 'publish'):
        return False

    analyses = obj.getAnalyses(full_objects=True)
    for an in analyses:
        # If the analysis is not active, omit
        if not isActive(an):
            continue

        # Check if the current state is 'verified'
        status = getCurrentState(an)
        if status in ['verified', 'to_be_verified']:
            return True

    # This analysis request has no single result ready to be verified or
    # verified yet. In this situation, it doesn't make sense to publish a
    # provisional results reports without a single result to display
    return False
Ejemplo n.º 7
0
 def guard_sample_prep_transition(self):
     """Allow the sampleprep automatic transition to fire.
     """
     if not isBasicTransitionAllowed(self):
         return False
     if self.getPreparationWorkflow():
         return True
     return False
Ejemplo n.º 8
0
 def guard_sample_prep_transition(self):
     """Allow the sampleprep automatic transition to fire.
     """
     if not isBasicTransitionAllowed(self):
         return False
     if self.getPreparationWorkflow():
         return True
     return False
Ejemplo n.º 9
0
def publish(obj):
    """Returns True if 'publish' transition can be applied to the Analysis
    Request passed in. Returns true if the Analysis Request is active (not in
    a cancelled/inactive state). As long as 'publish' transition, in accordance
    with its DC workflow can only be performed if its previous state is
    verified or published, there is no need of additional validations.
    :returns: true or false
    """
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 10
0
def publish(obj):
    """Returns True if 'publish' transition can be applied to the Analysis
    Request passed in. Returns true if the Analysis Request is active (not in
    a cancelled/inactive state). As long as 'publish' transition, in accordance
    with its DC workflow can only be performed if its previous state is
    verified or published, there is no need of additional validations.
    :returns: true or false
    """
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 11
0
def verify(obj):
    if not isBasicTransitionAllowed(obj):
        return False

    if obj.isVerifiable():
        mtool = getToolByName(obj, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        return obj.isUserAllowedToVerify(member)

    return False
Ejemplo n.º 12
0
def verify(obj):
    if not isBasicTransitionAllowed(obj):
        return False

    if obj.isVerifiable():
        mtool = getToolByName(obj, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        return obj.isUserAllowedToVerify(member)

    return False
Ejemplo n.º 13
0
def unassign(obj):
    """Allow or disallow transition depending on our children's states
    """
    # TODO Workflow UnAssign AR - To revisit. Is there any reason why we want an
    # AR to be in an 'assigned' state?. If no, remove the transition from the
    # workflow definition, as well as from here and from content.analysisrequest
    return False

    if not isBasicTransitionAllowed(obj):
        return False
    return True
Ejemplo n.º 14
0
def unassign(obj):
    """Allow or disallow transition depending on our children's states
    """
    # TODO Workflow UnAssign AR - To revisit. Is there any reason why we want an
    # AR to be in an 'assigned' state?. If no, remove the transition from the
    # workflow definition, as well as from here and from content.analysisrequest
    return False

    if not isBasicTransitionAllowed(obj):
        return False
    return True
Ejemplo n.º 15
0
 def guard_schedule_sampling_transition(self):
     """
     Prevent the transition if:
     - if the user isn't part of the sampling coordinators group
       and "sampling schedule" checkbox is set in bika_setup
     - if no date and samples have been defined
       and "sampling schedule" checkbox is set in bika_setup
     """
     if self.bika_setup.getScheduleSamplingEnabled() and isBasicTransitionAllowed(self):
         return True
     return False
Ejemplo n.º 16
0
def publish(obj):
    """ Returns true if the 'publish' transition can be performed to the
    analysis passed in.
    In accordance with bika_analysis_workflow, 'publish'
    transition can only be performed if the state of the analysis is verified,
    so this guard only checks if the analysis state is active: there is no need
    of additional checks, cause the DC Workflow machinery will already take
    care of them.
    :returns: true or false
    """
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 17
0
def publish(obj):
    """ Returns true if the 'publish' transition can be performed to the
    analysis passed in.
    In accordance with bika_analysis_workflow, 'publish'
    transition can only be performed if the state of the analysis is verified,
    so this guard only checks if the analysis state is active: there is no need
    of additional checks, cause the DC Workflow machinery will already take
    care of them.
    :returns: true or false
    """
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 18
0
def schedule_sampling(obj):
    """
    Prevent the transition if:
    - if the user isn't part of the sampling coordinators group
      and "sampling schedule" checkbox is set in bika_setup
    - if no date and samples have been defined
      and "sampling schedule" checkbox is set in bika_setup
    """
    if obj.bika_setup.getScheduleSamplingEnabled() and \
            isBasicTransitionAllowed(obj):
        return True
    return False
Ejemplo n.º 19
0
def verify(obj):
    """Returns True if 'verify' transition can be applied to the Worksheet
    passed in. This is, returns true if all the analyses assigned
    have already been verified. Those analyses that are in an inactive state
    (cancelled, inactive) are dismissed, but at least one analysis must be in
    an active state (and verified), otherwise always return False.
    Note this guard depends entirely on the current status of the children
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    dettached = ['rejected', 'retracted', 'attachment_due']
    return _children_are_ready(obj, 'verify', dettached)
Ejemplo n.º 20
0
def verify(obj):
    """Returns True if 'verify' transition can be applied to the Worksheet
    passed in. This is, returns true if all the analyses assigned
    have already been verified. Those analyses that are in an inactive state
    (cancelled, inactive) are dismissed, but at least one analysis must be in
    an active state (and verified), otherwise always return False.
    Note this guard depends entirely on the current status of the children
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    dettached = ['rejected', 'retracted', 'attachment_due']
    return _children_are_ready(obj, 'verify', dettached)
Ejemplo n.º 21
0
 def guard_receive_transition(self):
     """Prevent the receive transition from being available:
     - if object is cancelled
     - if any related ARs have field analyses with no result.
     """
     # Can't do anything to the object if it's cancelled
     if not isBasicTransitionAllowed(self):
         return False
     # check if any related ARs have field analyses with no result.
     for ar in self.getAnalysisRequests():
         field_analyses = ar.getAnalyses(getPointOfCapture="field", full_objects=True)
         no_results = [a for a in field_analyses if a.getResult() == ""]
         if no_results:
             return False
     return True
Ejemplo n.º 22
0
def submit(obj):
    """Returns if 'submit' transition can be applied to the worksheet passed in.
    By default, the target state for the 'submit' transition for a worksheet is
    'to_be_verified', so this guard returns true if all the analyses assigned
    to the worksheet have already been submitted. Those analyses that are in a
    non-valid state (cancelled, inactive) are dismissed in the evaluation, but
    at least one analysis must be in an active state (and submitted) for this
    guard to return True. Otherwise, always returns False.
    Note this guard depends entirely on the current status of the children.
    """
    if not isBasicTransitionAllowed(obj):
        return False

    dettached = ['rejected', 'retracted', 'attachment_due']
    return _children_are_ready(obj, 'submit', dettached)
Ejemplo n.º 23
0
def submit(obj):
    """Returns if 'submit' transition can be applied to the worksheet passed in.
    By default, the target state for the 'submit' transition for a worksheet is
    'to_be_verified', so this guard returns true if all the analyses assigned
    to the worksheet have already been submitted. Those analyses that are in a
    non-valid state (cancelled, inactive) are dismissed in the evaluation, but
    at least one analysis must be in an active state (and submitted) for this
    guard to return True. Otherwise, always returns False.
    Note this guard depends entirely on the current status of the children.
    """
    if not isBasicTransitionAllowed(obj):
        return False

    dettached = ['rejected', 'retracted', 'attachment_due']
    return _children_are_ready(obj, 'submit', dettached)
Ejemplo n.º 24
0
def guard_create_partitions(analysis_request):
    """Returns true if partitions can be created using the analysis request
    passed in as the source.
    """
    if not analysis_request.bika_setup.getShowPartitions():
        # If partitions are disabled in Setup, return False
        return False

    if not isBasicTransitionAllowed(analysis_request):
        return False

    if analysis_request.isPartition():
        # Do not allow the creation of partitions from partitions
        return False

    return True
Ejemplo n.º 25
0
 def guard_receive_transition(self):
     """Prevent the receive transition from being available:
     - if object is cancelled
     - if any related ARs have field analyses with no result.
     """
     # Can't do anything to the object if it's cancelled
     if not isBasicTransitionAllowed(self):
         return False
     # check if any related ARs have field analyses with no result.
     for ar in self.getAnalysisRequests():
         field_analyses = ar.getAnalyses(getPointOfCapture='field',
                                         full_objects=True)
         no_results = [a for a in field_analyses if a.getResult() == '']
         if no_results:
             return False
     return True
Ejemplo n.º 26
0
def guard_submit(context):
    if not IAnalysisRequest.providedBy(context):
        # Note that this guard is only used for bika_ar_workflow!
        return True

    logger.info("*** Custom Guard: submit **")
    if not isBasicTransitionAllowed(context):
        return False

    invalid = 0
    analyses = context.getAnalyses()
    for an in analyses:
        if an.review_state == 'to_be_verified':
            continue

        # The analysis has already been verified?
        an = api.get_object(an)
        if wasTransitionPerformed(an, 'submit'):
            continue

        # Maybe the analysis is in an 'inactive' state?
        if not isActive(an):
            invalid += 1
            continue

        # Maybe the analysis has been rejected or retracted?
        dettached = ['rejected', 'retracted', 'attachments_due']
        status = getCurrentState(an)
        if status in dettached:
            invalid += 1
            continue

        # At this point we can assume this analysis is an a valid state and
        # the AR could potentially be submitted, but the Analysis Request can
        # only be submitted if all the analyses have been submitted already
        return False

    # Be sure that at least there is one analysis in an active state, it
    # doesn't make sense to submit an Analysis Request if all the analyses that
    # contains are rejected or cancelled!
    return len(analyses) - invalid > 0
Ejemplo n.º 27
0
def verify(obj):
    """Returns True if 'verify' transition can be applied to the Analysis
    Request passed in. This is, returns true if all the analyses that contains
    have already been verified. Those analyses that are in an inactive state
    (cancelled, inactive) are dismissed, but at least one analysis must be in
    an active state (and verified), otherwise always return False. If the
    Analysis Request is in inactive state (cancelled/inactive), returns False
    Note this guard depends entirely on the current status of the children
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    analyses = obj.getAnalyses(full_objects=True)
    invalid = 0
    for an in analyses:
        # The analysis has already been verified?
        if wasTransitionPerformed(an, 'verify'):
            continue

        # Maybe the analysis is in an 'inactive' state?
        if not isActive(an):
            invalid += 1
            continue

        # Maybe the analysis has been rejected or retracted?
        dettached = ['rejected', 'retracted', 'attachments_due']
        status = getCurrentState(an)
        if status in dettached:
            invalid += 1
            continue

        # At this point we can assume this analysis is an a valid state and
        # could potentially be verified, but the Analysis Request can only be
        # verified if all the analyses have been transitioned to verified
        return False

    # Be sure that at least there is one analysis in an active state, it
    # doesn't make sense to verify an Analysis Request if all the analyses that
    # contains are rejected or cancelled!
    return len(analyses) - invalid > 0
Ejemplo n.º 28
0
def verify(obj):
    """Returns True if 'verify' transition can be applied to the Analysis
    Request passed in. This is, returns true if all the analyses that contains
    have already been verified. Those analyses that are in an inactive state
    (cancelled, inactive) are dismissed, but at least one analysis must be in
    an active state (and verified), otherwise always return False. If the
    Analysis Request is in inactive state (cancelled/inactive), returns False
    Note this guard depends entirely on the current status of the children
    :returns: true or false
    """
    if not isBasicTransitionAllowed(obj):
        return False

    analyses = obj.getAnalyses(full_objects=True)
    invalid = 0
    for an in analyses:
        # The analysis has already been verified?
        if wasTransitionPerformed(an, 'verify'):
            continue

        # Maybe the analysis is in an 'inactive' state?
        if not isActive(an):
            invalid += 1
            continue

        # Maybe the analysis has been rejected or retracted?
        dettached = ['rejected', 'retracted', 'attachments_due']
        status = getCurrentState(an)
        if status in dettached:
            invalid += 1
            continue

        # At this point we can assume this analysis is an a valid state and
        # could potentially be verified, but the Analysis Request can only be
        # verified if all the analyses have been transitioned to verified
        return False

    # Be sure that at least there is one analysis in an active state, it
    # doesn't make sense to verify an Analysis Request if all the analyses that
    # contains are rejected or cancelled!
    return len(analyses) - invalid > 0
Ejemplo n.º 29
0
 def guard_reinstate_transition(self):
     if not isBasicTransitionAllowed(self):
         return False
     return True
Ejemplo n.º 30
0
 def guard_cancel_transition(self):
     if not isBasicTransitionAllowed(self):
         return False
     return True
Ejemplo n.º 31
0
def receive(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 32
0
 def guard_reinstate_transition(self):
     if not isBasicTransitionAllowed(self):
         return False
     return True
Ejemplo n.º 33
0
def sample_prep(obj):
    """Allow the sampleprep automatic transition to fire.
    """
    if not isBasicTransitionAllowed(obj):
        return False
    return obj.getPreparationWorkflow()
Ejemplo n.º 34
0
def assign(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 35
0
def sample(obj):
    """ Returns true if the sample transition can be performed for the sample
    passed in.
    :returns: true or false
    """
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 36
0
def assign(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 37
0
def attach(obj):
    if not isBasicTransitionAllowed(obj):
        return False
    if not obj.getAttachment():
        return obj.getAttachmentOption() != 'r'
    return True
Ejemplo n.º 38
0
def import_transition(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 39
0
def sample_prep_complete(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 40
0
def attach(obj):
    if not isBasicTransitionAllowed(obj):
        return False
    if not obj.getAttachment():
        return obj.getAttachmentOption() != 'r'
    return True
Ejemplo n.º 41
0
def receive(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 42
0
 def guard_receive_transition(self):
     """Prevent the receive transition from being available if object
     is cancelled
     """
     # Can't do anything to the object if it's cancelled
     return isBasicTransitionAllowed(self)
Ejemplo n.º 43
0
def retract(obj):
    """ Returns true if the sample transition can be performed for the sample
    passed in.
    :returns: true or false
    """
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 44
0
def import_transition(obj):
    return isBasicTransitionAllowed(obj)
Ejemplo n.º 45
0
 def guard_cancel_transition(self):
     if not isBasicTransitionAllowed(self):
         return False
     return True
Ejemplo n.º 46
0
 def guard_receive_transition(self):
     """Prevent the receive transition from being available if object
     is cancelled
     """
     # Can't do anything to the object if it's cancelled
     return isBasicTransitionAllowed(self):
Ejemplo n.º 47
0
def sample_prep(obj):
    """Allow the sampleprep automatic transition to fire.
    """
    if not isBasicTransitionAllowed(obj):
        return False
    return obj.getPreparationWorkflow()
Ejemplo n.º 48
0
def sample_prep_complete(obj):
    return isBasicTransitionAllowed(obj)