j3ang
(Alex Wang)
2022 年 4 月 3 日午後 10: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 日午前 3:50
2
To view or to reply? They’re quite different things.
「いいね!」 2
j3ang
(Alex Wang)
2022 年 4 月 4 日午前 3: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 日午前 3: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 日午前 4: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 日午前 5:07
6
You can’t do that, I’m afraid.
「いいね!」 1
j3ang
(Alex Wang)
2022 年 4 月 4 日午前 5: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 日午前 5: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 日午前 12: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 日午後 6: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 日午後 6:29
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.