From 2cbc8f01c52979186a261e6cfffec40d5466ebdf Mon Sep 17 00:00:00 2001 From: exbinary Date: Wed, 20 Jan 2021 01:05:26 -0500 Subject: [PATCH 1/7] Extract restful AdminDashboardController Replaces AdminController#landing_page. --- app/controllers/admin_controller.rb | 15 +-------------- app/controllers/admin_dashboard_controller.rb | 14 ++++++++++++++ .../submission_response_imports_controller.rb | 2 +- app/views/admin/form_admin.html.erb | 2 +- app/views/admin/volunteer_admin.html.erb | 2 +- .../show.html.erb} | 0 app/views/announcements/index.html.erb | 2 +- app/views/community_resources/index.html.erb | 2 +- app/views/layouts/_without_navbar.html.erb | 4 ++-- app/views/submissions/index.html.erb | 2 +- app/views/system_settings/show.html.erb | 2 +- config/routes.rb | 5 ++++- 12 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 app/controllers/admin_dashboard_controller.rb rename app/views/{admin/landing_page.html.erb => admin_dashboard/show.html.erb} (100%) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index ece4e6722..51b71d6f1 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -6,19 +6,6 @@ class AdminController < ApplicationController before_action :authenticate_user!, except: %i[new create] before_action :set_system_settings, only: [:glossary_edit, :glossary_index, :glossary_update] - def landing_page - @submission_count = Submission.count - @match_count = Match.any? ? Match.pluck(:receiver_id).uniq.length : 1 - @ask_count = Ask.any? ? Ask.all.length : 1 - @offer_count = Offer.any? ? Offer.all.length : 1 - @percent_offers_fulfilled = ((@match_count.to_f / @offer_count.to_f).to_f * 100).to_i - @percent_asks_fulfilled = ((@match_count.to_f / @ask_count.to_f).to_f * 100).to_i - @asks_unmatched_count = Ask.unmatched.length - @offers_unmatched_count = Offer.unmatched.length - @announcements_pending_count = Announcement.pending_review.length - @community_resources_pending_count = CommunityResource.pending_review.length - end - def dispatch_steps; end def form_admin; end @@ -38,7 +25,7 @@ def glossary_update @system_settings.update(glossary_content: glossary_params[:glossary_content]) redirect_to glossary_admin_path end - + def yearbook @positions = Position.all end diff --git a/app/controllers/admin_dashboard_controller.rb b/app/controllers/admin_dashboard_controller.rb new file mode 100644 index 000000000..e066f58ba --- /dev/null +++ b/app/controllers/admin_dashboard_controller.rb @@ -0,0 +1,14 @@ +class AdminDashboardController < AdminController + def show + @submission_count = Submission.count + @match_count = Match.any? ? Match.pluck(:receiver_id).uniq.length : 1 + @ask_count = Ask.any? ? Ask.all.length : 1 + @offer_count = Offer.any? ? Offer.all.length : 1 + @percent_offers_fulfilled = ((@match_count.to_f / @offer_count.to_f).to_f * 100).to_i + @percent_asks_fulfilled = ((@match_count.to_f / @ask_count.to_f).to_f * 100).to_i + @asks_unmatched_count = Ask.unmatched.length + @offers_unmatched_count = Offer.unmatched.length + @announcements_pending_count = Announcement.pending_review.length + @community_resources_pending_count = CommunityResource.pending_review.length + end +end diff --git a/app/controllers/submission_response_imports_controller.rb b/app/controllers/submission_response_imports_controller.rb index 87d14e564..2ccba1bc8 100644 --- a/app/controllers/submission_response_imports_controller.rb +++ b/app/controllers/submission_response_imports_controller.rb @@ -15,6 +15,6 @@ def create ) flash[:notice] = 'Your file has been uploaded and is being imported' - redirect_to landing_page_admin_path + redirect_to admin_dashboard_path end end diff --git a/app/views/admin/form_admin.html.erb b/app/views/admin/form_admin.html.erb index 17085f986..43694405a 100644 --- a/app/views/admin/form_admin.html.erb +++ b/app/views/admin/form_admin.html.erb @@ -8,4 +8,4 @@

-<%= link_to "Admin home", landing_page_admin_path %> \ No newline at end of file +<%= link_to "Admin home", admin_dashboard_path %> diff --git a/app/views/admin/volunteer_admin.html.erb b/app/views/admin/volunteer_admin.html.erb index 11bc382b7..c17c8ad87 100644 --- a/app/views/admin/volunteer_admin.html.erb +++ b/app/views/admin/volunteer_admin.html.erb @@ -12,4 +12,4 @@

