{"version":3,"file":"main.kc8bS2.js","sources":["theme-51/virtual:theme","theme-51/discourse/api-initializers/theme-initializer.gjs","theme-51/virtual:entrypoint:main"],"sourcesContent":["import { getObjectForTheme } from \"discourse/lib/theme-settings-store\";\n\nexport const settings = getObjectForTheme(51);\n\nexport function themePrefix(key) {\n  return `theme_translations.51.${key}`;\n}\n","import { withPluginApi } from \"discourse/lib/plugin-api\";\nimport Component from \"@glimmer/component\";\nimport DModal from \"discourse/components/d-modal\";\nimport DButton from \"discourse/components/d-button\";\nimport { htmlSafe } from \"@ember/template\";\nimport { service } from \"@ember/service\";\n\nclass TagErrorModal extends Component {\n  get errorMessage() {\n    return htmlSafe(\n      `The tag <b>#${this.args.model.slug}</b> is restricted. Your Admin ID (${this.args.model.userId}) does not have permission to use it.`\n    );\n  }\n\n  <template>\n    <DModal @title=\"Access Denied\" @closeModal={{@closeModal}} class=\"tag-restriction-modal\">\n      <:body>\n        <p>{{this.errorMessage}}</p>\n      </:body>\n      <:footer>\n        <DButton @label=\"close\" @action={{@closeModal}} @icon=\"times\" class=\"btn-primary\" />\n      </:footer>\n    </DModal>\n  </template>\n}\n\nexport default {\n  name: \"scoped-admin-tag-validator\",\n  initialize() {\n    withPluginApi((api) => {\n      // You can now use EITHER the slug \"roundup\" OR the ID \"314\" as the key\n      const TAG_PERMISSIONS = {\n        \"roundup\": [11],\n        \"262\": [11]\n      };\n\n      const SUPER_ADMIN_ID = 1;\n\n      api.modifyClass(\"service:composer\", (Superclass) =>\n        class extends Superclass {\n          @service modal;\n\n          save(...args) {\n            console.log(\"🛠 [TagValidator] Save attempt initiated\");\n\n            const user = api.getCurrentUser();\n            \n            // 1. Bypass logic\n            if (!user?.admin || user.id === SUPER_ADMIN_ID) {\n              console.log(\"🛠 [TagValidator] Bypass: User is Super Admin or non-admin.\");\n              return super.save(...args);\n            }\n\n            // 2. Deep Inspect Tags\n            // We stringify/parse to break Ember's proxy tracking and see the real data\n            const rawTags = this.model.tags || [];\n            console.log(\"🛠 [TagValidator] Raw Model Tags:\", JSON.parse(JSON.stringify(rawTags)));\n\n            // 3. Resolve tags to a searchable format (Names or IDs)\n            const tagIdentifiers = rawTags.map(t => {\n              if (typeof t === 'string' || typeof t === 'number') {\n                return String(t);\n              }\n              // If it's an object, try to find a useful identifier\n              return String(t.id || t.slug || t.name || \"\");\n            }).filter(Boolean);\n\n            console.log(\"🛠 [TagValidator] Processed Identifiers:\", tagIdentifiers);\n\n            // 4. Validate against Permissions\n            const forbiddenId = tagIdentifiers.find(id => {\n              const allowedIds = TAG_PERMISSIONS[id];\n              if (allowedIds) {\n                const isAuthorized = allowedIds.includes(user.id);\n                console.log(`🛠 [TagValidator] Checking: #${id} | Allowed: [${allowedIds}] | Current User: ${user.id} | Result: ${isAuthorized ? \"PASS\" : \"FAIL\"}`);\n                return !isAuthorized;\n              }\n              return false;\n            });\n\n            if (forbiddenId) {\n              console.warn(`❌ [TagValidator] BLOCKING SAVE: User ${user.id} is not authorized for tag identifier: ${forbiddenId}`);\n\n              // 5. Reset Composer State\n              // This is the most important part for allowing multiple attempts\n              this.set(\"loading\", false);\n              if (this.setSavingStatus) {\n                this.setSavingStatus(false);\n              }\n\n              // 6. Show the Modal\n              this.modal.show(TagErrorModal, {\n                model: {\n                  slug: forbiddenId, // This might be the number 314 or string 'roundup'\n                  userId: user.id\n                }\n              });\n              \n              // Prevent the composer from actually sending the request\n              return Promise.reject(\"Tag validation failed.\"); \n            }\n\n            console.log(\"✅ [TagValidator] No permission issues found. Proceeding...\");\n            return super.save(...args);\n          }\n        }\n      );\n    });\n  },\n};","import * as Mod1 from \"./discourse/api-initializers/theme-initializer\";\nconst compatModules = {\n  \"discourse/api-initializers/theme-initializer\": Mod1,\n};\nexport { compatModules };\nexport default compatModules;\n"],"names":["getObjectForTheme","TagErrorModal","Component","errorMessage","htmlSafe","this","args","model","slug","userId","setComponentTemplate","createTemplateFactory","id","block","moduleName","scope","DModal","DButton","isStrictMode","themeInitializer","name","initialize","withPluginApi","api","TAG_PERMISSIONS","roundup","modifyClass","Superclass","dt7948","g","prototype","service","modal","i","save","console","log","user","getCurrentUser","admin","super","rawTags","tags","JSON","parse","stringify","tagIdentifiers","map","t","String","filter","Boolean","forbiddenId","find","allowedIds","isAuthorized","includes","warn","set","setSavingStatus","show","Promise","reject","compatModules"],"mappings":";AAEwBA,EAAkB;;ACK1C,MAAMC,UAAsBC,EAC1B,gBAAIC,GACF,OAAOC,EACL,eAAeC,KAAKC,KAAKC,MAAMC,0CAA0CH,KAAKC,KAAKC,MAAME,8CAE7F,QAEAC,EAAAC,EAAA,CAAAC,GAAA,KAAAC,MAAA,6VAAAC,WAAA,4BAAAC,MAAAA,KAAAA,CAAAC,SAAAC,YAAAC,cAAA,IASAb,KAAU,EAGZ,IAAAc,EAAe,CACbC,KAAM,6BACNC,UAAAA;8BACEC,CAAeC,IAEb,MAAMC,EAAkB,CACtBC,QAAW,CAAC,IACZ,IAAO,CAAC;AAKVF,EAAIG,YAAY,mBAAqBC,GACnC,cAAcA,SAAAC,OAAAC,EAAAxB,KAAAyB,mBACXC,GAAA,CAAAC,QAAAJ,OAAAK,EAAA5B,KAAA;AAED6B,IAAAA,IAAQ5B,GACN6B,QAAQC,IAAI;AAEZ,MAAMC,EAAOd,EAAIe;AAGjB,IAAKD,GAAME,OAZM,IAYGF,EAAKzB,GAEvB,OADAuB,QAAQC,IAAI,+DACLI,MAAMN,QAAQ5B;AAKvB,MAAMmC,EAAUpC,KAAKE,MAAMmC,MAAQ;AACnCP,QAAQC,IAAI,oCAAqCO,KAAKC,MAAMD,KAAKE,UAAUJ;AAG3E,MAAMK,EAAiBL,EAAQM,IAAIC,GAExBC,OADQ,iBAAND,GAA+B,iBAANA,EACpBA,EAGFA,EAAEpC,IAAMoC,EAAExC,MAAQwC,EAAE5B,MAAQ,KACzC8B,OAAOC;AAEVhB,QAAQC,IAAI,2CAA4CU;AAGxD,MAAMM,EAAcN,EAAeO,KAAKzC,IACtC,MAAM0C,EAAa9B,EAAgBZ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