Skip to content

Commit

Permalink
REFACTOR: dry post_event_enabled check in controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Mar 27, 2020
1 parent 2695668 commit bfe84db
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
11 changes: 1 addition & 10 deletions 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'])

Expand Down
11 changes: 1 addition & 10 deletions 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
Expand Down
11 changes: 1 addition & 10 deletions 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
14 changes: 14 additions & 0 deletions 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
1 change: 1 addition & 0 deletions plugin.rb
Expand Up @@ -59,6 +59,7 @@ class Engine < ::Rails::Engine
"../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",
Expand Down

0 comments on commit bfe84db

Please sign in to comment.