-<%= link_to "Admin home", landing_page_admin_path %> \ No newline at end of file +<%= link_to "Admin home", admin_dashboard_path %> diff --git a/app/views/admin/landing_page.html.erb b/app/views/admin_dashboard/show.html.erb similarity index 100% rename from app/views/admin/landing_page.html.erb rename to app/views/admin_dashboard/show.html.erb diff --git a/app/views/announcements/index.html.erb b/app/views/announcements/index.html.erb index 5a66d5556..1b0975591 100644 --- a/app/views/announcements/index.html.erb +++ b/app/views/announcements/index.html.erb @@ -27,4 +27,4 @@

-<%= link_to "Admin home", landing_page_admin_path %> +<%= link_to "Admin home", admin_dashboard_path %> diff --git a/app/views/community_resources/index.html.erb b/app/views/community_resources/index.html.erb index bbd361fef..1657f66f3 100644 --- a/app/views/community_resources/index.html.erb +++ b/app/views/community_resources/index.html.erb @@ -39,4 +39,4 @@

-<%= link_to "Admin home", landing_page_admin_path %> +<%= link_to "Admin home", admin_dashboard_path %> diff --git a/app/views/layouts/_without_navbar.html.erb b/app/views/layouts/_without_navbar.html.erb index cc6cd66e0..e6f48f3dd 100644 --- a/app/views/layouts/_without_navbar.html.erb +++ b/app/views/layouts/_without_navbar.html.erb @@ -1,5 +1,5 @@ <% if current_user %>
- <%= link_to "Return to admin", landing_page_admin_path, class: "button is-primary is-outlined" %> + <%= link_to "Return to admin", admin_dashboard_path, class: "button is-primary is-outlined" %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/submissions/index.html.erb b/app/views/submissions/index.html.erb index 7ce7825b7..a97ffe79c 100644 --- a/app/views/submissions/index.html.erb +++ b/app/views/submissions/index.html.erb @@ -52,4 +52,4 @@

