I am trying to display some externally generated user data below the user’s avatar. Currently, the data is stored in a custom user field of type ‘text’ and the field is populated via an API call as well as during SSO.
Now I am trying to determine the best way to actually display the data. Actually, I’m trying to find any way to display the data. A plugin seems like the best option, but there is no plugin-outlet that can be used.
Can someone with more knowledge point me in the correct direction?
Thank you, that has certainly helped with displaying data in the correct location. Unfortunately it has also led me to another stumbling block.
From the helper.attrs, I can get the username and the user_id. Using this info, I then tried:
Discourse.User.findByUsername(helper.attrs.username).then((user)=>{
let f1_val = user.user_fields[1];
return helper.h('div', `${f1_val}`);
});
Aside from throwing an error, this method of data retrieval results in an API request for every post. Is there a way to access the information from the Ember side without requiring an API call?
Would you mind sharing the basic idea of what ended up working for you? I’m curious what you ended up going with and I’m sure others that happen upon this topic will appreciate the info as well
Pour stocker les données personnalisées sur Discourse, je suis allé dans Admin > Personnaliser > Champs utilisateur et j’ai créé un champ personnalisé. Les données dont j’ai besoin sont un percentile représentant l’avancement, et j’ai choisi « texte » comme type de champ. Le nom du champ n’est affiché que sur la carte de l’utilisateur et sur son profil, et malheureusement, il n’est pas utilisé pour référencer les données du champ de manière programmatique.
Le champ stockant l’avancement était le troisième champ personnalisé que j’ai créé, et ainsi « 3 » devient un nombre très important.
En utilisant l’API, j’ai écrit un script curl (avec l’aide de https://meta.discourse.org/t/api-cannot-update-user/63876/4) pour remplir le champ avec des données de test. Comme le champ que je voulais remplir était le troisième que j’avais créé, ma ligne de données dans le script curl est :
--data '{ "user_fields": { "3":"87" } }'
Pour afficher les données, il a fallu aller dans Admin > Paramètres > Utilisateurs, faire défiler jusqu’à l’option « champs personnalisés publics des utilisateurs » et ajouter le champ à la liste blanche. Comme le champ était le troisième créé, j’ai dû ajouter « user_field_3 » à la liste blanche et non le nom réel que j’avais donné au champ.
À ce stade, j’ai écrit un plugin basique avec le code suivant :