j3ang
(Alex Wang)
3 Aprile 2022, 10:26pm
1
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 Mi Piace
HAWK
(Hawk)
4 Aprile 2022, 3:50am
2
To view or to reply? They’re quite different things.
2 Mi Piace
j3ang
(Alex Wang)
4 Aprile 2022, 3:56am
3
@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 Mi Piace
HAWK
(Hawk)
4 Aprile 2022, 3:59am
4
Yup, you can set that up at a category level. Add each trust level group and give it the appropriate permissions.
2 Mi Piace
j3ang
(Alex Wang)
4 Aprile 2022, 4:56am
5
What if we actually do want to hide the answers not just the restrict permission to reply? The ‘see’ column is grayed out.
2 Mi Piace
HAWK
(Hawk)
4 Aprile 2022, 5:07am
6
You can’t do that, I’m afraid.
1 Mi Piace
j3ang
(Alex Wang)
4 Aprile 2022, 5:28am
7
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 Mi Piace
HAWK
(Hawk)
4 Aprile 2022, 5:32am
8
Sorry, I meant it’s not possible out of the box. Pretty much anything is possible with a custom plugin!
5 Mi Piace
j3ang
(Alex Wang)
5 Aprile 2022, 12:13am
9
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?
j3ang
(Alex Wang)
5 Aprile 2022, 6:29pm
10
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));
}
})
system
(system)
Chiuso
5 Maggio 2022, 6:29pm
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.