Group plugin: Combining template files but javascript interactions don't work

Plugin Development
  • GNU/Linux

    I am working on a plugin that adapts the current category/group paradigm to center content around groups (vs categories). Basically, the plugin ensures every group has exactly one category associated with it, and no one has privileges for that category except the members of the group. When a user wants to "post to the group' they are actually posting to the group's category.

    The beginnings of the plugin have been easy to code. I hook into filter:groups.create to automatically create a category with a group property and attach the resulting cid to the group. When the user wants to view the "group feed", I direct them to the group's category and hook into filter:category.get to attach the group to the category before it gets sent to the client.

    Where I am stuck, however, is the templates. As a proof of concept for the plugin, I combined groups/details.tpl file and the category.tpl from the persona theme. The information all displays properly, including the group admin panel for if necessary for the user. There is just one major problem -- the javascript interactions on the group panels don't work. A user can't leave the group, grant/rescind ownership, etc. I need help understanding why this is so?? I spend the majority of my time in Angular, and to be honest haven't yet got a clear grip on NodeBB templating.

    I am hoping this is an easy solve, but I keep running into dead ends. Would much appreciate any thoughts on this!

  • Global Moderator Plugin & Theme Dev

    @agd1 It sounds like the necessary scripts aren't being loaded. Can you post the original group/details.tpl and category.tpl and then the combined file?

  • GNU/Linux

    @PitaJ sorry it took me a second to get back to you. I threw the code in Github

    You'll see in the templates directory that there is a category.tpl. This is the combined version. These are the links to the originals from the Persona theme:

    The plugin is working w/ NodeBB 0.9 & the Persona theme. Thanks for any input!

  • Did you change the route for this page, or is it still /groups/groupname?

  • GNU/Linux

    @psychobunny need to update the Git repo, but in my sandbox where I was toying with this plugin I actually overwrote the groups/list.tpl so that when a group is selected it doesn't take the user to groups/:groupName but instead to to the url for the category associated with the group: category/:cid/groupName

  • GNU/Linux

    and to clarify the intent here a little bit: I'm very impressed with NodeBB, and I'd like to see a plugin that enables functionality not unlike Facebook groups.

  • So that's the problem then, NodeBB automatically loads via requirejs the JS file for a certain route.

    Let's say you went to /group/groupname

    It would auto load public/src/forum/group.js

    (I'm on mobile now the routes are probably wrong, but hope you get what I mean)

    So to solve this, you would have to detect page load of your new route via the action:ajaxify.end route and load the groups.js file as well

  • GNU/Linux

    @psychobunny that was exactly the trick. I have updated the repo and everything seems to be working pretty well right now. Very pleased with how it is turning out!

    The only seeming major block left is a problem with privileges. If I remove the read privileges from non-group members, NodeBB prevents them from seeing the "frankensteined" category/group view. I merged both views, so the user seems the same thing at both /groups/:groupname and /category/:cid/:slug, and both are restricted from viewing if the read privilege isn't given to a user.

    My solution was to give the access but strip the topics out from the JSON response before sending to the client. One major problem -- they are still visible in the Recent and Popualr feeds. This tells me my solution is not really robust enough.

    Any thoughts from anyone on how to get around this? I need to be able to embed a category topic list inside the group view and still let non-group members view the group page to join (without of course seeing the topics until they are a member).

    Here's a screeenshot of the frankensteined view:

    0_1449354246354_Screen Shot 2015-12-05 at 5.23.31 PM.png

  • GNU/Linux

    Thinking out loud here, perhaps a good lead on this would be to figure out what generates this error. The HTTP response to get this group comes back as 403 Forbidden, which means it must be coming from the category ACL.


  • GNU/Linux


    I think I got most -- if not all -- of this figured out. I learned about NodeBB in the process -- very impressed with it!

    For posterity, take a look at the nodebb-plugin-groupthink plugin. The way I ended up solving this is rethinking the privilege setup from what I first did. Nobody has any privileges to a group's category except group members. If a user visits a group page at /groups/:groupname the group metadata is still passed to the client so the user can join the group, but the category is not retrieved. Due to some strange bug in the Persona theme (or in templates.js-- not sure) I couldn't wrap <!-- IMPORT partials/topics_list.tpl --> in <!-- IF group.isMember -->, but I solved this by rearranging some of the template html.

    The plugin seems to be working well. Users can now "Post to a group" similar to how they would on other social networks.

  • I did a try and i liked it 🙂

    It would be awesome if you could choose what category works that way and what category works on the standard forum way 🙂

Suggested Topics

  • 0 Votes
    2 Posts

  • 0 Votes
    1 Posts

  • 0 Votes
    3 Posts

  • 0 Votes
    3 Posts

  • 1 Votes
    10 Posts

| | | |