'If there are no organisations that the user has update
permission for, prevents create & update of a record in
table & gives an warning if the user tries to.
@param table: the table or table name
@param error_msg: error message
@param redirect_on_error: whether to redirect on error'

def permitted_organisations(self, table=None, error_msg=None, redirect_on_error=True):

    T = current.T
    ERROR = T('You    do    not    have    permission    for    any    organization    to    perform    this    action.')
    HINT = T('Create    a    new    organization    or    ensure    that    you    have    permissions    for    an    existing    organization.')
    if (not error_msg):
        error_msg = ERROR
    s3db = current.s3db
    org_table = s3db.org_organisation
    query = self.s3_accessible_query('update', org_table)
    query &= (org_table.deleted == False)
    rows = current.db(query).select(org_table.id)
    if rows:
        return [org.id for org in rows]
    request = current.request
    if (('update' in request.args) or ('create' in request.args)):
        if redirect_on_error:
            current.session.error = ((error_msg + '    ') + HINT)
            redirect(URL(c='default', f='index'))
    elif (table is not None):
        if hasattr(table, '_tablename'):
            tablename = original_tablename(table)
        else:
            tablename = table
        s3db.configure(tablename, insertable=False)
    return []
