Show a menu item to "unanswered topics" only for users with a particular minimum trust level


(Anton) #1

I’d like to show an additional menu item linking to unanswered topics only for those who has gained 2nd level of trust - how would I do this?


Notify moderators of unanswered posts
(Michael Downey) #2

Do you mean topics with 0 replies, or something else?


(Anton) #3

Yes, correct - this is what I mean


(Mittineague) #4

Finding them is easy enough

But the “only for TL2 members” would be a plugin I guess


(Kane York) #5

Have some javascript that only adds it to the nav menu if the current user is at or above TL2. No plugin needed.


(Anton) #6

Could you drop me a hint pls about javascript :wink:


(Dean Taylor) #7

Couple these two pieces of code together:

###Code 1

var user = Discourse.User.current();
if (user && user.trust_level >= 2) {
    alert('Wooo - TL2 or above user');
}

Here is a screen grab of Google Chrome Dev Tools console with the output for me:

###Code 2
Here is the code that currently adds two Custom Nav Bar items for meta.discourse.org


(Casey Locker) #8

Using this suggestion I now have a new button “Unanswered” that directs users to the /latest?max_posts=1 endpoint (sometimes). Thanks for that. The only issue that I need to figure out now is why, when the home page is viewed - it’s currently set to Latest as the default - the url changes in the browser but the page isn’t refreshed. If I hit the button from another section - New, Unread, Top, etc - the expected /latest?max_posts=1 content is returned to the browser.

Is this due to the default /latest homepage endpoint and the /latest?max_posts=1 endpoint being the same except the querystring? Is there any way to overcome that so that going from /latest to /latest?max_posts=1 actually updates the page?


(Casey Locker) #9

Thinking it might have something to do with this:
http://guides.emberjs.com/v1.10.0/routing/query-params/#toc_opting-into-a-full-transition

I’m not all that familiar with ember so any guidance would be appreciated.

FYI, the button addition is happening by adding a custom </body> within the admin area as follows:

    Discourse.ExternalNavItem = Discourse.NavItem.extend({
        href : function() {
          return this.get('href');
        }.property('href')
    });
    
    I18n.translations.en.js.filters.unanswered = { title: "Unanswered", help: "Unanswered Posts" };
    
    Discourse.NavItem.reopenClass({
        buildList : function(latest, args) {
          var list = this._super(latest, args);
          if(!latest) {
            list.push(Discourse.ExternalNavItem.create({href: '/latest?max_posts=1', name: 'unanswered'}));
          }
          return list;
        }
    });