האם יש דרך להגביל theme component רק למנהלים?

סיכום מבוסס בינה מלאכותית

pangbo developed a theme component for moderators that adds a modal to remind them to consider suspending a user after handling a flag. The component is located in javascripts/discourse/admin/components/modal/remove-post.gjs and imports AdminUser from the admin namespace. While it functions correctly for moderators, regular users encounter an error because they cannot load the admin/models/admin-user module. pangbo is seeking a supported way to restrict the component (or its admin-specific import) to only moderators and admins, preventing the error for regular users.

david suggests using optionalRequire as a current best practice, referencing an example implementation in discourse/app/components/modal/tag-upload.gjs. However, david notes that the JavaScript build systems are undergoing changes, and this approach may require updates in the future with accompanying deprecation messages and instructions.

פיתחתי רכיב ערכת נושא במיוחד עבור המנהלים שלנו. רכיב זה מוסיף חלון קופץ שמזכיר למנהלים לשקול השעיית משתמש לאחר טיפול בסימון. מיקמתי את הרכיב הזה ב-javascripts/discourse/admin/components/modal/remove-post.gjs, ובראש הקובץ, הוא מייבא את AdminUser עם import AdminUser from "admin/models/admin-user";.

עבור המנהלים, הכל עובד בצורה מושלמת. עם זאת, משתמשים רגילים חווים בעיות. Discourse עדיין מנסה לטעון את הרכיב הזה עבור כל המשתמשים, ומכיוון שמשתמשים רגילים אינם טוענים מודולים מסוג admin/**, זה גורם לשגיאה הבאה:

Error: Could not find module `admin/models/admin-user`

באופן אידיאלי, הייתי רוצה שהרכיב המשנה הזה (או אפילו רק הייבוא הזה) ייטען רק עבור מנהלים ומנהלי מערכת. האם יש דרך נתמכת רשמית להבטיח שרכיב Glimmer בתוך רכיב ערכת נושא ייטען רק עבור צוות (מנהלים/מנהלי מערכת) ב-Discourse, כך שמשתמשים רגילים לעולם לא יתקלו בשגיאות מודולים חסרים עבור ייבואים ספציפיים למנהלים?

Right now, the best strategy is to use optionalRequire like this:

We’re doing a lot of work on our JS build systems right now, so there’s a change this will need change in future. If it does, there will be a deprecation message with instructions to upgrade.