Is there any way to get a user object by username or id via javascript?
It is difficult to answer without some more context. You can always do this: (try it in the dev tools for Meta)
Discourse.User.findByUsername("David_Taylor").then(function(user){
console.log("User Found", user);
});
But that will result in an additional request to the server, which may not be necessary.
What are you trying to achieve?
Thanks very much. I am trying to get a list of usersnames with certain custom field attributes. As you correctly pointed out, it will result in many additional calls from the API.
Is it possible to achieve what I intend more gracefully?
If this is just for administrators, you might be able to utilise the data-explorer plugin. If you wanted this to work for all users, you would probably need to create a plugin which adds a new HTTP endpoint.
Estoy trabajando en uno de los errores relacionados con el plugin de eventos, donde la implementación actual dependía de los nombres de usuario. Aunque es un caso excepcional, los nombres de usuario pueden cambiar, lo que crea la necesidad de poder obtener a un usuario por su id.
Creo que debería haber un método similar en el núcleo para buscar a un usuario por su id.
Me gustaría conocer tu opinión al respecto.
Tu plugin debe poder actualizar las referencias al nombre de usuario cuando este cambia o agregar las rutas y serializadores necesarios para obtener los datos.
Revisaré si es posible hacer esto en el escenario actual.
Sí. Necesitaré agregar un método a UsersController para buscar un usuario por su ID y agregar un método en el modelo User del lado de Ember para llamar a este nuevo método del controlador.