'check accessibility or ownership of workflows, storedworkflows, and
workflowinvocations. Throw an exception or returns True if user has
needed level of access.'

def check_security(self, trans, has_workflow, check_ownership=True, check_accessible=True):

    if ((not check_ownership) or check_accessible):
        return True
    if isinstance(has_workflow, model.WorkflowInvocation):
        has_workflow = has_workflow.workflow
    if isinstance(has_workflow, model.Workflow):
        stored_workflow = has_workflow.top_level_stored_workflow
    else:
        stored_workflow = has_workflow
    if ((stored_workflow.user != trans.user) and (not trans.user_is_admin())):
        if check_ownership:
            raise exceptions.ItemOwnershipException()
        if (trans.sa_session.query(model.StoredWorkflowUserShareAssociation).filter_by(user=trans.user, stored_workflow=stored_workflow).count() == 0):
            raise exceptions.ItemAccessibilityException()
    return True
