REFACTOR: dry post_event_enabled check in controllers

REFACTOR: dry post_event_enabled check in controllers

diff --git a/app/controllers/discourse_calendar/invitees_controller.rb b/app/controllers/discourse_calendar/invitees_controller.rb
index c7ed24a..e8b3c73 100644
--- a/app/controllers/discourse_calendar/invitees_controller.rb
+++ b/app/controllers/discourse_calendar/invitees_controller.rb
@@ -1,16 +1,7 @@
 # frozen_string_literal: true
 
 module DiscourseCalendar
-  class InviteesController < ::ApplicationController
-    before_action :ensure_logged_in
-
-    before_action :ensure_post_event_enabled
-    def ensure_post_event_enabled
-      if !SiteSetting.post_event_enabled
-        raise Discourse::NotFound
-      end
-    end
-
+  class InviteesController < DiscourseCalendarController
     def index
       post_event = PostEvent.find(params['post-event-id'])
 
diff --git a/app/controllers/discourse_calendar/post_events_controller.rb b/app/controllers/discourse_calendar/post_events_controller.rb
index 5e18c71..843f68a 100644
--- a/app/controllers/discourse_calendar/post_events_controller.rb
+++ b/app/controllers/discourse_calendar/post_events_controller.rb
@@ -1,16 +1,7 @@
 # frozen_string_literal: true
 
 module DiscourseCalendar
-  class PostEventsController < ::ApplicationController
-    before_action :ensure_logged_in
-
-    before_action :ensure_post_event_enabled
-    def ensure_post_event_enabled
-      if !SiteSetting.post_event_enabled
-        raise Discourse::NotFound
-      end
-    end
-
+  class PostEventsController < DiscourseCalendarController
     def index
       # TODO: optimize this
       post_events_topics_ids = PostEvent
diff --git a/app/controllers/discourse_calendar/upcoming_events_controller.rb b/app/controllers/discourse_calendar/upcoming_events_controller.rb
index 29bea6f..34cf446 100644
--- a/app/controllers/discourse_calendar/upcoming_events_controller.rb
+++ b/app/controllers/discourse_calendar/upcoming_events_controller.rb
@@ -1,16 +1,7 @@
 # frozen_string_literal: true
 
 module DiscourseCalendar
-  class UpcomingEventsController < ::ApplicationController
-    before_action :ensure_logged_in
-
-    before_action :ensure_post_event_enabled
-    def ensure_post_event_enabled
-      if !SiteSetting.post_event_enabled
-        raise Discourse::NotFound
-      end
-    end
-
+  class UpcomingEventsController < DiscourseCalendarController
     def index; end
   end
 end
diff --git a/app/controllers/discourse_calendar_controller.rb b/app/controllers/discourse_calendar_controller.rb
new file mode 100644
index 0000000..094c45c
--- /dev/null
+++ b/app/controllers/discourse_calendar_controller.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module DiscourseCalendar
+  class DiscourseCalendarController < ::ApplicationController
+    before_action :ensure_logged_in
+
+    before_action :ensure_post_event_enabled
+    def ensure_post_event_enabled
+      if !SiteSetting.post_event_enabled
+        raise Discourse::NotFound
+      end
+    end
+  end
+end
diff --git a/plugin.rb b/plugin.rb
index 135c8a4..e8b1f65 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -59,6 +59,7 @@ after_initialize do
     "../app/models/calendar_event.rb",
     "../app/models/guardian.rb",
     "../app/serializers/user_timezone_serializer.rb",
+    "../app/controllers/discourse_calendar_controller.rb",
     "../app/controllers/discourse_calendar/invitees_controller.rb",
     "../app/controllers/discourse_calendar/post_events_controller.rb",
     "../app/controllers/discourse_calendar/upcoming_events_controller.rb",

GitHub sha: bfe84db1