Beeminder Forum

Adding link to Beeminder profile on user card?

Hi everyone!

I’d like to suggest a tweak to the forum, which is to add an icon/link on each person’s user card and forum profile, linking to that person’s account on Beeminder. Sometimes I’m reading posts here and I’m a little curious to see what that person is (publicly) beeminding. I know one could always use the website field, and knowing a username it’s trivial to just type the URL… but it would make it a tiny bit easier. :slight_smile:

We did this on our own installation of Discourse, following more or less these instructions, but the URL is not submitted/editable by members (since the username is the same as in the main site, like here). It looks like this:

Screenshot 2021-04-24 at 22.02.06

The red P is a link to the person’s profile on the main site. The little Beeminder bee would work well here, I think!

6 Likes

Very cool, we’ve been wanting to do that for a long time! Obrigado!

I started to follow the instructions you linked, but our discourse doesn’t seem to have the Customize > HTML/CSS tab. Is that something you had to turn on, or have someone grant you access to, etc? Update: seems that it’s moved around since those instructions were written. I think I’ve found it, hiding under themes!

PS: just for pointing us in the right direction, I think you’ve earned some stickers. Email support@beeminder.com with your snailmail address and they’ll put you on the list!


ok, partly done! It’s not as pretty as yours, and it doesn’t cope with when the forum user name is different than the Beeminder user name, but that shouldn’t affect too many people.

Because we use DiscourseConnect to do single sign on with Beeminder, there should be a way for us to access the SSO username in javascript rather than relying on a custom field. Digging into the docs now.

Found these alternate instructions that just use the forum username: Link username to external website - tips & tricks - Discourse Meta


OK, more done! It now uses the custom user field, if present, to override the forum name. @admins can change this value on the Users > User > Preferences > Profile page

5 Likes

For posterity and future searchers, here’s the mashed-up code:

<script type="text/discourse-plugin" version="0.8.7">
api.registerConnectorClass('user-profile-primary', 'site-link', {
  setupComponent(args, component) {
    component.set('siteLink', args.model.get('siteLink'));
  }
});

api.registerConnectorClass('user-card-metadata', 'site-link', {
  setupComponent(args, component) {
    component.set('siteLink', args.user.get('siteLink'));
  }
});

api.modifyClass('model:user', {
  siteLink: function() {
      
      /* first we check for the custom field */
      let customusername = null;
      const siteUserFields = Discourse.Site.currentProp('user_fields');
      if (!Ember.isEmpty(siteUserFields)) {
        const externalUserIdField = siteUserFields.filterBy('name', 'Beeminder Profile Override')[0]
        if (externalUserIdField) {
            const userFieldId = externalUserIdField.get('id');
            const userFields = this.get('user_fields');
            if (userFields && userFields[userFieldId]) {
                customusername = userFields[userFieldId];
            }
        }
      }
      
      /* then we fall back to using the forum username */
      const username = customusername || this.get('username');
      if (username) {
          const url = `https://beeminder.com/${username}`;
          const link = `<a href=${url} target='_blank'>${url}</a>`;

          return Ember.Object.create({ link, name: "My Beeminder Goals" });
      } else {
          return null;
      }
  }.property('username')
});

The use of Discourse.Site gives a deprecation warning, but should be ok until v2.6

4 Likes

Three cheers for you, @philip! :tada: Thank you for putting this together so quickly!

3 Likes