def add_role_lib(self, name):
    """02添加角色函数"""
    role= Role.by_name(name)
    if role is not None:
        flash(self, "角色已经存在,添加失败", "error")
        return
    role = Role()
    role.name = name
    self.db.add(role)
    self.db.commit()
    flash(self, "角色添加成功", "success")
Beispiel #2
0
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 []

    return roles, permissions, menus, handlers, users, dev_users, dev_role.id
Beispiel #3
0
def save_role_name(self, role_name):
    ''' 存入新增角色名 '''
    if role_name == '':
        flash(self, "角色不能为空", "error")
        return
    role = Role.by_name(role_name)
    if role is not None:
        flash(self, "角色已经存在", "error")
        return

    role = Role()
    role.name = role_name
    self.db.add(role)
    self.db.commit()
    flash(self, "角色添加成功", "success")
def add_role_lib(self, name):
    '''02添加一个角色'''
    if not name:
        flash(self, '请输入角色名称!', 'error')
        return
    print type(name), 'name:%s' % name
    role = Role.by_name(name)
    if role is not None:
        flash(self, '角色已经存在!', 'error')
        return
    role = Role()
    role.name = name
    self.db.add(role)
    self.db.commit()
    flash(self, '角色添加成功!', 'success')
Beispiel #5
0
def permission_manager_list_lib(self):
    ''' 返回给权限管理页面 '''
    roles = Role.all()
    permissions = Permission.all()
    menus = Menu.all()
    handlers = Handler.all()
    users = User.all()
    return roles, permissions, menus, handlers, users
Beispiel #6
0
 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)
Beispiel #7
0
def permission_manage_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 []
    # print("*****")
    # print(type(dev_role))
    # print(dev_role)
    if dev_role is None:
        return roles, permissions, menus, handlers, users, dev_users, None
    return roles, permissions, menus, handlers, users, dev_users, dev_role.id
def del_user_role_lib(self, userid,roleid):
    """12删除用户的角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    user.roles.remove(role)
    self.db.add(user)
    self.db.commit()
    flash(self, '用户角色删除成功', 'success')
Beispiel #9
0
def del_role_lib(self, roleid):
    """03删除角色"""
    role = Role.by_id(roleid)
    if role is None:  #如果role是空的话,我们就什么也不操作
        flash(self, "角色不存在")
        return
    self.db.delete(role)
    self.db.commit()
    flash(self, "角色删除成功", "success")
def del_role_lib(self, roleid):
    """03删除角色"""
    role= Role.by_id(roleid)
    if role is None:
        flash(self, "角色删除失败", "error")
        return
    self.db.delete(role)
    self.db.commit()
    flash(self, "角色删除成功", "success")
Beispiel #11
0
def add_role_permission_lib(self, permissionid, roleid):
    permission = Permission.by_id(permissionid)
    role = Role.by_id(roleid)

    if permission is None or role is None:
        return
    permission.roles.append(role)  #多对多关系添加
    self.db.add(permission)
    self.db.commit()
def del_user_dev_role_lib(self, userid, roleid):
    """14为用户删除角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.remove(role)
    self.db.add(user)
    self.db.commit()
Beispiel #13
0
def del_role_name(self, role_id):
    ''' 删除角色名 '''
    role = Role.by_id(role_id)
    if role:
        self.db.delete(role)
        self.db.commit()
        flash(self, "删除成功", "success")
        return {'status': True}
    return {'status': False, 'msg': '不存在的ID'}
