def permission_manager_list_lib(self): """01权限管理页面函数""" roles = Role.all() permissions = Permission.all() menus = Menu.all() handlers = Handler.all() users = User.all() # 研发员工 dev_role = Role.by_name('研发员工') dev_users = dev_role.users if dev_role else [] dev_roleid = dev_role.id if dev_role else '' return roles, permissions, menus, handlers, users, dev_users, dev_roleid
def add_role_lib(self, name): """02添加角色""" try: role = Role.by_name(name) if role is not None: flash(self, '角色已存在', 'error') role = Role() role.name = name self.db.add(role) self.db.commit() flash(self, '角色添加成功', 'success') # return {'status': True, 'msg': '角色添加成功'} except Exception as e: print e flash(self, '角色添加失败', 'error')
def get(self): kw = { 'user_msg': self.get_redis_json_to_dict('user'), 'role_msg': self.get_redis_json_to_dict('role'), 'system_msg': self.get_redis_json_to_dict('system'), 'roles': Role.all(), } self.render('message/message_send_message.html', **kw)
def send_role_message(cls, self, content, send_type, roleid): role = Role.by_id(roleid) redis_msg = cls.dict_to_json(self, content, send_type, role.name) self.conn.rpush('message:%s' % send_type, redis_msg) role_users = role.users for user in role_users: if MessageWebSocket.users.get(user.name, None) is not None: MessageWebSocket.users[user.name].write_message(redis_msg) else: # self.conn.lpush("ws:not_line", messgae) pass
def del_role_lib(self, roleid): """03删除角色""" try: role = Role.by_id(roleid) if role is None: flash(self, '角色不存在', 'error') self.db.delete(role) # 删除 self.db.commit() flash(self, '角色删除成功', 'success') except Exception as e: print e flash(self, '角色删除失败', 'error')
def del_user_dev_role_lib(self, userid, roleid): """14为用户删除角色""" try: user = User.by_id(userid) role = Role.by_id(roleid) if user is None or role is None: flash(self, '用户或者角色不存在', 'error') user.roles.remove(role) # 添加到中间表 self.db.add(user) self.db.commit() flash(self, '用户删除角色成功', 'success') except Exception as e: print e flash(self, '用户删除角色失败', 'error')
def add_permission_role_lib(self, permissionid, roleid): """11给角色添加权限""" try: permission = Permission.by_id(permissionid) role = Role.by_id(roleid) if permission is None or role is None: flash(self, '权限或者角色不存在', 'error') role.permissions.append(permission) # 添加到中间表 self.db.add(role) self.db.commit() flash(self, '处理器权限删除失败', 'success') except Exception as e: print e flash(self, '角色添加权限失败', 'error')