'Return all RequestTypes that the received user has permission to access.'

def get_accessible_request_types(self, trans, user):

    accessible_request_types = []
    current_user_role_ids = [role.id for role in user.all_roles()]
    request_type_access_action = self.permitted_actions.REQUEST_TYPE_ACCESS.action
    restricted_request_type_ids = [rtp.request_type_id for rtp in trans.sa_session.query(trans.model.RequestTypePermissions).filter((trans.model.RequestTypePermissions.table.c.action == request_type_access_action)).distinct()]
    accessible_restricted_request_type_ids = [rtp.request_type_id for rtp in trans.sa_session.query(trans.model.RequestTypePermissions).filter(and_((trans.model.RequestTypePermissions.table.c.action == request_type_access_action), trans.model.RequestTypePermissions.table.c.role_id.in_(current_user_role_ids)))]
    for request_type in trans.sa_session.query(trans.model.RequestType).filter(and_((trans.model.RequestType.table.c.deleted == false()), or_(not_(trans.model.RequestType.table.c.id.in_(restricted_request_type_ids)), trans.model.RequestType.table.c.id.in_(accessible_restricted_request_type_ids)))).order_by(trans.app.model.RequestType.name):
        accessible_request_types.append(request_type)
    return accessible_request_types
