Creating custom privilege

Plugin Development
  • I want to create a new privilege for categories.
    I'm not quite sure how to go forward with this idea. What I've done so far is:

    var privileges = module.parent.require('./privileges');
    privileges.privilegeLabels.push({ name: '[[admin/manage/privileges:custom]]' });

    Now what do I do? The above code creates a new column in the privileges table, but no clickable checkboxes.
    Where do I write the logic for the custom privilege?
    I want the plugin to filter topics in categories based on the privilege of users.
    I also find the source code very confusing, no JSDoc or any other comments.

  • You want to add your privilege by adding a hook handler for each of

    • filter:privileges.list
    • filter:privileges.groups.list
    • filter:privileges.list_human
    • filter:privileges.groups.list_human

    In the .list ones, you should have something like this:

    exports.privilegesList = function (list, callback) {
      callback(null, list);

    and in the .list_human ones, you want to add a human-readable name or provide a translation token

    exports.privilegesListHuman = function (list, callback) {
      callback(null, list);

    All this does is add these privileges to the ACP interface for configuration. You can use the methods provided by the privileges core module to actually apply that permission, through methods like:

    • privileges.posts.can
    • privileges.topics.can
    • privileges.categories.filterUids
    • privileges.posts.filter

    You'd have to listen to other filter hooks in order to filter topics from the category listing and prevent users from viewing those topics via direct link.

    Here's an example of using a custom privileges from my plugin

  • @pitaj Thank you for the detailed answer, appreciate it!

Suggested Topics

  • 1 Votes
    2 Posts

    I was able to achieve the desired functionality by adding a custom "Share" button to the template for the private topics. This button triggers the move to predesignated categories based on the type of post.

  • 0 Votes
    14 Posts

    @baris Thanks for the help. I appreciate it.

  • 0 Votes
    2 Posts

    You want to use nodebb-plugin-customize

  • 0 Votes
    4 Posts

    @waldhay yes, you're supposed to rebuild and restart after installing plugins or changing themes.

  • Custom profile fields

    Plugin Development
    1 Votes
    7 Posts

    @psychobunny is there any option to include plugin client js only for /account/edit endpoint?

    Also, Do you have an ideas, how to augment template for the plugin use - templates/account/edit.tpl? I need add dynamic set of fields to the template, Vanilla's account-edit template is 3 column layout (md:2-5-5), I would like to have (md: 2:4:3:3). Main problem here, that I can't find really abstract approach, solution will be very dependent on Theme... One solution, just replace template on app startup, another option, create set of regexps and try to change template or dom manipulation to get another set of columns. Anyway I'm looking for less dependent solution, so It will not brake with every release of the theme and easily work with another themes

    Taking everything into consideration, I will swap edit.tpl and include client js with a template just as script tag. But maybe you have better ideas 😉