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
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
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
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
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
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
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
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
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)
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)
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
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
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
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
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
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)
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)
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
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)
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)
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
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)
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)
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
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
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
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
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
def guard_reinstate_transition(self): if not isBasicTransitionAllowed(self): return False return True
def guard_cancel_transition(self): if not isBasicTransitionAllowed(self): return False return True
def receive(obj): return isBasicTransitionAllowed(obj)
def guard_reinstate_transition(self): if not isBasicTransitionAllowed(self): return False return True
def sample_prep(obj): """Allow the sampleprep automatic transition to fire. """ if not isBasicTransitionAllowed(obj): return False return obj.getPreparationWorkflow()
def assign(obj): return isBasicTransitionAllowed(obj)
def sample(obj): """ Returns true if the sample transition can be performed for the sample passed in. :returns: true or false """ return isBasicTransitionAllowed(obj)
def assign(obj): return isBasicTransitionAllowed(obj)
def attach(obj): if not isBasicTransitionAllowed(obj): return False if not obj.getAttachment(): return obj.getAttachmentOption() != 'r' return True
def import_transition(obj): return isBasicTransitionAllowed(obj)
def sample_prep_complete(obj): return isBasicTransitionAllowed(obj)
def attach(obj): if not isBasicTransitionAllowed(obj): return False if not obj.getAttachment(): return obj.getAttachmentOption() != 'r' return True
def receive(obj): return isBasicTransitionAllowed(obj)
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)
def retract(obj): """ Returns true if the sample transition can be performed for the sample passed in. :returns: true or false """ return isBasicTransitionAllowed(obj)
def import_transition(obj): return isBasicTransitionAllowed(obj)
def guard_cancel_transition(self): if not isBasicTransitionAllowed(self): return False return True
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):
def sample_prep(obj): """Allow the sampleprep automatic transition to fire. """ if not isBasicTransitionAllowed(obj): return False return obj.getPreparationWorkflow()
def sample_prep_complete(obj): return isBasicTransitionAllowed(obj)