Restrict answers to trust levels

Hi,

I’m wondering if there’s way to restrict answers/replies to certain trust levels or user custom fields? Our users are migrated from WordPress with different membership level. We don’t want to give all user the capability to view answers unless they’ve reached to certain membership level.

2 Likes

To view or to reply? They’re quite different things.

2 Likes

@HAWK , ah sorry, to reply. they can see the topic and replies, but shouldn’t be able to reply unless they are certain level.

2 Likes

Yup, you can set that up at a category level. Add each trust level group and give it the appropriate permissions.

2 Likes

What if we actually do want to hide the answers not just the restrict permission to reply? The ‘see’ column is grayed out.

2 Likes

You can’t do that, I’m afraid.

1 Like

Would it be possible with a custom plug-in ? I suspect it shouldn’t be hard reading current user and hide the whole answer section via JavaScript?

2 Likes

Sorry, I meant it’s not possible out of the box. Pretty much anything is possible with a custom plugin!

5 Likes

As I’m trying to accomplish this via custom plugin. I think I’m almost there by editing overriding the postsToRender variable.

  TopicRoute.reopen({
    setupController(controller, model) {
      this._super(controller, model);
      topicController = controller;
      console.log(topicController);
      let userPrivileged = userCanViewAnswers(topicController.currentUser);

      const postStream = topicController.get("model.postStream");
      window.postStream = postStream;
      window.topicController = topicController;

      topicController.postsToRender = userPrivileged ? topicController.postsToRender : topicController.postsToRender.posts.filter(p=>p.post_number == 1);

    }
  });

function userCanViewAnswers(user){
    let user_groups = user.groups.map(g => g.name);
    return user_groups.includes('privileged');
}

It seems like it will show error not found briefly and reload correctly when hard reloading the page or come back after home page,

I’m using MacOS Docker dev image, kinda slow.

Sorry, I’m not familiar with the discourse code base quite yet.
Is there a better way to intercept the posts on topic load?

I see I was supposed to reopen the Controller.

  TopicController.reopen({
    @discourseComputed(
    "model.postStream.posts",
    "model.postStream.postsWithPlaceholders"
  )
    postsToRender(posts,postsWithPlaceholders ){
      let userPrivileged = userCanViewAnswers(this.currentUser);
      return userPrivileged 
      ? (this.capabilities.isAndroid ? posts : postsWithPlaceholders) 
      : (this.capabilities.isAndroid ? posts.slice(0, 1) : postsWithPlaceholders.slice(0, 1));
    }
  })

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.