diff --git a/app/controllers/announcement_controller.rb b/app/controllers/announcement_controller.rb index 93083c1e..ee2bbb24 100644 --- a/app/controllers/announcement_controller.rb +++ b/app/controllers/announcement_controller.rb @@ -1,4 +1,6 @@ class AnnouncementController < ApplicationController + before_action :authenticate_user! + def index @announcements = Announcement.all end diff --git a/config/routes.rb b/config/routes.rb index bdc9a8c7..56dfd2b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -127,12 +127,15 @@ Rails.application.routes.draw do match '/:username/groups(/p/:page)', to: 'user#groups', via: 'get', as: :show_user_groups, defaults: {page: 1} match '/:username/questions(/p/:page)', to: 'user#questions', via: 'get', as: :show_user_questions, defaults: {page: 1} - match "/admin/announcements", to: "announcement#index", via: :get, as: :announcement_index - match "/admin/announcements", to: "announcement#create", via: :post, as: :announcement_create - match "/admin/announcements/new", to: "announcement#new", via: :get, as: :announcement_new - match "/admin/announcements/:id/edit", to: "announcement#edit", via: :get, as: :announcement_edit - match "/admin/announcements/:id", to: "announcement#update", via: :patch, as: :announcement_update - match "/admin/announcements/:id", to: "announcement#destroy", via: :delete, as: :announcement_destroy + constraints ->(req) { req.env['warden'].authenticate?(scope: :user) && + (req.env['warden'].user.admin?) } do + match "/admin/announcements", to: "announcement#index", via: :get, as: :announcement_index + match "/admin/announcements", to: "announcement#create", via: :post, as: :announcement_create + match "/admin/announcements/new", to: "announcement#new", via: :get, as: :announcement_new + match "/admin/announcements/:id/edit", to: "announcement#edit", via: :get, as: :announcement_edit + match "/admin/announcements/:id", to: "announcement#update", via: :patch, as: :announcement_update + match "/admin/announcements/:id", to: "announcement#destroy", via: :delete, as: :announcement_destroy + end puts 'processing time of routes.rb: ' + "#{(Time.now - start).round(3).to_s.ljust(5, '0')}s".light_green end