j3ang
(Alex Wang)
2022 年4 月 3 日 22:26
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 个赞
HAWK
(Hawk)
2022 年4 月 4 日 03:50
2
To view or to reply? They’re quite different things.
2 个赞
j3ang
(Alex Wang)
2022 年4 月 4 日 03:56
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 个赞
HAWK
(Hawk)
2022 年4 月 4 日 03:59
4
Yup, you can set that up at a category level. Add each trust level group and give it the appropriate permissions.
2 个赞
j3ang
(Alex Wang)
2022 年4 月 4 日 04:56
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 个赞
HAWK
(Hawk)
2022 年4 月 4 日 05:07
6
You can’t do that, I’m afraid.
1 个赞
j3ang
(Alex Wang)
2022 年4 月 4 日 05:28
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 个赞
HAWK
(Hawk)
2022 年4 月 4 日 05:32
8
Sorry, I meant it’s not possible out of the box. Pretty much anything is possible with a custom plugin!
5 个赞
j3ang
(Alex Wang)
2022 年4 月 5 日 00:13
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)
2022 年4 月 5 日 18:29
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)
关闭
2022 年5 月 5 日 18:29
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.