def add_user_dev_role_lib(self, userid, roleid):
    """13为用户添加角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)
    self.db.add(user)
    self.db.commit()
def add_permission_role_lib(self, permissionid , roleid):
    """11为角色添加权限"""
    permission = Permission.by_id(permissionid)
    role = Role.by_id(roleid)
    if permission is None or role is None:
        return
    role.permissions.append(permission)
    self.db.add(role)
    self.db.commit()
def permission_manager_list_lib(self):
    # 获取所有的角色/权限/菜单/处理器/用户
    roles = Role.all()
    permissions = Permission.all()
    menus = Menu.all()
    handlers = Handler.all()
    users = User.all()

    return roles, permissions, menus, handlers, users
Beispiel #17
0
def add_user_role_lib(self, userid, roleid):
    """10为用户添加角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)  #注意这里画龙点睛
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户添加角色添加成功", "success")
Beispiel #18
0
def add_user_dev_role_lib(self, userid, roleid):
    """13添加用户到研发部门"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户添加研发部门的角色添加成功", "success")
Beispiel #19
0
def add_role_permission_lib(self, roleid, permissionid):
    """11为角色添加权限"""
    role = Role.by_id(roleid)
    permission = Permission.by_id(permissionid)
    if role is None or permission is None:
        return
    role.permissions.append(permission)
    self.db.add(role)
    self.db.commit()
    flash(self, "为角色添加权限添加成功", "success")
Beispiel #20
0
 def get(self):
     self.conn.delete('massage:%s' %
                      self.current_user.name)  # 到这个页面删除拥护邮件记录
     kw = {
         'roles': Role.all(),
         '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'),
     }
     self.render('message/message_send_message.html', **kw)
Beispiel #21
0
def add_user_role_lib(self, userid, roleid):
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        return
    user.roles.append(role)  #多对多关系添加
    #role.users.append(user)

    self.db.add(user)
    self.db.commit()
def del_role_lib(self, roleid):
    '''03删除角色'''
    role = Role.by_id(roleid)  # 获取用户信息
    # 判断角色是否存在
    if role is None:
        flash(self, '角色删除失败!', 'error')
        return
    self.db.delete(role)
    self.db.commit()
    flash(self, '角色删除成功!', 'success')
Beispiel #23
0
def del_user_for_one_role_lib(self, userid, roleid):
    """15为用户删除某个角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    # print("********%s"%role)
    if user is None or role is None:
        return
    user.roles.remove(role)
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户删除某个角色删除成功", "success")
def add_role_permission_lib(self, permissionid, roleid):
    """11为角色添加权限"""
    permission = Permission.by_id(permissionid)
    role = Role.by_id(roleid)
    if permission is None or role is None:
        flash(self, "为角色添加权限失败", "error")
        return
    permission.roles.append(role) #多对多关系添加
    self.db.add(permission)
    self.db.commit()
    flash(self, "为角色添加权限成功", "success")
Beispiel #25
0
 def send_role_message(cls, self, content, send_type, role_id):
     role = Role.by_id(role_id)
     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.username, None) is not None:
             MessageWebSocket.users[user.username].write_message(redis_msg)
         else:
             # self.conn.lpush("ws:role_not_online": message)
             pass
Beispiel #26
0
 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  #[zhangsan, lishi , wangwu]  [zhangsan, lishi]
     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:role_off_line",message)
             pass
def add_user_role_lib(self, userid, roleid):
    """10为用户添加角色"""
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        flash(self, "为用户添加角色失败", "error")
        return
    user.roles.append(role) #这行的意思是:往多对多关系表中插入数据
    #role.users.append(user)
    self.db.add(user)
    self.db.commit()
    flash(self, "为用户添加角色成功", "success")
Beispiel #28
0
def user_add_role(self, user_id, role_id):
    ''' 给用户添加角色 '''
    user = User.by_id(user_id)
    if user is None:
        return {'status': False, 'msg': '不存在该用户ID'}
    role = Role.by_id(role_id)
    if role is None:
        return {'status': False, 'msg': '不存在该角色ID'}
    user_role = UserToRole()
    user_role.r_id = role_id
    user_role.u_id = user_id
    self.db.add(user_role)
    self.db.commit()
    return {'status': True}
def add_role_permission_lib(self, roleid, permissionid):
    '''11 给角色添加权限'''
    if not permissionid or not roleid:
        flash(self, '请输入角色id!和权限id!', 'error')
        return
    permission = Permission.by_id(permissionid)
    role = Role.by_id(roleid)

    if permission is None or role is None:
        flash(self, '角色id或权限id不存在!', 'error')
        return
    permission.roles.append(role)  # 多对多关系添加,数组添加
    print 'permission%s' % permission
    self.db.add(permission)
    self.db.commit()
    flash(self, '给角色添加权限成功!', 'success')
def add_user_role_lib(self, userid, roleid):
    '''10 给用户添加角色'''
    if not userid or not roleid:
        flash(self, '请输入用户id和角色id!', 'error')
        return
    user = User.by_id(userid)
    role = Role.by_id(roleid)
    if user is None or role is None:
        flash(self, '用户id或角色id不存在!', 'error')
        return
    user.roles.append(role)  # 多对多关系添加
    # role.users.append(user)

    self.db.add(user)
    self.db.commit()
    flash(self, '给用户添加角色成功!', 'success')