لقد أضفت بعض الأزرار عبر سكريبت في جزء <head>...</head> في هذه الصفحة:
/admin/customize/themes/2/common/head_tag/edit
على هذا النحو
<script type="text/discourse-plugin" version="0.4">
api.onToolbarCreate(toolbar => {
toolbar.addButton({
id: "times-circle",
});
});
</script>
كيف يمكنني جعل هذا الزر مرئيًا فقط لمستخدمي الطاقم (المشرفين، المدراء) ولمستخدمي المجموعة المسماة “vip-group”؟
zcuric
(Zdravko)
28 أبريل 2020، 7:43ص
2
مرحباً! الأمر بسيط كما يلي
<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();
// التحقق مما إذا كان المستخدم ضمن مجموعة vip-group
const isInVipGroup = user.groups.some(({name}) => name === "vip-group");
if (user.staff || isInVipGroup) {
api.onToolbarCreate(toolbar => {
toolbar.addButton({
id: "times-circle",
});
});
}
</script>
عظيم! إنه يعمل!
كما أنني وجدت هذه المواضيع، التي قد تكون مفيدة لشخص ما.
Discourse adds a staff class to the body tag when a staff user is viewing the site. If you are ok with the button being visible to admins and moderators, you could hide the button with CSS and then make it visible when the staff class is present.
If only having the button visible to admins is a requirement, you will need to use some javascript to determine that the user is an admin. The easiest approach to that would be to add an admin class to the body and then make the button visible when the…
<div id="after-header">Stuff</div>
<script type="text/discourse-plugin" version="0.8">
api.onPageChange(() => {
let currentUser = api.getCurrentUser();
var groups = currentUser.groups;
const isInGroup1 = groups.some(g => g.name === 'group1');
const isInGroup2 = groups.some(g => g.name === 'group2');
const isInGroup3 = groups.some(g => g.name === 'group3');
if (isInGroup1) {
$("#after-header").addClass("group1");
}
…
zcuric
(Zdravko)
28 أبريل 2020، 7:51ص
4
@Ed_Bobkov لقد قمت بتعديل المقطع ليعمل مع نوع المجموعة المحدد لديك. لا أعرف ما إذا كنت قد رأيت ذلك، مجرد تذكير.