Ensure we're logged in as an admin when using the AnnouncementController
This commit is contained in:
parent
b6d6c1fded
commit
a505e7ee71
|
@ -1,4 +1,6 @@
|
|||
class AnnouncementController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
@announcements = Announcement.all
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue