Example #1
0
def get_sub_orgs(userid, data_filter):
    user_info = User.get_by_id(userid, ['user_info']).get('user_info')
    role = user_info.get('role') or 1
    if role >= 100:
        org = data_filter.get('user_info').get('org')
        if org:
            res = Organization.get_by_name(org).get('sub_orgs') or []
            return res
        list = []
        res = Organization.get_iter()
        for e in res:
            cur_list = e.get('sub_orgs') or []
            list.extend(cur_list)
        return list
    elif 4 <= role < 100:
        res = Organization.get_by_name(
            user_info.get('org')).get('sub_orgs') or []
        return res
    else:
        return []
Example #2
0
def get_ogs(userid):
    user_info = User.get_by_id(userid).get('user_info') or {}
    role = user_info.get('role') or 1
    if role >= 100:
        res = Organization.get_iter()
        res = list(res)
        for e in res:
            e['_id'] = str(e['_id'])
        return res
    else:
        res = Organization.get_by_name(user_info.get('org'))
        if not res:
            return []
        res['_id'] = str(res['_id'])
        return [res]
Example #3
0
def add_org(org):
    has_org = Organization.get_by_name(org.get('org_name')) is not None
    if has_org:
        return False
    return Organization.add(org)