@@ -13,6 +13,7 @@ import DTooltip from "discourse/components/d-tooltip";
1313import withEventValue from " discourse/helpers/with-event-value" ;
1414import { ajax } from " discourse/lib/ajax" ;
1515import { popupAjaxError } from " discourse/lib/ajax-error" ;
16+ import dIcon from " discourse-common/helpers/d-icon" ;
1617import i18n from " discourse-common/helpers/i18n" ;
1718import getURL from " discourse-common/lib/get-url" ;
1819import AdminConfigAreaCard from " admin/components/admin-config-area-card" ;
@@ -35,10 +36,51 @@ export default class AiSpam extends Component {
3536 @tracked isEnabled = false ;
3637 @tracked selectedLLM = null ;
3738 @tracked customInstructions = " " ;
39+ @tracked errors = [];
3840
3941 constructor () {
4042 super (... arguments );
4143 this .initializeFromModel ();
44+
45+ if (this .args .model ? .spam_scanning_user ? .admin === false ) {
46+ this .errors .push ({
47+ message: i18n (" discourse_ai.spam.errors.scan_not_admin.message" ),
48+ button: {
49+ label: i18n (" discourse_ai.spam.errors.scan_not_admin.action" ),
50+ action: this .fixScanUserNotAdmin ,
51+ },
52+ });
53+ }
54+ }
55+
56+ @action
57+ async fixScanUserNotAdmin () {
58+ const spamScanningUser = this .args .model .spam_scanning_user ;
59+ if (! spamScanningUser || spamScanningUser .admin ) {
60+ return ;
61+ }
62+ try {
63+ const response = await ajax (
64+ ` /admin/plugins/discourse-ai/ai-spam/fix-errors` ,
65+ {
66+ type: " POST" ,
67+ data: {
68+ error: " spam_scanner_not_admin" ,
69+ },
70+ }
71+ );
72+
73+ if (response .success ) {
74+ this .toasts .success ({
75+ data: { message: i18n (" discourse_ai.spam.errors.resolved" ) },
76+ duration: 2000 ,
77+ });
78+ }
79+ } catch (error) {
80+ popupAjaxError (error);
81+ } finally {
82+ window .location .reload ();
83+ }
4284 }
4385
4486 @action
@@ -165,11 +207,22 @@ export default class AiSpam extends Component {
165207 <template >
166208 <div class =" ai-spam" >
167209 <section class =" ai-spam__settings" >
210+ <div class =" ai-spam__errors" >
211+ {{#each this . errors as | e | }}
212+ <div class =" alert alert-error" >
213+ {{dIcon " triangle-exclamation" }}
214+ <p >{{e.message }} </p >
215+ <DButton
216+ @ action ={{e.button.action }}
217+ @ translatedLabel ={{e.button.label }}
218+ />
219+ </div >
220+ {{/each }}
221+ </div >
168222 <DPageSubheader
169223 @ titleLabel ={{i18n " discourse_ai.spam.title" }}
170224 @ descriptionLabel ={{i18n " discourse_ai.spam.spam_description" }}
171225 />
172-
173226 <div class =" control-group ai-spam__enabled" >
174227 <DToggleSwitch
175228 class =" ai-spam__toggle"
0 commit comments