FIX: ensures trust_level_0 is not propagate from public to private event

FIX: ensures trust_level_0 is not propagate from public to private event

diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb
index 5d660f3..56f0490 100644
--- a/app/models/discourse_post_event/event.rb
+++ b/app/models/discourse_post_event/event.rb
@@ -249,11 +249,11 @@ module DiscoursePostEvent
 
       case params[:status] ? params[:status].to_i : self.status
       when Event.statuses[:private]
-        raw_invitees = Array(params[:raw_invitees])
+        raw_invitees = Array(params[:raw_invitees]) - ['trust_level_0']
         self.update!(params.merge(raw_invitees: raw_invitees))
         self.enforce_raw_invitees!
       when Event.statuses[:public]
-        self.update!(params.merge(raw_invitees: [:trust_level_0]))
+        self.update!(params.merge(raw_invitees: ['trust_level_0']))
       when Event.statuses[:standalone]
         self.update!(params.merge(raw_invitees: []))
         self.invitees.destroy_all
diff --git a/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6 b/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6
index 7991a40..16cf6de 100644
--- a/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6
+++ b/assets/javascripts/discourse/controllers/discourse-post-event-builder.js.es6
@@ -53,6 +53,17 @@ export default Controller.extend(ModalFunctionality, {
   },
 
   @action
+  onChangeStatus(newStatus) {
+    if (newStatus === "private") {
+      this.setRawInvitees(
+        null,
+        this.model.eventModel.raw_invitees.filter(x => x !== "trust_level_0")
+      );
+    }
+    this.set("model.eventModel.status", newStatus);
+  },
+
+  @action
   setRawInvitees(_, newInvitees) {
     this.set("model.eventModel.raw_invitees", newInvitees);
   },
diff --git a/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs b/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs
index a39c764..eccb77a 100644
--- a/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs
+++ b/assets/javascripts/discourse/templates/modal/discourse-post-event-builder.hbs
@@ -34,7 +34,7 @@
             name="status"
             value="public"
             selection=model.eventModel.status
-            onChange=(action (mut model.eventModel.status))
+            onChange=(action "onChangeStatus")
           }}
           <span class="message">
             <span class="title">{{i18n "discourse_post_event.models.event.status.public.title"}}</span>
@@ -46,7 +46,7 @@
             name="status"
             value="private"
             selection=model.eventModel.status
-            onChange=(action (mut model.eventModel.status))
+            onChange=(action "onChangeStatus")
           }}
           <span class="message">
             <span class="title">{{i18n "discourse_post_event.models.event.status.private.title"}}</span>
@@ -58,7 +58,7 @@
             name="status"
             value="standalone"
             selection=model.eventModel.status
-            onChange=(action (mut model.eventModel.status))
+            onChange=(action "onChangeStatus")
           }}
           <span class="message">
             <span class="title">{{i18n "discourse_post_event.models.event.status.standalone.title"}}</span>

GitHub sha: 41d65e6a

1 Like