Skip to content

Commit

Permalink
Merge pull request #371 from fablabbcn/monolith
Browse files Browse the repository at this point in the history
Monolith Part 1: Incorporate id.sc functionality into the app and decommision.
  • Loading branch information
timcowlishaw authored Oct 23, 2024
2 parents 3e51bc5 + d7eb6aa commit 582db3d
Show file tree
Hide file tree
Showing 37 changed files with 590 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
TEST_DB_USERNAME: postgres
TEST_DB_PASSWORD: postgres
TEST_DB_NAME: postgres
discourse_sso_secret: "secret"
discourse_endpoint: "https://example.com"
PG_PORT: ${{ job.services.postgres.ports['5432'] }}

#- name: Deploy to server via SSH
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ gem 'rails', '6.1.7.3'
gem 'sidekiq', '~> 6'
gem 'doorkeeper', '~> 5'

gem 'jquery-rails'
gem 'sass-rails'
gem 'turbolinks'
gem 'uglifier'

# To resize active storage images:
# Revise if this is needed after Rails 6.0
gem 'image_processing'
Expand Down Expand Up @@ -91,6 +96,7 @@ group :development, :test do
gem 'brakeman', github: 'presidentbeef/brakeman', require: false
gem 'byebug'
gem 'cane'
gem "capybara"
gem 'factory_bot_rails'
gem 'faker'
gem 'guard-rspec'
Expand Down
39 changes: 38 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ GEM
c_geohash (1.1.2)
cane (3.0.0)
parallel
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
choice (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.2.2)
Expand Down Expand Up @@ -151,6 +160,7 @@ GEM
tzinfo
eventmachine (1.2.7)
excon (0.99.0)
execjs (2.9.1)
factory_bot (6.2.1)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
Expand Down Expand Up @@ -221,6 +231,10 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jmespath (1.6.2)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.6.3)
jwt (2.7.0)
kaminari (1.2.2)
Expand Down Expand Up @@ -252,6 +266,7 @@ GEM
json (>= 1.7.7)
rest-client (>= 1.6.7)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
Expand Down Expand Up @@ -445,6 +460,16 @@ GEM
rufus-scheduler (3.8.2)
fugit (~> 1.1, >= 1.1.6)
safe_yaml (1.0.5)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
sentry-rails (5.9.0)
railties (>= 5.0)
sentry-ruby (~> 5.9.0)
Expand Down Expand Up @@ -505,8 +530,13 @@ GEM
timeout (0.3.2)
treetop (1.6.12)
polyglot (~> 0.3)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uglifier (4.2.1)
execjs (>= 0.3.0, < 3)
unaccent (0.4.0)
unf (0.1.4)
unf_ext
Expand All @@ -526,6 +556,8 @@ GEM
workflow-activerecord (6.0.0)
activerecord (>= 6.0)
workflow (~> 3.0)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.34)
zeitwerk (2.6.8)
zonebie (0.6.1)
Expand All @@ -546,6 +578,7 @@ DEPENDENCIES
byebug
c_geohash
cane
capybara
countries
dalli
date_validator
Expand All @@ -561,6 +594,7 @@ DEPENDENCIES
guard-rspec
image_processing
jbuilder
jquery-rails
kaminari
listen
mailgun_rails
Expand Down Expand Up @@ -594,6 +628,7 @@ DEPENDENCIES
rspec-rails
rubocop
rufus-scheduler
sass-rails
sentry-rails
sentry-ruby
sentry-sidekiq
Expand All @@ -608,6 +643,8 @@ DEPENDENCIES
stamp
timecop
treetop
turbolinks
uglifier
vcr
versionist!
webmock
Expand All @@ -620,4 +657,4 @@ RUBY VERSION
ruby 3.0.6p216

BUNDLED WITH
2.5.21
2.5.22
3 changes: 3 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
Binary file added app/assets/images/sck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
15 changes: 15 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
63 changes: 63 additions & 0 deletions app/assets/stylesheets/sessions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
$blue: #0C2EFB;
$black: #212121;
$grey: #E3E3E3;
$red: #FA5161;

@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed:400,300,300italic,400italic,700,700italic|Roboto:400,700,700italic,400italic');
@import url('https://fonts.googleapis.com/css?family=Kanit:400,500,600,700,900');

*{
font-family:'Kanit';
}
body{
background-color: #e3e3e3;
}
h1{
font-weight:700 !important;
}
.button {
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 18px;
}
.bg-blue{
background-color: $blue !important;
}

.button:hover{
cursor: pointer;
color: white;
text-decoration:underline;
}

.bg-red{
background-color: $red;
}
.color-red{
color: $red;
}

input[type=text],input[type=password] {
padding:7px;
border:none;
border-bottom:2px solid #BEBEBE;
}

#flash_notice{
padding:20px;
color: white;
background-color: $blue;
}

#flash_alert{
padding:20px;
color: white;
background-color: $red;
}
4 changes: 1 addition & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# this file is required for errbit notifier
class ApplicationController < ActionController::API
include ActionController::ImplicitRender
include ActionController::Helpers
class ApplicationController < ActionController::Base
end
32 changes: 32 additions & 0 deletions app/controllers/discourse_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class DiscourseController < ApplicationController
include SharedControllerMethods

DISCOURSE_SSO_SECRET = ENV.fetch("discourse_sso_secret")
DISCOURSE_ENDPOINT = ENV.fetch("discourse_endpoint")
def sso
if !current_user
session[:discourse_url] = request.url
redirect_to new_ui_session_path(goto: request.path), notice: 'Please Log In before using SSO'
return
end
secret = DISCOURSE_SSO_SECRET
sso = SingleSignOn.parse(request.query_string, secret)
sso.email = current_user.email # from devise
#sso.name = current_user.full_name # this is a custom method on the User class
sso.username = current_user.email # from devise
#sso.username = current_user.username
sso.external_id = current_user.id # from devise
sso.sso_secret = secret

redirect_to sso.to_url("#{DISCOURSE_ENDPOINT}session/sso_login")
rescue => e
Rails.logger.error(e.message)
Rails.logger.error(e.backtrace)
#flash[:error] = 'SSO error'
render inline: "Error, check logs"

#redirect_to "/"
#redirect_to root
end

end
29 changes: 29 additions & 0 deletions app/controllers/shared_controller_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module SharedControllerMethods

include Pundit::Authorization

def self.included(klass)
klass.helper_method :current_user
end

def current_user(fail_unauthorized=true)
if @current_user.nil?
if session[:user_id]
@current_user = User.find(session[:user_id])
elsif doorkeeper_token
# return render text: 'abc'
@current_user = User.find(doorkeeper_token.resource_owner_id)
elsif ActionController::HttpAuthentication::Basic.has_basic_credentials?(request) # username and password
authenticate_with_http_basic do |username, password|
if user = User.find_by(username: username) and user.authenticate_with_legacy_support(password)
@current_user = user
elsif fail_unauthorized
self.headers["WWW-Authenticate"] = %(Basic realm="Application", Token realm="Application")
raise Smartcitizen::Unauthorized.new "Invalid Username/Password Combination"
end
end
end
end
@current_user
end
end
6 changes: 6 additions & 0 deletions app/controllers/ui/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Ui
class ApplicationController < ActionController::Base
layout "application"
include SharedControllerMethods
end
end
Loading

0 comments on commit 582db3d

Please sign in to comment.