'Returns the Approver for a new Registration &
the organisation_id field
@param: user - the user record (form.vars when done direct)
@ToDo: Support multiple approvers per Org - via Org Admin (or specific Role?)
Split into separate functions to returning approver & finding users\' org from auth_organisations
@returns approver, organisation_id - if approver = False, user is automatically approved by whitelist'

def s3_approver(self, user):

    db = current.db
    approver = None
    organisation_id = user.get('organisation_id')
    table = current.s3db.auth_organisation
    if organisation_id:
        query = ((table.organisation_id == organisation_id) & (table.deleted == False))
        record = db(query).select(table.approver, limitby=(0, 1)).first()
    elif (('email' in user) and user['email'] and ('@' in user['email'])):
        domain = user.email.split('@', 1)[(-1)]
        query = ((table.domain == domain) & (table.deleted == False))
        record = db(query).select(table.organisation_id, table.approver, limitby=(0, 1)).first()
    else:
        record = None
    if record:
        if (not organisation_id):
            organisation_id = record.organisation_id
        approver = record.approver
    if (not approver):
        approver = current.deployment_settings.get_mail_approver()
        if ('@' not in approver):
            utable = db.auth_user
            mtable = db.auth_membership
            gtable = db.auth_group
            query = (((gtable.uuid == approver) & (gtable.id == mtable.group_id)) & (mtable.user_id == utable.id))
            rows = db(query).select(utable.email, utable.language, distinct=True)
            approver = rows.as_list()
    return (approver, organisation_id)
