Skip to content

Commit

Permalink
add job mission control
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed Jul 9, 2024
1 parent 2bdf2fa commit f3693bc
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ gem "activerecord-enhancedsqlite3-adapter"
gem "litestream", "~> 0.10.1"
gem "solid_cache"
gem "solid_queue"
gem "mission_control-jobs"

gem "inline_svg", "~> 1.9"
gem "net-http", "~> 0.3.2"
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
inline_svg (1.9.0)
activesupport (>= 3.0)
nokogiri (>= 1.6)
Expand Down Expand Up @@ -238,6 +242,11 @@ GEM
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.24.1)
mission_control-jobs (0.2.1)
importmap-rails
rails (~> 7.1)
stimulus-rails
turbo-rails
msgpack (1.7.2)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
Expand Down Expand Up @@ -403,6 +412,8 @@ GEM
rubocop-performance (~> 1.21.0)
standardrb (1.0.1)
standard
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.1)
Expand Down Expand Up @@ -478,6 +489,7 @@ DEPENDENCIES
litestream (~> 0.10.1)
meilisearch-rails
meta-tags (~> 2.18)
mission_control-jobs
net-http (~> 0.3.2)
pagy (~> 6.0)
propshaft
Expand Down
2 changes: 1 addition & 1 deletion app/clients/youtube/transcript.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "message_pb"
require "message_type"

module Youtube
class Transcript
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
#
config.autoload_lib(ignore: %w[assets tasks])

config.active_job.queue_adapter = :solid_queue
config.solid_queue.connects_to = {database: {writing: :queue}}
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 10 } %>
timeout: 5000

# DATABASE CONFIGURATIONS
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#

Rails.application.routes.draw do
extend Authenticator

# static pages
get "uses", to: "page#uses"

Expand All @@ -14,6 +16,10 @@
get "sign_up", to: "registrations#new"
post "sign_up", to: "registrations#create"

authenticate :admin do
mount MissionControl::Jobs::Engine, at: "/jobs"
end

resources :sessions, only: [:index, :show, :destroy]
resource :password, only: [:edit, :update]
namespace :identity do
Expand Down
44 changes: 44 additions & 0 deletions lib/authenticator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Authenticator
class AdminConstraint
def matches?(request)
session = Session.find_by_id(request.cookie_jar.signed[:session_token])

if session
session.user.admin?
else
false
end
end
end

class UserConstraint
def matches?(request)
session = Session.find_by_id(request.cookie_jar.signed[:session_token])

if session
session.user
else
false
end
end
end

class ForbiddenConstraint
def matches?(request) = false
end

ROLES = {
admin: AdminConstraint,
user: UserConstraint
}

def authenticate(role, &)
constraints(constraint_for(role), &)
end

private

def constraint_for(role)
ROLES[role.to_sym]&.new || ForbiddenConstraint.new
end
end
File renamed without changes.

0 comments on commit f3693bc

Please sign in to comment.