user-wsc/AppInit.py

80 lines
2.8 KiB
Python
Raw Normal View History

2022-11-07 13:53:42 +08:00
from AppUser.Model import UserModel, RoleModel, DepartmentModel, VerifyCodeModel
from AppUser.Model.UserModel import User
from AppUser.Model.RoleModel import Role
from AppUser.Model.DepartmentModel import Department
from AppUser.Crud import UserCrud
from AppUser.Crud import RoleCrud
from AppUser.Crud import DepartmentCrud
from AppUser.Schemas import UserSchemas, RoleSchema
from Utils.DataBase.SqlAlchemyUtils import Session, engine
UserModel.Base.metadata.create_all(bind=engine)
RoleModel.Base.metadata.create_all(bind=engine)
DepartmentModel.Base.metadata.create_all(bind=engine)
VerifyCodeModel.Base.metadata.create_all(bind=engine)
DEFAULT_ROLE = "管理员"
DEFAULT_ROLE_ID = "ROLE01"
DEFAULT_DEPARTMENT = "数字化部"
DEFAULT_DEPARTMENT_ID = "D001"
DEFAULT_AVATAR = "https://file.fecribd.com/pic/avatar.jpg"
DEFAULT_PASSWD = "AP3+dq8nx3+1J9nt+3hRbI4kNXNP7Whm7P+rmP5ewmQLH5lmwAzcs/xwXZqOr+vtMwAzHAAxN64TYbsOSzcuoo1nf843vxc6e4FFHBin+jmnxP2A37XmLBdMBKBzhZDRgppvMn/E77hKqJnC8TdDeO20SuuPIJTCE14qotwqX90="
DEFAULT_USER = {
"email": "fecribd@fecr.com.cn",
"name": "root",
"role_id": DEFAULT_ROLE_ID,
"department_id": DEFAULT_DEPARTMENT_ID
}
def init_role():
db = Session()
if db.query(Role).count() == 0:
2022-11-08 09:46:44 +08:00
2022-11-07 13:53:42 +08:00
RoleCrud.create_role(db=db, name=DEFAULT_ROLE)
2022-11-08 09:46:44 +08:00
role01_menus = ["模型", "指标", "流程", "评级"]
for subject in role01_menus:
RoleCrud.create_role_menu(db=db, role_id="ROLE01", subject=subject)
2022-11-07 13:53:42 +08:00
RoleCrud.create_role(db=db, name="分析师")
2022-11-08 09:46:44 +08:00
role02_menus = ["模型", "指标", "流程", "评级"]
for subject in role02_menus:
RoleCrud.create_role_menu(db=db, role_id="ROLE02", subject=subject)
2022-11-07 13:53:42 +08:00
role02_rap = [
2022-11-08 09:46:44 +08:00
{"module": "指标函数", "ptype": "p", "sub": "分析师", "obj": "/api/index_function/.*", "act": "计算"},
{"module": "指标仓库", "ptype": "p", "sub": "分析师", "obj": "/api/index_store/view/(IID.*?)$", "act": "查看指标"},
{"module": "指标仓库", "ptype": "p", "sub": "分析师", "obj": "/api/index_store/describe/(IID.*?)$", "act": "查看指标描述"},
{"module": "指标仓库", "ptype": "p", "sub": "分析师", "obj": "/api/index_store/search$", "act": "查询"}
2022-11-07 13:53:42 +08:00
]
for rap in role02_rap:
RoleCrud.create_role_policy(db=db, role_id="ROLE02", schema=RoleSchema.CreateRolePolicyReqBody(**rap))
db.close()
def init_department():
db = Session()
if db.query(Department).count() == 0:
DepartmentCrud.create_department(db=db, name=DEFAULT_DEPARTMENT)
db.close()
def init_user():
db = Session()
if db.query(User).count() == 0:
UserCrud.create_user(db=db, schema=UserSchemas.CreateReqBody(**DEFAULT_USER))
db.close()
if __name__ == '__main__':
init_role()
init_department()
init_user()