Skip to content

Commit

Permalink
Merge pull request #1530 from codidact/art/maintenance-tasks
Browse files Browse the repository at this point in the history
Update maintenance_tasks
  • Loading branch information
Oaphi authored Feb 15, 2025
2 parents 6337f7a + e40d9f8 commit 41768be
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 12 deletions.
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ gem 'aws-sdk-s3', '~> 1.61', require: false
gem 'aws-sdk-sns', '~> 1.72'
gem 'aws-ses-v4', require: 'aws/ses'

# Task scheduler.
# Task scheduling & maintenance.
gem 'maintenance_tasks', '~> 2.2'
gem 'whenever', '~> 1.0', require: false

# Debugging, linting, testing.
Expand Down Expand Up @@ -100,5 +101,3 @@ group :development do
gem 'spring', '~> 4.0'
gem 'web-console', '~> 4.2'
end

gem 'maintenance_tasks', '~> 2.1.1'
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ GEM
crass (1.0.6)
css_parser (1.16.0)
addressable
csv (3.3.2)
date (3.4.1)
devise (4.8.1)
bcrypt (~> 3.0)
Expand Down Expand Up @@ -164,7 +165,7 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jmespath (1.6.1)
job-iteration (1.3.6)
job-iteration (1.9.0)
activejob (>= 5.2)
jquery-rails (4.5.0)
rails-dom-testing (>= 1, < 3)
Expand All @@ -191,12 +192,14 @@ GEM
net-imap
net-pop
net-smtp
maintenance_tasks (2.1.1)
actionpack (>= 6.0)
activejob (>= 6.0)
activerecord (>= 6.0)
job-iteration (~> 1.3.6)
railties (>= 6.0)
maintenance_tasks (2.11.0)
actionpack (>= 7.0)
activejob (>= 7.0)
activerecord (>= 7.0)
csv
job-iteration (>= 1.3.6)
railties (>= 7.0)
zeitwerk (>= 2.6.2)
marcel (1.0.4)
matrix (0.4.2)
memory_profiler (1.0.0)
Expand Down Expand Up @@ -423,7 +426,7 @@ DEPENDENCIES
jquery-rails (~> 4.5.0)
letter_opener_web (~> 2.0)
listen (~> 3.7)
maintenance_tasks (~> 2.1.1)
maintenance_tasks (~> 2.2)
memory_profiler (~> 1.0)
minitest (~> 5.16.0)
minitest-ci (~> 3.4.0)
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class TasksController < ApplicationController
before_action :check_permissions

private

def check_permissions
# We can't use ApplicationController#verify_developer because it tries to render not_found with
# layout: 'without_sidebar', which breaks because routing doesn't work under mounted applications. Bleugh.
if !helpers.user_signed_in? || !helpers.current_user.developer?
render plain: '403 Forbidden', status: :forbidden
end
end
end
1 change: 1 addition & 0 deletions config/initializers/maintenance_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MaintenanceTasks.parent_controller = 'TasksController'
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

root to: 'categories#homepage'

mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
mount MaintenanceTasks::Engine, at: '/maintenance'

scope 'admin' do
root to: 'admin#index', as: :admin
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ admin:
is_global_admin: false
is_global_moderator: false
confirmed_at: 2020-01-01T00:00:00.000000Z

developer:
email: [email protected]
encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW'
sign_in_count: 1337
username: developer
developer: true
confirmed_at: 2020-01-01T00:00:00.000000Z

global_moderator:
email: [email protected]
Expand Down
22 changes: 22 additions & 0 deletions test/integration/tasks_integration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'test_helper'

class TasksIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers

test 'should deny access to anonymous users' do
get '/maintenance'
assert_response 403
end

test 'should deny access to non-developers' do
sign_in users(:admin)
get '/maintenance'
assert_response 403
end

test 'should grant access to developers' do
sign_in users(:developer)
get '/maintenance'
assert_response 200
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ def load_host
request.env['HTTP_HOST'] = Community.first.host
end
end

class ActionDispatch::IntegrationTest
setup :load_host

def load_host
integration_session.host = Community.first.host
end
end

0 comments on commit 41768be

Please sign in to comment.