def create_role(): # 创建角色 # 1,访问者(可以修改个人信息) visitor = CMSRole(name='访问者', desc='只能修改个人相关数据') visitor.permissions = CMSPermission.VISITOR # 2,运营角色(修改个人信息,管理帖子,管理评论,管理前台用户) operator = CMSRole(name='运营', desc='管理帖子,管理评论,管理前台用户') operator.permissions = CMSPermission.VISITOR|CMSPermission.POSTER|CMSPermission.CMSUSER\ |CMSPermission.COMMENTER|CMSPermission.FRONTUSER # 3,管理员(拥有绝大部分权限) admin = CMSRole(name='管理员', desc='拥有本系统所有权限') admin.permissions = CMSPermission.VISITOR|CMSPermission.POSTER|CMSPermission.CMSUSER\ |CMSPermission.COMMENTER|CMSPermission.FRONTUSER|CMSPermission.BOARDER # 4,开发者 developer = CMSRole(name='开发者', desc='开发人员专用角色') developer.permissions = CMSPermission.ALL_PERMISSION # 添加到数据库 db.session.add_all([visitor, operator, admin, developer]) db.session.commit()
def create_role(): """创建角色""" # 访问者 visitor = CMSRole(name='访问者', desc='访问,修改个人信息') visitor.premissions = CMSPermission.VISITOR # 运营角色(修改个人个人信息,管理帖子,管理评论,管理前台用户) operitor = CMSRole(name='运营人员', desc='修改个人个人信息,管理帖子,管理评论,管理前台用户') operitor.premissions = CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.COMMENTER | CMSPermission.FRONTUSER # 管理员(拥有绝大部分权限) admin = CMSRole(name='管理员', desc='拥有管理员权限') admin.premissions = CMSPermission.VISITOR | CMSPermission.FRONTUSER | CMSPermission.COMMENTER | CMSPermission.POSTER | CMSPermission.BORDER | CMSPermission.CMSUSER | CMSPermission.ADMINER # 开发者 developer = CMSRole(name='开发者', desc='拥有开发相关权限') developer.premissions = CMSPermission.ALL_PERMISSION db.session.add_all([visitor, operitor, admin, developer]) db.session.commit()
def create_role(): #访问者(可以修改个人信息) visitor = CMSRole(name='访问者', desc='可以修改个人信息') visitor.permissions = CMSPermission.VISITOR #运营角色(修改个人信息,管理帖子,管理评论,管理前台用户) operator = CMSRole(name='运营', desc='管理帖子,评论,前台用户') operator.permissions = (CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.COMMENTER | CMSPermission.FRONTUSER) #管理员(拥有绝大部分权限) admin = CMSRole(name='管理员', desc='拥有本系统所有权限') admin.permissions = (CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.COMMENTER | CMSPermission.BOARDER | CMSPermission.FRONTUSER | CMSPermission.CMSUSER) #开发者 developer = CMSRole(name='开发者', desc='开发人员专用') developer.permissions = CMSPermission.ALL_PERMISSION db.session.add_all([visitor, operator, admin, developer]) db.session.commit()
def create_role(): # 访问者 visitor = CMSRole(name='访问者', desc='只能查看数据,不能修改数据') visitor.permissions = CMSPersmission.VISITOR # 运营人员 operator = CMSRole(name='运营', desc='管理帖子,管理评论,管理前台用户') operator.permissions = CMSPersmission.VISITOR | CMSPersmission.POSTER | CMSPersmission.CMSUSER | CMSPersmission.COMMENTER | CMSPersmission.FRONTUSER # 管理员 admin = CMSRole(name='管理员', desc='拥有本系统大部分权限') admin.permissions = CMSPersmission.VISITOR | CMSPersmission.POSTER | CMSPersmission.CMSUSER | CMSPersmission.COMMENTER | CMSPersmission.FRONTUSER | CMSPersmission.BOARDER # 开发人员 developer = CMSRole(name='开发者', desc='拥有所有的权限') developer.permissions = CMSPersmission.ALL_PERMISSION db.session.add_all([visitor, operator, admin, developer]) db.session.commit()
def create_role(): # 访问者 visitor = CMSRole(name="访问者", desc="只能查看数据,不能修改数据") visitor.permission = CMSPersmission.VISITOR # 权限 # 运营人员 operator = CMSRole(name="运营人员", desc="管理评论、帖子、管理前台用户") # 权限或运算,代表包含有运算中的所有权限 二进制的运算 001|010=011 operator.permission = CMSPersmission.VISITOR | CMSPersmission.POSTER | CMSPersmission.CMSUSER | \ CMSPersmission.COMMENTER | CMSPersmission.FRONTUSER # 管理员 admin = CMSRole(name="管理员", desc="拥有本系统大部分权限") admin.permission = CMSPersmission.VISITOR | CMSPersmission.POSTER | CMSPersmission.CMSUSER | \ CMSPersmission.COMMENTER | CMSPersmission.FRONTUSER | CMSPersmission.BOARDER # 开发人员 developer = CMSRole(name="开发人员", desc="拥有本系统所有权限") developer.permission = CMSPersmission.ALL_PERMISSION # 提交数据库 添加身份字段到数据库中的表, db.session.add_all([visitor, operator, admin, developer]) db.session.commit() return "创建角色成功"
def create_role(): # 1. 访问者(可以修改个人信息) visitor = CMSRole(name='访问者', desc='只能相关数据,不能修改。') visitor.permissions = CMSPermission.VISITOR # 2. 运营角色(修改个人信息,管理帖子,管理评论,管理前台用户) operator = CMSRole(name='运营者', desc='管理帖子,管理评论,管理前台用户。') operator.permissions = CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.COMMENTER | CMSPermission.FRONTUSER # 3. 管理员(拥有绝大部分权限) admin = CMSRole(name='管理员', desc='拥有本系统所有权限。') admin.permissions = CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.CMSUSER | CMSPermission.COMMENTER | CMSPermission.FRONTUSER | CMSPermission.BOARDER # 4. 开发者 developer = CMSRole(name='开发者', desc='开发人员专用角色。') developer.permissions = CMSPermission.ALL_PERMISSION db.session.add_all([visitor, operator, admin, developer]) db.session.commit()
def create_role(): # 访问者 visitor = CMSRole(name='访问者', desc='只能查看数据,不能修改数据') visitor.permissions = CMSPermission.VISITOR # 也可以省去,因为默认权限就是VISITOR # 运营者 operator = CMSRole(name='运营', desc='管理帖子,管理评论,管理前台和后台用户,管理轮播图') # 有多个权限时,使用或运算表示 operator.permissions = CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.CMSUSER | CMSPermission.COMMENTER | CMSPermission.FRONTUSER | CMSPermission.BANNER # 管理员 admin = CMSRole(name='管理员', desc='拥有本系统大部分权限') admin.permissions = CMSPermission.VISITOR | CMSPermission.POSTER | CMSPermission.CMSUSER | CMSPermission.COMMENTER | CMSPermission.FRONTUSER | CMSPermission.BOARDER | CMSPermission.BANNER # 开发人员 developer = CMSRole(name='开发者', desc='拥有所有权限') developer.permissions = CMSPermission.ALL_PERMISSION db.session.add_all([visitor, operator, admin, developer]) db.session.commit() print('角色添加成功')
def create_role(): # 1. 访问者(可修改个人角色) visitor = CMSRole(name='访问者', desc='只能查看相关数据, 不能修改') visitor.permission = CMSPersmission.VISITOR # 2. 运营角色(可修改个人角色, 管理帖子, 管理评论, 管理前台人员) operator = CMSRole(name='运营', desc='管理帖子,管理评论,管理板块') operator.permission = CMSPersmission.VISITOR | CMSPersmission.POSTER | CMSPersmission.COMMENTER | CMSPersmission.BOARDER # 3. 管理员() admin = CMSRole(name='管理员', desc='拥有本系统所有权限') admin.permission = CMSPersmission.VISITOR | CMSPersmission.POSTER | CMSPersmission.COMMENTER | CMSPersmission.BOARDER | CMSPersmission.FRONTUSER | CMSPersmission.CMSUSER # 4. 开发者 developer = CMSRole(name='开发者', desc='开发人员专用角色') developer.permission = CMSPersmission.ALL_PERMISSION db.session.add_all([visitor, operator, admin, developer]) db.session.commit()