Пример #1
0
 def all_role(self, app):
     try:
         roles = RoleModel.get()
         result = {}
         if roles:
             result = roles.serialize()
         return helper.handler_response(app, 201, 'Lista de Roles', result)
     except Exception as e:
         return helper.handler_response(app, 500, f'{str(e)}')
Пример #2
0
def change_role():
    """角色切换"""

    role_id = toint(request.args.get('role_id', '0'))
    uid     = session.get('uid')
    if role_id <= 0:
        return u'参数出错'

    role = Role.get(role_id)

    if not role and role_id != 1:
        return u'切换的角色不存在'

    role_id_list = user_role_id_list(uid)
    role_id_list.remove(role_id) #去除角色列表中的已切换的角色
    session['menu'] = menu(role_id)
    session['role_id'] = role_id
    session['role_name'] = u'超级管理员' if role_id == 1 else role.role_name
    session['role_temp_list'] = get_role_list(role_id_list)

    return u'ok'
Пример #3
0
def test_get_role_endpoint(client: CustomFlaskClient, auth_header: any):
    role_id = (RoleModel.select(RoleModel.id).where(
        RoleModel.deleted_at.is_null()).order_by(
            fn.Random()).limit(1).get().id)

    role = RoleModel.get(RoleModel.id == role_id)
    db_wrapper.database.close()

    response = client.get('/api/roles/%s' % role_id,
                          json={},
                          headers=auth_header())
    json_response = response.get_json()
    json_data = json_response.get('data')

    assert 200 == response.status_code
    assert role_id == json_data.get('id')
    assert role.name == json_data.get('name')
    assert role.name.lower() == json_data.get('name').lower().replace('-', ' ')
    assert role.created_at.strftime('%Y-%m-%d %H:%M:%S') == json_data.get(
        'created_at')
    assert role.updated_at.strftime('%Y-%m-%d %H:%M:%S') == json_data.get(
        'updated_at')
    assert role.deleted_at == json_data.get('deleted_at')