def update_role_and_api_per(old_per_value, new_per_value=0): """ 更新所有使用了old_per的role和api :param old_per: :param new_per: :return: """ # 更新使用了该权限的role # 当前所有的用户角色 updated_rolename = [] roles = mdbs["user"].db.role.find() for role in roles: if role["permissions"] & old_per_value and not ( role["permissions"] & get_permission("ROOT")): role_new_per = (role["permissions"] - old_per_value) | new_per_value mdbs["user"].db.role.update_many( {"_id": role["_id"]}, {"$set": { "permissions": role_new_per }}) updated_rolename.append(role["name"]) # 更新使用了该权限的url or page # 当前所有自定义权限url urls = list(mdbs["sys"].db.sys_urls.find( {"custom_permission": { "$ne": {}, "$exists": True }})) for url in urls: for method, v in url["custom_permission"].items(): if v & old_per_value: # 修改 url["custom_permission"][method] = ( v - old_per_value) | new_per_value # 更新 mdbs["sys"].db.sys_urls.update_one( {"_id": url["_id"]}, {"$set": { "custom_permission": url["custom_permission"] }}) cache.delete_autokey(fun="get_sys_url", db_type="redis", url=url['url'].rstrip("/")) return {"updated_rolename": updated_rolename}
def is_staff(self): role = mdb_user.db.role.find_one({"_id": self.role_id}) return role and int(role['permissions']) & int(get_permission("STAFF"))
def is_staff(self): role = mdbs["user"].db.role.find_one({"_id": self.role_id}) print(self.user_info) print(self.role_id, role) return role and int(role['permissions']) & int(get_permission("STAFF"))