-<%= link_to "Admin home", landing_page_admin_path %> +<%= link_to "Admin home", admin_dashboard_path %> diff --git a/app/views/system_settings/show.html.erb b/app/views/system_settings/show.html.erb index 1c4d9df8c..14fdeaeea 100644 --- a/app/views/system_settings/show.html.erb +++ b/app/views/system_settings/show.html.erb @@ -91,5 +91,5 @@
<%= link_to('Edit', edit_system_setting_path(@system_setting)) + " | " if current_user.sys_admin_role? %> - <%= link_to 'Admin', landing_page_admin_path %> + <%= link_to 'Admin', admin_dashboard_path %> diff --git a/config/routes.rb b/config/routes.rb index d54cce433..022b0771a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,7 +5,10 @@ # FIXME: drop controller override when the pundit work is ready, #514 devise_for :users, controllers: { registrations: 'registrations_sans_signup' } - get '/admin', to: 'admin#landing_page', as: 'landing_page_admin' + scope '/admin' do + root to: 'admin_dashboard#show', as: 'admin_dashboard' + end + get '/admin/forms', to: 'admin#form_admin', as: 'form_admin' get '/admin/volunteers', to: 'admin#volunteer_admin', as: 'volunteer_admin' get '/admin/dispatch', to: 'admin#dispatch_steps', as: 'dispatch_steps_admin' From 1fb7777287bed85c277a4370539e0449f80b173e Mon Sep 17 00:00:00 2001 From: exbinary Date: Wed, 20 Jan 2021 23:51:10 -0500 Subject: [PATCH 2/7] Remove unused/unnecessary /admin/forms page This page links to Forms, FormQuestions and CustomFormQuestions, all of which are accessible from the admin dashboard. It also doesn't seem to be linked from anywhere. --- app/controllers/admin_controller.rb | 2 -- app/views/admin/form_admin.html.erb | 11 ----------- config/routes.rb | 1 - 3 files changed, 14 deletions(-) delete mode 100644 app/views/admin/form_admin.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 51b71d6f1..272448f05 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -8,8 +8,6 @@ class AdminController < ApplicationController def dispatch_steps; end - def form_admin; end - # FIXME: extract glossary related code into their own controller def glossary_edit @system_settings = SystemSetting.current_settings diff --git a/app/views/admin/form_admin.html.erb b/app/views/admin/form_admin.html.erb deleted file mode 100644 index 43694405a..000000000 --- a/app/views/admin/form_admin.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -
Forms admin
- -<%= link_to "Forms", forms_path %> -
-<%= link_to "Custom Form Questions", custom_form_questions_path %> -
-<%= link_to "Form Questions", form_questions_path %> -
- -
-<%= link_to "Admin home", admin_dashboard_path %> diff --git a/config/routes.rb b/config/routes.rb index 022b0771a..2b1f9343e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,6 @@ root to: 'admin_dashboard#show', as: 'admin_dashboard' end - get '/admin/forms', to: 'admin#form_admin', as: 'form_admin' get '/admin/volunteers', to: 'admin#volunteer_admin', as: 'volunteer_admin' get '/admin/dispatch', to: 'admin#dispatch_steps', as: 'dispatch_steps_admin' get '/admin/glossary', to: 'admin#glossary_index', as: 'glossary_admin' From 0a2348973b773f26921c6739f1ebcb85dfcd8774 Mon Sep 17 00:00:00 2001 From: exbinary Date: Thu, 21 Jan 2021 00:06:48 -0500 Subject: [PATCH 3/7] Extract VolunteerAdminController --- app/controllers/volunteer_admin_controller.rb | 2 ++ .../volunteer_admin.html.erb => volunteer_admin/show.html.erb} | 0 config/routes.rb | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 app/controllers/volunteer_admin_controller.rb rename app/views/{admin/volunteer_admin.html.erb => volunteer_admin/show.html.erb} (100%) diff --git a/app/controllers/volunteer_admin_controller.rb b/app/controllers/volunteer_admin_controller.rb new file mode 100644 index 000000000..d18c4439b --- /dev/null +++ b/app/controllers/volunteer_admin_controller.rb @@ -0,0 +1,2 @@ +class VolunteerAdminController < AdminController +end diff --git a/app/views/admin/volunteer_admin.html.erb b/app/views/volunteer_admin/show.html.erb similarity index 100% rename from app/views/admin/volunteer_admin.html.erb rename to app/views/volunteer_admin/show.html.erb diff --git a/config/routes.rb b/config/routes.rb index 2b1f9343e..005c1f7f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,9 +7,10 @@ scope '/admin' do root to: 'admin_dashboard#show', as: 'admin_dashboard' + + resource :volunteers, only: [:show], controller: :volunteer_admin, as: 'volunteer_admin' end - get '/admin/volunteers', to: 'admin#volunteer_admin', as: 'volunteer_admin' get '/admin/dispatch', to: 'admin#dispatch_steps', as: 'dispatch_steps_admin' get '/admin/glossary', to: 'admin#glossary_index', as: 'glossary_admin' get '/admin/glossary_edit', to: 'admin#glossary_edit', as: 'glossary_admin_edit' From 8b6e91c8deec5e22160cc739e2e90d20ea0f9232 Mon Sep 17 00:00:00 2001 From: exbinary Date: Thu, 21 Jan 2021 00:19:10 -0500 Subject: [PATCH 4/7] Extract DispatchSteps controller --- app/controllers/admin_controller.rb | 2 -- app/controllers/dispatch_steps_controller.rb | 2 ++ app/views/admin_dashboard/show.html.erb | 2 +- app/views/contributions/respond.html.erb | 2 +- .../dispatch_steps.html.erb => dispatch_steps/show.html.erb} | 0 app/views/volunteer_admin/show.html.erb | 2 +- config/routes.rb | 4 ++-- 7 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 app/controllers/dispatch_steps_controller.rb rename app/views/{admin/dispatch_steps.html.erb => dispatch_steps/show.html.erb} (100%) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 272448f05..be437b3b1 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -6,8 +6,6 @@ class AdminController < ApplicationController before_action :authenticate_user!, except: %i[new create] before_action :set_system_settings, only: [:glossary_edit, :glossary_index, :glossary_update] - def dispatch_steps; end - # FIXME: extract glossary related code into their own controller def glossary_edit @system_settings = SystemSetting.current_settings diff --git a/app/controllers/dispatch_steps_controller.rb b/app/controllers/dispatch_steps_controller.rb new file mode 100644 index 000000000..09626b3fe --- /dev/null +++ b/app/controllers/dispatch_steps_controller.rb @@ -0,0 +1,2 @@ +class DispatchStepsController < AdminController +end diff --git a/app/views/admin_dashboard/show.html.erb b/app/views/admin_dashboard/show.html.erb index b7ec8bbf7..e8f37dc45 100644 --- a/app/views/admin_dashboard/show.html.erb +++ b/app/views/admin_dashboard/show.html.erb @@ -47,7 +47,7 @@
<%= link_to "Glossary!", glossary_path %>
- <%= link_to "Dispatch steps", dispatch_steps_admin_path %> + <%= link_to "Dispatch steps", dispatch_steps_path %>
<%= link_to "Yearbook", yearbook_admin_path %>
diff --git a/app/views/contributions/respond.html.erb b/app/views/contributions/respond.html.erb index ecf5eb3b2..998353d3f 100644 --- a/app/views/contributions/respond.html.erb +++ b/app/views/contributions/respond.html.erb @@ -3,7 +3,7 @@
Respond to Contribution: <%= link_to "go to Contributions page", contributions_path %>
- <%= link_to "(1. Triage (or log Communication), then 2. Add tentative Match)", dispatch_steps_admin_path %> + <%= link_to "(1. Triage (or log Communication), then 2. Add tentative Match)", dispatch_steps_path %>


