コード例 #1
0
def set_org(org_id, org):
    del org['_id']
    old_org = Organization.get_by_id(org_id)
    if old_org.get('org_name') != org.get('org_name'):
        User.update({'user_info.org': old_org.get('org_name')},
                    {'$set': {
                        'user_info.org': org.get('org_name')
                    }})
    return Organization.update_by_id(org_id, org)
コード例 #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]
コード例 #3
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 []
コード例 #4
0
def __check_auth_org():
    userid = session['userid']
    user_info = User.get_by_id(userid, ['user_info']).get('user_info')
    role = user_info.get('role') or 1
    if role >= 100:
        return True
    data = request.get_json() or {}
    org_name = Organization.get_by_id(data.get('org_id'),
                                      ['org_name']).get('org_name')
    if 4 <= role < 100:
        return org_name == user_info.get('org')
    return False
コード例 #5
0
def del_org(org_id):
    Organization.delete_by_id(org_id)
    return True
コード例 #6
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)
コード例 #7
0
def get_ogs_name():
    res = Organization.get_iter(None, {'_id': 0, 'org_name': 1, 'sub_orgs': 1})
    res = list(res)
    return res