From 54484612068214a01cf40256b7fd4db97d8255c4 Mon Sep 17 00:00:00 2001 From: Travis Grathwell Date: Sun, 29 May 2016 20:49:19 -0700 Subject: [PATCH] Event form: change code that updates CoC URL to fetch it over ajax Also fixes a bug where the CoC URL would be inaccurately set back to the default URL when you 'save draft' or the like. --- app/controllers/chapters_controller.rb | 5 +++++ app/models/chapter.rb | 4 ++++ app/models/event.rb | 4 ++++ app/views/events/_form.html.erb | 8 ++++---- config/routes.rb | 4 ++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/controllers/chapters_controller.rb b/app/controllers/chapters_controller.rb index 48a53ad8b..b34c44bfb 100644 --- a/app/controllers/chapters_controller.rb +++ b/app/controllers/chapters_controller.rb @@ -64,6 +64,11 @@ def destroy redirect_to chapters_url end + def code_of_conduct_url + skip_authorization + render text: @chapter.code_of_conduct_url + end + private def chapter_params diff --git a/app/models/chapter.rb b/app/models/chapter.rb index 877c36321..d80ba7946 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -22,4 +22,8 @@ def has_leader?(user) def destroyable? (events_count + external_events_count) == 0 end + + def code_of_conduct_url + organization.code_of_conduct_url || Event::DEFAULT_CODE_OF_CONDUCT_URL + end end diff --git a/app/models/event.rb b/app/models/event.rb index 1791d0cae..b5abe02ab 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -366,6 +366,10 @@ def levels course[:levels] end + def code_of_conduct_url + chapter.try(:code_of_conduct_url) || DEFAULT_CODE_OF_CONDUCT_URL + end + private DEFAULT_DETAIL_FILES = Dir[Rails.root.join('app', 'models', 'event_details', '*.html')] diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index a3b09a976..3bdda75a5 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -264,12 +264,12 @@
@@ -279,7 +279,7 @@ 'toggle-target' => '.coc-required', 'toggle-enable-when-checked' => true } %> - I accept the <%= link_to 'Code of Conduct', Event::DEFAULT_CODE_OF_CONDUCT_URL, target: :blank, id: 'coc_url' %> and will communicate it at the beginning of the event. + I accept the <%= link_to 'Code of Conduct', @event.code_of_conduct_url, target: :blank, id: 'coc_url' %> and will communicate it at the beginning of the event. <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 4860468f2..836ede5ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,10 @@ resources :leaders, only: [:index, :create, :destroy], controller: 'chapters/leaders' do get :potential, on: :collection end + + member do + get :code_of_conduct_url + end end resources :regions do