diff --git a/app/views/admin/dispatch_steps.html.erb b/app/views/dispatch_steps/show.html.erb similarity index 100% rename from app/views/admin/dispatch_steps.html.erb rename to app/views/dispatch_steps/show.html.erb diff --git a/app/views/volunteer_admin/show.html.erb b/app/views/volunteer_admin/show.html.erb index c17c8ad87..2dcecd796 100644 --- a/app/views/volunteer_admin/show.html.erb +++ b/app/views/volunteer_admin/show.html.erb @@ -4,7 +4,7 @@
<%= link_to "Add Shifts", shifts_path %>
-<%= link_to "Review Dispatch steps", dispatch_steps_admin_path %> +<%= link_to "Review Dispatch steps", dispatch_steps_path %>
<%= link_to "View training status (NOT IMPLEMENTED)", people_path(position_type: "Volunteer") %>
diff --git a/config/routes.rb b/config/routes.rb index 005c1f7f5..ae33c6415 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,10 +8,10 @@ scope '/admin' do root to: 'admin_dashboard#show', as: 'admin_dashboard' - resource :volunteers, only: [:show], controller: :volunteer_admin, as: 'volunteer_admin' + resource :volunteers, only: [:show], controller: :volunteer_admin, as: 'volunteer_admin' + resource :dispatch_steps, only: [:show] end - get '/admin/dispatch', to: 'admin#dispatch_steps', as: 'dispatch_steps_admin' get '/admin/glossary', to: 'admin#glossary_index', as: 'glossary_admin' get '/admin/glossary_edit', to: 'admin#glossary_edit', as: 'glossary_admin_edit' patch '/admin/glossary_edit', to: 'admin#glossary_update', as: 'glossary_admin_update' From 7c6cf57f5f061a30a3ab0f3e971c451f6b4e8554 Mon Sep 17 00:00:00 2001 From: exbinary Date: Thu, 21 Jan 2021 00:25:22 -0500 Subject: [PATCH 5/7] Extract YearbookController --- app/controllers/admin_controller.rb | 4 ---- app/controllers/yearbook_controller.rb | 5 +++++ app/views/admin_dashboard/show.html.erb | 2 +- app/views/glossary/show.html.erb | 2 +- .../{admin/yearbook.html.erb => yearbook/show.html.erb} | 0 config/routes.rb | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 app/controllers/yearbook_controller.rb rename app/views/{admin/yearbook.html.erb => yearbook/show.html.erb} (100%) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index be437b3b1..87d82f3ef 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -22,10 +22,6 @@ def glossary_update redirect_to glossary_admin_path end - def yearbook - @positions = Position.all - end - private def glossary_params diff --git a/app/controllers/yearbook_controller.rb b/app/controllers/yearbook_controller.rb new file mode 100644 index 000000000..6d37465d1 --- /dev/null +++ b/app/controllers/yearbook_controller.rb @@ -0,0 +1,5 @@ +class YearbookController < AdminController + def show + @positions = Position.all + end +end diff --git a/app/views/admin_dashboard/show.html.erb b/app/views/admin_dashboard/show.html.erb index e8f37dc45..79dd4ae43 100644 --- a/app/views/admin_dashboard/show.html.erb +++ b/app/views/admin_dashboard/show.html.erb @@ -49,7 +49,7 @@
<%= link_to "Dispatch steps", dispatch_steps_path %>
- <%= link_to "Yearbook", yearbook_admin_path %> + <%= link_to "Yearbook", yearbook_path %>
<%= link_to "Org chart", org_chart_path %>
diff --git a/app/views/glossary/show.html.erb b/app/views/glossary/show.html.erb index 05c33a179..48d31e56d 100644 --- a/app/views/glossary/show.html.erb +++ b/app/views/glossary/show.html.erb @@ -76,7 +76,7 @@
- <%= link_to "Yearbook", yearbook_admin_path %>: List of everyone who has a Position. (Later we can have Profile photos.) + <%= link_to "Yearbook", yearbook_path %>: List of everyone who has a Position. (Later we can have Profile photos.)
diff --git a/app/views/admin/yearbook.html.erb b/app/views/yearbook/show.html.erb similarity index 100% rename from app/views/admin/yearbook.html.erb rename to app/views/yearbook/show.html.erb diff --git a/config/routes.rb b/config/routes.rb index ae33c6415..6cedb0b9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,12 +10,12 @@ resource :volunteers, only: [:show], controller: :volunteer_admin, as: 'volunteer_admin' resource :dispatch_steps, only: [:show] + resource :yearbook, only: [:show], controller: :yearbook end get '/admin/glossary', to: 'admin#glossary_index', as: 'glossary_admin' get '/admin/glossary_edit', to: 'admin#glossary_edit', as: 'glossary_admin_edit' patch '/admin/glossary_edit', to: 'admin#glossary_update', as: 'glossary_admin_update' - get '/admin/yearbook', to: 'admin#yearbook', as: 'yearbook_admin' get '/public', to: 'public_pages#landing_page', as: 'landing_page_public' get '/about', to: 'public_pages#about', as: 'about_public' From e5ae91f3908a4d95b87bc9bfd295e7df34f70e1e Mon Sep 17 00:00:00 2001 From: exbinary Date: Thu, 21 Jan 2021 20:21:43 -0500 Subject: [PATCH 6/7] Move glossary related actions out of AdminController... ... into GlossaryController, and consolidate views. Note two important loose ends: 1. The edit/update actions need to be secured with pundit. 2. The current glossary was hardcoded in /glossary/show.html.erb. Since this commit changes that to be dynamic, we'll want to put the static contents into a seed file or similar. --- app/controllers/admin_controller.rb | 29 +----- app/controllers/glossary_controller.rb | 18 ++++ app/views/admin/glossary/index.html.erb | 4 - .../{admin => }/glossary/_header.html.erb | 0 .../form.html.erb => glossary/edit.html.erb} | 6 +- app/views/glossary/show.html.erb | 97 +------------------ config/routes.rb | 6 +- spec/requests/admin_spec.rb | 37 ------- spec/requests/glossary_spec.rb | 35 +++++++ 9 files changed, 62 insertions(+), 170 deletions(-) delete mode 100644 app/views/admin/glossary/index.html.erb rename app/views/{admin => }/glossary/_header.html.erb (100%) rename app/views/{admin/glossary/form.html.erb => glossary/edit.html.erb} (52%) delete mode 100644 spec/requests/admin_spec.rb create mode 100644 spec/requests/glossary_spec.rb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 87d82f3ef..6a25ee7f1 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -3,32 +3,5 @@ class AdminController < ApplicationController include NotUsingPunditYet - before_action :authenticate_user!, except: %i[new create] - before_action :set_system_settings, only: [:glossary_edit, :glossary_index, :glossary_update] - - # FIXME: extract glossary related code into their own controller - def glossary_edit - @system_settings = SystemSetting.current_settings - render 'admin/glossary/form' - end - - def glossary_index - @glossary_content = @system_settings.glossary_content - render 'admin/glossary/index' - end - - def glossary_update - @system_settings.update(glossary_content: glossary_params[:glossary_content]) - redirect_to glossary_admin_path - end - - private - - def glossary_params - params.require(:system_setting).permit(:glossary_content) - end - - def set_system_settings - @system_settings = SystemSetting.current_settings - end + before_action :authenticate_user! end diff --git a/app/controllers/glossary_controller.rb b/app/controllers/glossary_controller.rb index efb0708b9..5542f4a78 100644 --- a/app/controllers/glossary_controller.rb +++ b/app/controllers/glossary_controller.rb @@ -1,5 +1,23 @@ class GlossaryController < PublicController include NotUsingPunditYet + before_action :set_system_settings + def show; end + def edit; end + + def update + @system_settings.update!(glossary_params) + redirect_to glossary_path + end + + private + + def glossary_params + params.require(:system_setting).permit(:glossary_content) + end + + def set_system_settings + @system_settings = SystemSetting.current_settings + end end diff --git a/app/views/admin/glossary/index.html.erb b/app/views/admin/glossary/index.html.erb deleted file mode 100644 index b6d9b4839..000000000 --- a/app/views/admin/glossary/index.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= render partial: 'admin/glossary/header' %> -<%= link_to "Edit Glossary", glossary_admin_edit_path, class: "btn" %> -
-<%= @glossary_content %> diff --git a/app/views/admin/glossary/_header.html.erb b/app/views/glossary/_header.html.erb similarity index 100% rename from app/views/admin/glossary/_header.html.erb rename to app/views/glossary/_header.html.erb diff --git a/app/views/admin/glossary/form.html.erb b/app/views/glossary/edit.html.erb similarity index 52% rename from app/views/admin/glossary/form.html.erb rename to app/views/glossary/edit.html.erb index 5e1b473b9..924053891 100644 --- a/app/views/admin/glossary/form.html.erb +++ b/app/views/glossary/edit.html.erb @@ -1,8 +1,8 @@ -<%= render partial: 'admin/glossary/header' %> -<%= link_to "View Glossary", glossary_admin_path %> +<%= render partial: 'glossary/header' %> +<%= link_to "View Glossary", glossary_path %>
- <%= form_with model: @system_settings, url: glossary_admin_edit_path, local: true do |f| %> + <%= form_with model: @system_settings, url: glossary_path, local: true do |f| %>
<%= f.rich_text_area :glossary_content %>
diff --git a/app/views/glossary/show.html.erb b/app/views/glossary/show.html.erb index 48d31e56d..ddc706db1 100644 --- a/app/views/glossary/show.html.erb +++ b/app/views/glossary/show.html.erb @@ -1,93 +1,4 @@ -
-
-
Glossary
-
-
-
- -
-
-
- <%= link_to "Contributions", contributions_path %>: All public-generated content, like, Asks, Offers, Community Resources, Announcements - -
- - <%= link_to "Community Resources", community_resources_path(is_approved: false) %>: Local offerings and organizations that are always available, e.g. Food Pantry, Diaper Bank. Can be links or videos -
- <%= link_to "Announcements", announcements_path(is_approved: false) %>: References and notes to share with the public about specific events and offerings, e.g. food drive Jun 12 - -
- - - <%= link_to "Asks", listings_path(contribution_type: "Ask") %>: Request for support/exchange from the public -
- <%= link_to "Offers", listings_path(contribution_type: "Offer") %> Offer of support/exchange from the public -
- <%= link_to "Donations", donations_path %>: Log of Donations to the mutual aid group, but this form could connect to Stripe, etc, later - -
- - <%= link_to "Locations", locations_path %>: Address-related info submitted by People or Organizations when they fill out Forms. Also used to store Service Area info -
- <%= link_to "Location Types", location_types_path %>: Kind of Location, so, home, business, cross street, etc -
- <%= link_to "Submissions", submissions_path %>: Form "responses" (This is a log of all results from all Forms: Ask, Offer, (CommunityResource, Annoucement, Volunteer), etc) -
- <%= link_to "Form Questions", custom_form_questions_path %>: Questions you want to be on your Forms -
- <%= link_to "Submission Responses", submission_responses_path %>: People's answers to specific Form Questions - -
- - - <%= link_to "Matches", matches_path %>: Connection between a receiver (Ask/Profile) and a provider (Offer/Community Resource/Profile) (Profile matches are TBD) -
- <%= link_to "Feedback", feedbacks_path %>: Each Match will generate an email request to receivers and providers to request Feedback about their experience. (We are considering showing stats on Profiles re thumbsup/starts/rating, TBD) -
- <%= link_to "Communication Log", communication_logs_path %>: Log of all phone calls, texts, etc, to People. Any system-generated emails will be saved as such. - -
- - <%= link_to "People", people_path %>: All the human People in the system -- receiver/provider/leadership team member/partner organization point of contact/etc -
- <%= link_to "Volunteers", volunteer_admin_path %>: People who are part of the group (different than Providers who submit Offers) -
- <%= link_to "Positions", positions_path %>: Title/Role/Membership a Person has within an Organization, e.g. Leadership Team member/Dispatch Team member/Point of Contact - -
- - <%= link_to "User accounts", users_path %>: For People who log in to this system. People will still have Profiles even if they don't have a User Account. (Still need to decide depending on login status.) -
- <%= link_to "Shared Accounts", shared_accounts_path %>: List of accounts the mutual aid group keeps, along w descriptions (but NOT passwords!), so there's one list of all the gmail addresses, payment gateways, etc. (Again, NOT the actual passwords!) -
- <%= link_to "Software Feedback", software_feedbacks_path %>: Place for Users (Admins only?) to store ideas/feedback for this system. (Y'all can decide which of these you want to request of coders...) -
- - <%= link_to "Categories", categories_path %>: Services offered/facilitated by the mutual aid group. Can be nested. Categories will appear on Form checkboxes and dropdowns, and Contribution page filters -
- <%= link_to "Service Areas", service_areas_path %>: Geographic "areas" served by the mutual aid group. Can be nested. Can start at state, and drill down to Pods. Service Areas will appear on Form checkboxes and dropdowns, and Contribution page filters -
- <%= link_to "Contact Methods", contact_methods_path %>: Mechanism for contacting People, e.g. Text, Call, Email, WhatsApp. Contact Methods will appear on Form checkboxes and dropdowns, and on Contribution page filters - -
- <%= link_to "Translations", mobility_string_translations_path %>: Working up to multilanguage support -
- <%= link_to "System Locales", system_locales_path %>: Languages your group supports. We populated this list, but you can change it to whatever you want! - -
- - <%= link_to "Yearbook", yearbook_path %>: List of everyone who has a Position. (Later we can have Profile photos.) - -
- - <%= link_to "Respond", respond_contribution_path(Listing.first) %>: Preview a Contribution and prepare to "Respond" to the person by adding a Tentative Match -
- <%= link_to "Triage", triage_contribution_path(Listing.first) %>: Update Contribution -- Add short summary, change description, indicate if 'Inexhaustible' -
- Tentative Match: This is a real Match. The first point of contact is to choose a potential match, and then to contact both parties. -
- Inexhaustible: This Contribution can be matched many times, will continue to show up in dropdowns, etc - -
-
-
+<%= render partial: 'glossary/header' %> +<%= link_to "Edit Glossary", edit_glossary_path, class: "btn" %> +
+<%= @system_settings.glossary_content %> diff --git a/config/routes.rb b/config/routes.rb index 6cedb0b9e..509b34bf9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,10 +13,6 @@ resource :yearbook, only: [:show], controller: :yearbook end - get '/admin/glossary', to: 'admin#glossary_index', as: 'glossary_admin' - get '/admin/glossary_edit', to: 'admin#glossary_edit', as: 'glossary_admin_edit' - patch '/admin/glossary_edit', to: 'admin#glossary_update', as: 'glossary_admin_update' - get '/public', to: 'public_pages#landing_page', as: 'landing_page_public' get '/about', to: 'public_pages#about', as: 'about_public' get '/announcements_list', to: 'public_pages#announcements', as: 'announcements_public' @@ -80,7 +76,7 @@ resources :teams resources :users - resource :glossary, controller: :glossary, only: [:show] + resource :glossary, controller: :glossary, only: [:show, :edit, :update] root :to => 'public_pages#landing_page' end diff --git a/spec/requests/admin_spec.rb b/spec/requests/admin_spec.rb deleted file mode 100644 index e39641723..000000000 --- a/spec/requests/admin_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'rails_helper' - -describe '/admin', type: :request do - before do - sign_in create(:user, :admin) - end - - describe 'GET /glossary' do - it 'renders a successful response' do - get glossary_admin_url - expect(response).to be_successful - end - end - - describe 'GET /glossary_edit' do - it 'renders a successful response' do - get glossary_admin_edit_url - expect(response).to be_successful - end - end - - describe 'PATCH /glossary_edit' do - let(:system_settings) { (FactoryBot.create :system_setting) } - let(:glossary_html) { "Word: Definition" } - - it 'does not update the glossary_content if system_setting object is missing' do - patch glossary_admin_update_url(), params: { system_setting: { glossary_content: glossary_html } } - expect(system_settings.glossary_content.body).to be_nil - end - - it 'updates glossary_content of the system_setting object' do - patch glossary_admin_update_url(system_settings), params: { system_setting: { glossary_content: glossary_html } } - expect(response.status).to eq 302 - expect(system_settings.glossary_content.body).not_to be_nil - end - end -end diff --git a/spec/requests/glossary_spec.rb b/spec/requests/glossary_spec.rb new file mode 100644 index 000000000..7835973dd --- /dev/null +++ b/spec/requests/glossary_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +describe '/glossary', type: :request do + let!(:system_setting) { FactoryBot.create :system_setting, glossary_content: 'Original text' } + + before do + sign_in create(:user, :admin) + end + + describe 'GET /glossary' do + it 'renders a successful response with the current content' do + get glossary_url + expect(response).to be_successful + expect(response.body).to include 'Original text' + end + end + + describe 'GET /glossary/edit' do + it 'renders a successful response with the current content' do + get edit_glossary_url + expect(response).to be_successful + expect(response.body).to include 'Original text' + end + end + + describe 'PATCH /glossary' do + let(:new_html) { "Word: Definition" } + + it 'updates glossary_content of the system_setting object' do + patch glossary_url, params: { system_setting: { glossary_content: new_html } } + expect(response.status).to eq 302 + expect(system_setting.reload.glossary_content.to_s).to include new_html + end + end +end From 083b6ffc5a7586dca5808f7c2e4fbc981e51fe64 Mon Sep 17 00:00:00 2001 From: Svetlana Vileshina Date: Tue, 26 Jan 2021 13:53:31 -0500 Subject: [PATCH 7/7] glossary policy and specs, glossary changed to inherit app controllers --- app/controllers/glossary_controller.rb | 10 +++++--- app/policies/glossary_policy.rb | 9 +++++++ app/views/glossary/show.html.erb | 4 ++- spec/policies/glossary_policy_spec.rb | 29 ++++++++++++++++++++++ spec/requests/glossary_spec.rb | 34 ++++++++++++++------------ 5 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 app/policies/glossary_policy.rb create mode 100644 spec/policies/glossary_policy_spec.rb diff --git a/app/controllers/glossary_controller.rb b/app/controllers/glossary_controller.rb index 5542f4a78..5ffc84b22 100644 --- a/app/controllers/glossary_controller.rb +++ b/app/controllers/glossary_controller.rb @@ -1,6 +1,6 @@ -class GlossaryController < PublicController - include NotUsingPunditYet - +class GlossaryController < ApplicationController + skip_before_action :authenticate_user!, only: [:show] + before_action :authorize_glossary before_action :set_system_settings def show; end @@ -13,6 +13,10 @@ def update private + def authorize_glossary + authorize :glossary + end + def glossary_params params.require(:system_setting).permit(:glossary_content) end diff --git a/app/policies/glossary_policy.rb b/app/policies/glossary_policy.rb new file mode 100644 index 000000000..aa4d62259 --- /dev/null +++ b/app/policies/glossary_policy.rb @@ -0,0 +1,9 @@ +class GlossaryPolicy < ApplicationPolicy + def read? + true + end + + def change? + acting_user && (acting_user.admin_role? || acting_user.sys_admin_role? ) + end +end \ No newline at end of file diff --git a/app/views/glossary/show.html.erb b/app/views/glossary/show.html.erb index ddc706db1..af91e85f8 100644 --- a/app/views/glossary/show.html.erb +++ b/app/views/glossary/show.html.erb @@ -1,4 +1,6 @@ <%= render partial: 'glossary/header' %> -<%= link_to "Edit Glossary", edit_glossary_path, class: "btn" %> +<% if policy(:glossary).change? %> + <%= link_to "Edit Glossary", edit_glossary_path, class: "btn" %> +<% end %>
<%= @system_settings.glossary_content %> diff --git a/spec/policies/glossary_policy_spec.rb b/spec/policies/glossary_policy_spec.rb new file mode 100644 index 000000000..4088a6db7 --- /dev/null +++ b/spec/policies/glossary_policy_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +RSpec.describe GlossaryPolicy do + subject { GlossaryPolicy.new(user, :glossary) } + + context "user can edit glossary if they are" do + context "an admin" do + let(:user) { build(:user, :admin) } + it { is_expected.to permit_action(:update) } + end + + context "a sys_admin" do + let(:user) { build(:user, :sys_admin) } + it { is_expected.to permit_action(:update) } + end + end + + context "user cannot edit glossary if they are" do + context "a neighbor" do + let(:user) { build(:user, :neighbor) } + it { is_expected.not_to permit_action(:update) } + end + + context "not logged in" do + let(:user) { nil } + it { is_expected.not_to permit_action(:update) } + end + end +end \ No newline at end of file diff --git a/spec/requests/glossary_spec.rb b/spec/requests/glossary_spec.rb index 7835973dd..521c4f824 100644 --- a/spec/requests/glossary_spec.rb +++ b/spec/requests/glossary_spec.rb @@ -3,10 +3,6 @@ describe '/glossary', type: :request do let!(:system_setting) { FactoryBot.create :system_setting, glossary_content: 'Original text' } - before do - sign_in create(:user, :admin) - end - describe 'GET /glossary' do it 'renders a successful response with the current content' do get glossary_url @@ -15,21 +11,27 @@ end end - describe 'GET /glossary/edit' do - it 'renders a successful response with the current content' do - get edit_glossary_url - expect(response).to be_successful - expect(response.body).to include 'Original text' + context "when user is signed in" do + before do + sign_in create(:user, :admin) + end + + describe 'GET /glossary/edit' do + it 'renders a successful response with the current content' do + get edit_glossary_url + expect(response).to be_successful + expect(response.body).to include 'Original text' + end end - end - describe 'PATCH /glossary' do - let(:new_html) { "Word: Definition" } + describe 'PATCH /glossary' do + let(:new_html) { "Word: Definition" } - it 'updates glossary_content of the system_setting object' do - patch glossary_url, params: { system_setting: { glossary_content: new_html } } - expect(response.status).to eq 302 - expect(system_setting.reload.glossary_content.to_s).to include new_html + it 'updates glossary_content of the system_setting object' do + patch glossary_url, params: { system_setting: { glossary_content: new_html } } + expect(response.status).to eq 302 + expect(system_setting.reload.glossary_content.to_s).to include new_html + end end end end