def __check_auth_user(): userid = session['userid'] data = request.get_json() or {} userids = data.get('userids') or [] usernames = [] if not userids: userid_get = data.get('userid') if userid_get: userids = [userid_get] if not userids: usernames = data.get('usernames') or [] if not usernames: return True user_info = User.get_by_id(userid, ['user_info']).get('user_info') role = user_info.get('role') or 1 if role == 101: return True if userids: for userid_get in userids: user_info_get = User.get_by_id(userid_get, ['user_info']).get('user_info') if not __inner_check_auth_user(user_info, role, user_info_get): return False else: for username in usernames: user_info_get = User.get({ 'user_info.username': username }, ['user_info']).get('user_info') if not __inner_check_auth_user(user_info, role, user_info_get): return False return True
def upload(qu_id, usernames, qu_datas): for username, qu_data in zip(usernames, qu_datas): userid_set = User.get({'user_info.username': username}, ['_id']) if not userid_set: continue userid_set = str(userid_set.get('_id')) set_qu_data(userid_set, qu_id, qu_data) return True
def __get_qu(userid, qu_id): res = User.get( { "_id": ObjectId(userid), "qus": { '$elemMatch': { "qu_id": ObjectId(qu_id) } } }, ['qus']) return res
def get_qu_data(userid, qu_id): res = User.get( { "_id": ObjectId(userid), "qus": { '$elemMatch': { "qu_id": ObjectId(qu_id) } } }, { '_id': 0, 'qus.$.qu_data': 1 }) if not res: return None res = res.get('qus') if res: res = res[0].get('qu_data') return res
def get_qu(userid, qu_id): res = User.get( { "_id": ObjectId(userid), "qus": { '$elemMatch': { "qu_id": ObjectId(qu_id) } } }, { '_id': 0, 'qus.$': 1 }) if not res: return None res = res.get('qus') if res: res = res[0] res['qu_id'] = str(res['qu_id']) return res
def get_user_by_userid(userid, dic_r=None): return User.get({'_id': ObjectId(userid)}, dic_r)
def get_user_by_username(username): return User.get({'user_info.username': username})
def has_username(username): user = User.get({'user_info.username': username}) return user is not None