From 634cf4ee06a4820eaa2431a272b9a223118cf884 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 11 Nov 2024 21:09:06 +0000 Subject: Adds is_admin to the User model and ensures only admin users can add new resource --- app/controllers/pdfresources_controller.rb | 8 ++++++++ app/views/registrations/new.html.erb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/pdfresources_controller.rb b/app/controllers/pdfresources_controller.rb index 068b61a..1f8a6af 100644 --- a/app/controllers/pdfresources_controller.rb +++ b/app/controllers/pdfresources_controller.rb @@ -1,5 +1,6 @@ class PdfresourcesController < ApplicationController before_action :set_pdfresource, only: %i[ show edit update destroy ] + before_action :require_admin, only: %i[ new create update destroy ] # GET /pdfresources or /pdfresources.json def index @@ -67,4 +68,11 @@ class PdfresourcesController < ApplicationController def pdfresource_params params.expect(pdfresource: [ :name, :stripe_product_id, :price, :age_range, :curriculum, :feature_slot, :description, :card_description, pdfs: [], thumbnails: [] ]) end + + #must be admin! + def require_admin + unless Current.session.user&.is_admin + redirect_to root_path, notice: "You must be an admin to perform this action." + end + end end diff --git a/app/views/registrations/new.html.erb b/app/views/registrations/new.html.erb index b9e01e1..f70d143 100644 --- a/app/views/registrations/new.html.erb +++ b/app/views/registrations/new.html.erb @@ -26,7 +26,7 @@ <%= label_tag "email_address", nil, class: "font-bold text-gray-700" %> <%= form.email_field :email_address, required: true, autocomplete: "email_address", placeholder: "Enter your email address", value: params[:email_address], class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> - +
<%= label_tag "password", nil, class: "font-bold text-gray-700" %> <%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter new password", maxlength: 72, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> -- cgit v1.2.3