Merge pull request #900 from openSUSE/demo

Make it possible to run OSEM on heroku
This commit is contained in:
Henne Vogelsang 2016-04-29 16:51:26 +02:00
commit ac0659d9c6
31 changed files with 242 additions and 137 deletions

5
.gitignore vendored
View file

@ -31,3 +31,8 @@ pickle-email-*.html
/doc/app /doc/app
.ruby-version .ruby-version
.vagrant/ .vagrant/
.env
.env.production
.env.development
.env.test
.env.local

View file

@ -18,8 +18,6 @@ notifications:
on_failure: change on_failure: change
before_script: before_script:
- cp config/database.yml.example config/database.yml - cp config/database.yml.example config/database.yml
- cp config/config.yml.example config/config.yml
- cp config/secrets.yml.example config/secrets.yml
- RAILS_ENV=test bundle exec rake db:migrate --trace - RAILS_ENV=test bundle exec rake db:migrate --trace
script: script:
- 'bundle exec rubocop -Dc .rubocop.yml' - 'bundle exec rubocop -Dc .rubocop.yml'

View file

@ -8,6 +8,11 @@ end
# as web framework # as web framework
gem 'rails', '~> 4.2' gem 'rails', '~> 4.2'
# enables serving assets in production and setting your logger to standard out
# both of which are required to run an application on a twelve-factor provider
# like heroku.com
gem 'rails_12factor', group: :production
# respond_to methods have been extracted to the responders gem # respond_to methods have been extracted to the responders gem
# http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#responders # http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#responders
gem 'responders', '~> 2.0' gem 'responders', '~> 2.0'
@ -166,6 +171,10 @@ gem 'ruby-oembed'
# for uploading images to the cloud # for uploading images to the cloud
gem 'cloudinary' gem 'cloudinary'
# for setting app configuration in the environment
gem 'dotenv-rails'
# Use guard and spring for testing in development
group :development do group :development do
# to launch specs when files are modified # to launch specs when files are modified
gem 'guard-rspec', '~> 4.2.8' gem 'guard-rspec', '~> 4.2.8'

View file

@ -162,6 +162,10 @@ GEM
docile (1.1.5) docile (1.1.5)
domain_name (0.5.20160310) domain_name (0.5.20160310)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
dotenv (2.1.1)
dotenv-rails (2.1.1)
dotenv (= 2.1.1)
railties (>= 4.0, < 5.1)
erubis (2.7.0) erubis (2.7.0)
execjs (2.6.0) execjs (2.6.0)
factory_girl (4.5.0) factory_girl (4.5.0)
@ -372,6 +376,11 @@ GEM
railties (~> 4.0) railties (~> 4.0)
rails-observers (0.1.2) rails-observers (0.1.2)
activemodel (~> 4.0) activemodel (~> 4.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.3)
railties (4.2.5.2) railties (4.2.5.2)
actionpack (= 4.2.5.2) actionpack (= 4.2.5.2)
activesupport (= 4.2.5.2) activesupport (= 4.2.5.2)
@ -539,6 +548,7 @@ DEPENDENCIES
delayed_job_active_record delayed_job_active_record
devise devise
devise_ichain_authenticatable devise_ichain_authenticatable
dotenv-rails
factory_girl_rails factory_girl_rails
font-awesome-rails font-awesome-rails
formtastic (~> 3.1.1) formtastic (~> 3.1.1)
@ -581,6 +591,7 @@ DEPENDENCIES
rails-assets-waypoints! rails-assets-waypoints!
rails-i18n (~> 4.0.0) rails-i18n (~> 4.0.0)
rails-observers rails-observers
rails_12factor
rdoc-generator-fivefish rdoc-generator-fivefish
redcarpet redcarpet
responders (~> 2.0) responders (~> 2.0)

View file

@ -5,7 +5,33 @@ base operating systems. [Check Google](https://encrypted.google.com/search?hl=en
For more information about rails and what it can do, see the [rails guides.](http://guides.rubyonrails.org/getting_started.html) For more information about rails and what it can do, see the [rails guides.](http://guides.rubyonrails.org/getting_started.html)
## Dependency for ImageMagick ## Configuring OSEM
There are a couple of environment variables you can set to configure OSEM.
| Variable | Content | Purpose |
|---------- |--------- |--------- |
| OSEM_NAME | openSUSE Events | The name of your page |
| OSEM_HOSTNAME | events.opensuse.org | The host this OSEM instance runs on |
| OSEM_EMAIL_ADDRESS | events@opensuse.org | The address OSEM uses for sending mails |
| OSEM_ICHAIN_ENABLED | true/false | Enable the usage of [devise_ichain_authenticatable](https://github.com/openSUSE/devise_ichain_authenticatable) |
| OSEM_TRANSIFEX_APIKEY | *string* | Use this api key for [transifex](https://www.transifex.com/). See TRANSLATION.md for details. |
| OSEM_ERRBIT_HOST | errbit.opensuse.org | The [errbit](https://github.com/errbit/errbit) host to post exceptions to |
| OSEM_ERRBIT_APIKEY | *string* | The api key for the errbit host |
| OSEM_FACTORY_LINT | *boolean* (true/false) | Setting this to false will disable linting of factories before running spec
| OSEM_GOOGLE_KEY/OSEM_GOOGLE_SECRET | *string* | OMNIAUTH Developer Keys/Secrets for GOOGLE
| OSEM_FACEBOOK_KEY/OSEM_FACEBOOK_SECRET | *string* | OMNIAUTH Developer Keys/Secrets for Facebook
| OSEM_GITHUB_KEY/OSEM_GITHUB_SECRET |*string* | OMNIAUTH Developer Keys/Secrets for GitHub
| OSEM_SMTP_ADDRESS | smtp.opensuse.org | The smtp server to use
| OSEM_SMTP_PORT | *int* | The port on the smtp server
| OSEM_SMTP_USERNAME | *string* | The user for the smtp server
| OSEM_SMTP_PASSWORD | *string* | The password for the smtp server
| OSEM_SMTP_AUTHENTICATION | plain, login or cram_md5 | The auth method for the smtp server
| OSEM_SMTP_DOMAIN | opensuse.org | The HELO domain for the smtp server
| CLOUDINARY_URL | *sting* | Configure your cloudinary.com cloud name and api key/secret
## Dependencies
### ImageMagick
We use [ImageMagick](http://imagemagick.org/) for image manipulation so it needs to be available in your installation. We use [ImageMagick](http://imagemagick.org/) for image manipulation so it needs to be available in your installation.
If you would like to resize exisiting logos in your OSEM installation you can do so by running the following rake task: If you would like to resize exisiting logos in your OSEM installation you can do so by running the following rake task:
@ -13,11 +39,11 @@ If you would like to resize exisiting logos in your OSEM installation you can do
$ bundle exec rake logo:reprocess $ bundle exec rake logo:reprocess
``` ```
## Using openID ### openID
In order to use [openID](http://openid.net/) logins for your OSEM installation you need to register your application with the providers ([Google](https://code.google.com/apis/console#:access), [GitHub](https://github.com/settings/applications/new) or [Facebook](https://developers.facebook.com/)) and enter their API keys in `config/secrets.yml` file, changing the existing sample values. In order to use [openID](http://openid.net/) logins for your OSEM installation you need to register your application with the providers ([Google](https://code.google.com/apis/console#:access), [GitHub](https://github.com/settings/applications/new) or [Facebook](https://developers.facebook.com/)) and enter their API keys in `config/secrets.yml` file, changing the existing sample values.
## Recurring Jobs ## Recurring Jobs
=======
Open a separate terminal and go into the directory where the rails app is present, and type the following to start the delayed_jobs worker for sending email notifications. Open a separate terminal and go into the directory where the rails app is present, and type the following to start the delayed_jobs worker for sending email notifications.
``` ```
bundle exec rake jobs:work bundle exec rake jobs:work

View file

@ -13,7 +13,7 @@ class ConferenceRegistrationsController < ApplicationController
redirect_to edit_conference_conference_registrations_path(@conference.short_title) redirect_to edit_conference_conference_registrations_path(@conference.short_title)
return return
# ichain does not allow us to create users during registration # ichain does not allow us to create users during registration
elsif CONFIG['authentication']['ichain']['enabled'] && !current_user elsif (ENV['OSEM_ICHAIN_ENABLED'] == 'true') && !current_user
redirect_to root_path, alert: 'You need to sign in or sign up before continuing.' redirect_to root_path, alert: 'You need to sign in or sign up before continuing.'
return return
end end

View file

@ -274,8 +274,10 @@ module ApplicationHelper
unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank? unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank?
providers << provider providers << provider
end end
providers << provider if !ENV["OSEM_#{provider.upcase}_KEY"].blank? && !ENV["OSEM_#{provider.upcase}_SECRET"].blank?
end end
return providers
return providers.uniq
end end
# Receives a hash, generated from User model, function get_roles # Receives a hash, generated from User model, function get_roles
@ -294,7 +296,7 @@ module ApplicationHelper
end end
def sign_in_path def sign_in_path
if CONFIG['authentication']['ichain']['enabled'] if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
new_user_ichain_session_path new_user_ichain_session_path
else else
new_user_session_path new_user_session_path
@ -302,7 +304,7 @@ module ApplicationHelper
end end
def sign_up_path def sign_up_path
if CONFIG['authentication']['ichain']['enabled'] if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
new_user_ichain_registration_path new_user_ichain_registration_path
else else
new_user_registration_path new_user_registration_path

View file

@ -45,7 +45,7 @@ class Ability
# can view Commercials of confirmed Events # can view Commercials of confirmed Events
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id) can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
can [:show, :create], User can [:show, :create], User
unless CONFIG['authentication']['ichain']['enabled'] unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
can :show, Registration do |registration| can :show, Registration do |registration|
registration.new_record? registration.new_record?
end end

View file

@ -9,12 +9,12 @@ class EmailSettings < ActiveRecord::Base
'conference_start_date' => conference.start_date, 'conference_start_date' => conference.start_date,
'conference_end_date' => conference.end_date, 'conference_end_date' => conference.end_date,
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registrations_url( 'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registrations_url(
conference.short_title, host: CONFIG['url_for_emails']), conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url( 'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
conference.short_title, host: CONFIG['url_for_emails']), conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
'schedule_link' => Rails.application.routes.url_helpers.schedule_conference_url( 'schedule_link' => Rails.application.routes.url_helpers.schedule_conference_url(
conference.short_title, host: CONFIG['url_for_emails']) conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
} }
if conference.program.cfp if conference.program.cfp
@ -41,7 +41,7 @@ class EmailSettings < ActiveRecord::Base
if event if event
h['eventtitle'] = event.title h['eventtitle'] = event.title
h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposal_index_url( h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposal_index_url(
conference.short_title, host: CONFIG['url_for_emails']) conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
end end
h h
end end

View file

@ -19,7 +19,7 @@ class User < ActiveRecord::Base
# :lockable, :timeoutable and :omniauthable # :lockable, :timeoutable and :omniauthable
devise_modules = [] devise_modules = []
if CONFIG['authentication']['ichain']['enabled'] if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
devise_modules += [ :ichain_authenticatable, :ichain_registerable, :omniauthable, omniauth_providers: [] ] devise_modules += [ :ichain_authenticatable, :ichain_registerable, :omniauthable, omniauth_providers: [] ]
else else
devise_modules += [:database_authenticatable, :registerable, devise_modules += [:database_authenticatable, :registerable,

View file

@ -11,7 +11,7 @@
%legend %legend
%span %span
=link_to('#signup', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do =link_to('#signup', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do
= CONFIG['name'] = ENV['OSEM_NAME'] || 'OSEM'
Account Account
%span.pull-right#account-already %span.pull-right#account-already
=link_to('#signin', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do =link_to('#signin', role: 'tab', "aria-controls" => "home", "data-toggle" => "tab") do

View file

@ -1,4 +1,4 @@
- if !CONFIG['authentication']['ichain']['enabled'] - if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
= form_tag(new_user_session_path, class: 'form-horizontal') do = form_tag(new_user_session_path, class: 'form-horizontal') do
%legend %legend
%span %span

View file

@ -7,7 +7,7 @@
%span.icon-bar %span.icon-bar
%span.icon-bar %span.icon-bar
%span.icon-bar %span.icon-bar
= link_to CONFIG['name'], root_path, class: 'navbar-brand', title: 'Open Source Event Manager' = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager'
.collapse.navbar-collapse .collapse.navbar-collapse
- if content_for :splash_nav - if content_for :splash_nav
%ul.nav.navbar-nav#splash-nav %ul.nav.navbar-nav#splash-nav
@ -43,7 +43,7 @@
%li= link_to 'See all Comments', admin_comments_path(anchor: 'all_comments') %li= link_to 'See all Comments', admin_comments_path(anchor: 'all_comments')
- else - else
%ul.nav.navbar-nav.navbar-right %ul.nav.navbar-nav.navbar-right
- if CONFIG['authentication']['ichain']['enabled'] - if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
%li{:class=> "#{active_nav_li(new_ichain_registration_path('user'))}"} %li{:class=> "#{active_nav_li(new_ichain_registration_path('user'))}"}
= link_to(new_ichain_registration_path('user')) do = link_to(new_ichain_registration_path('user')) do
%span.fa.fa-heart %span.fa.fa-heart
@ -59,7 +59,7 @@
Sign In Sign In
%span.caret %span.caret
.dropdown-menu{:style => "padding: 17px; min-width: 225px;"} .dropdown-menu{:style => "padding: 17px; min-width: 225px;"}
- if CONFIG['authentication']['ichain']['enabled'] - if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
= form_tag User.ichain_login_url do = form_tag User.ichain_login_url do
= text_field_tag 'username', nil, id: 'user_ichain_email_dd', placeholder: 'Username' = text_field_tag 'username', nil, id: 'user_ichain_email_dd', placeholder: 'Username'
= password_field_tag 'password', nil, id: 'user_ichain_password_dd', placeholder: 'Password' = password_field_tag 'password', nil, id: 'user_ichain_password_dd', placeholder: 'Password'

View file

@ -1,4 +1,4 @@
- unless CONFIG['authentication']['ichain']['enabled'] - unless ENV['OSEM_ICHAIN_ENABLED'] == 'true'
%li %li
= link_to(edit_user_registration_path) do = link_to(edit_user_registration_path) do
%span.fa.fa-wrench %span.fa.fa-wrench
@ -13,7 +13,7 @@
%span.fa.fa-comment %span.fa.fa-comment
My Submissions My Submissions
%li %li
- if CONFIG['authentication']['ichain']['enabled'] - if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
= link_to(destroy_user_ichain_session_path, :method=>'delete') do = link_to(destroy_user_ichain_session_path, :method=>'delete') do
%span.fa.fa-minus %span.fa.fa-minus
Sign out Sign out

View file

@ -2,7 +2,7 @@
%head %head
%meta{:charset => "utf-8"} %meta{:charset => "utf-8"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"} %meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
%title= content_for?(:title) ? yield(:title) : CONFIG['name'] %title= content_for?(:title) ? yield(:title) : (ENV['OSEM_NAME'] || 'OSEM')
%meta{:content => "", :name => "description"} %meta{:content => "", :name => "description"}
%meta{:content => "", :name => "author"} %meta{:content => "", :name => "author"}
= stylesheet_link_tag "application", :media => "all" = stylesheet_link_tag "application", :media => "all"
@ -11,7 +11,7 @@
= csrf_meta_tags = csrf_meta_tags
:javascript :javascript
window.liveSettings = { window.liveSettings = {
api_key: "#{CONFIG['transifex_live_api_key']}", api_key: "#{ENV['OSEM_TRANSIFEX_APIKEY']}",
picker: "bottom-right", picker: "bottom-right",
detectlang: true, detectlang: true,
autocollect: true autocollect: true

View file

@ -3,7 +3,7 @@
%head %head
%meta{:charset => "utf-8"} %meta{:charset => "utf-8"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"} %meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
%title= content_for?(:title) ? yield(:title) : CONFIG['name'] %title= content_for?(:title) ? yield(:title) : (ENV['OSEM_NAME'] || 'OSEM')
%meta{:content => "", :name => "description"} %meta{:content => "", :name => "description"}
%meta{:content => "", :name => "author"} %meta{:content => "", :name => "author"}
= stylesheet_link_tag "/stylesheets/schedule/jquery-ui-1.9.2.custom.min" = stylesheet_link_tag "/stylesheets/schedule/jquery-ui-1.9.2.custom.min"

View file

@ -12,7 +12,7 @@
%legend %legend
%span %span
=link_to('#signup', role: 'tab', 'aria-controls' => 'home', 'data-toggle' => 'tab') do =link_to('#signup', role: 'tab', 'aria-controls' => 'home', 'data-toggle' => 'tab') do
= CONFIG['name'] = ENV['OSEM_NAME'] || 'OSEM'
Account Account
%span.pull-right#account-already %span.pull-right#account-already
=link_to('#signin', role: 'tab', 'aria-controls' => 'home', 'data-toggle' => 'tab') do =link_to('#signin', role: 'tab', 'aria-controls' => 'home', 'data-toggle' => 'tab') do

View file

@ -15,24 +15,6 @@ gem install bundler
echo -e "\ninstalling your bundle...\n" echo -e "\ninstalling your bundle...\n"
su - vagrant -c "cd /vagrant/; bundle install --quiet" su - vagrant -c "cd /vagrant/; bundle install --quiet"
# Configure the app if it isn't
if [ ! -f /vagrant/config/config.yml ] && [ -f /vagrant/config/config.yml.example ]; then
echo "Configuring your app in config/options.yml..."
cp config/config.yml.example config/config.yml
else
echo -e "\n\nWARNING: You have already configured your app in config/options.yml."
echo -e "WARNING: Please make sure this configuration works in this vagrant box!\n\n"
fi
# Configure the app if it isn't
if [ ! -f /vagrant/config/secrets.yml ] && [ -f /vagrant/config/secrets.yml.example ]; then
echo "Configuring your secrets in config/secrets.yml..."
cp config/secrets.yml.example config/secrets.yml
else
echo -e "\n\nWARNING: You have already configured your secrets in config/secrets.yml."
echo -e "WARNING: Please make sure this configuration works in this vagrant box!\n\n"
fi
# Configure the database if it isn't # Configure the database if it isn't
if [ ! -f /vagrant/config/database.yml ] && [ -f /vagrant/config/database.yml.example ]; then if [ ! -f /vagrant/config/database.yml ] && [ -f /vagrant/config/database.yml.example ]; then
echo -e "\nSetting up your database from config/database.yml...\n" echo -e "\nSetting up your database from config/database.yml...\n"

View file

@ -1,41 +0,0 @@
defaults: &defaults
# The name of your instance
name: OSEM
# The sender address of emails
sender_for_emails: "no-reply@localhost"
# The hostname to be used when building the URL in the emails
url_for_emails: "localhost:3000"
# errbit configuration, get your own instance: https://github.com/errbit/errbit
#errbit_key: See config/secrets.yml
#errbit_host: errbit.exmaple.com
# These are the currently supported commercial types for conference and events
# If you want to use iChain to handle registration and authentication enable the next lines
authentication:
ichain:
enabled: false
# Set it to false if you don't want FactoryGirl lint to run before every test suit.
# You can run lint manually with: bundle exec rake factory_girl:lint
factory_girl_lint: true
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
# If you add more providers that do not require a key, you still have to create the 2 variables with sample data
transifex_live_api_key: ''
# Set the smtp configuration of your service provider
# For further details of each configuration checkout: http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
mail_address: 'smtp.host.com'
mail_port: 587
mail_username: 'username@host.com'
mail_password: 'password'
mail_authentication: 'plain'

View file

@ -10,7 +10,7 @@ set :repository, 'https://github.com/openSUSE/osem.git'
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server. # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step. # They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, %w{ config/database.yml log public/system config/secrets.yml config/config.yml config/piwik.yml tmp} set :shared_paths, %w{ config/database.yml log public/system config/secrets.yml config/piwik.yml tmp}
task setup: :environment do task setup: :environment do
queue! %[mkdir -p "#{deploy_to}/shared/log"] queue! %[mkdir -p "#{deploy_to}/shared/log"]

View file

@ -3,11 +3,18 @@ require File.expand_path('../application', __FILE__)
# Load the configuration file # Load the configuration file
path = Rails.root.join('config', 'config.yml') path = Rails.root.join('config', 'config.yml')
begin if File.exist?(path)
CONFIG = YAML.load_file(path)[Rails.env] puts "
rescue
puts "Error while parsing config file #{path}" WARNING: The OSEM configuration file
CONFIG = {}
#{path}
is deprecated. Please use the environment variables
explained in INSTALL.md instead.
"
end end
# Initialize the rails application # Initialize the rails application

View file

@ -35,7 +35,10 @@ Osem::Application.configure do
config.eager_load = false config.eager_load = false
# Set the detault url for action mailer # Set the detault url for action mailer
config.action_mailer.default_url_options = { host: CONFIG['url_for_emails'] } config.action_mailer.default_url_options = { host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000') }
# Set the secret key base if it's not set via other means
config.secret_key_base ||= 'f4be765bc98e516de82ac01daa8f8aa11c5ca13cb6c911887851ac89457b6c0b056b2361a21b5c08926c9386e0f91eef84fc0b103d522bf00bc0c78ea8ce7c58'
# Use omniauth mock credentials # Use omniauth mock credentials
OmniAuth.config.test_mode = true OmniAuth.config.test_mode = true

View file

@ -67,15 +67,20 @@ Osem::Application.configure do
config.active_support.deprecation = :notify config.active_support.deprecation = :notify
# Set the detault url for action mailer # Set the detault url for action mailer
config.action_mailer.default_url_options = { host: CONFIG['url_for_emails'] } config.action_mailer.default_url_options = { host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000') }
# Set the smtp configuration of your service provider # Set the smtp configuration of your service provider
# For further details of each configuration checkout: http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration # For further details of each configuration checkout: http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: CONFIG['MAIL_ADDRESS'], address: ENV['OSEM_SMTP_ADDRESS'],
port: CONFIG['MAIL_PORT'], port: ENV['OSEM_SMTP_PORT'],
user_name: CONFIG['MAIL_USERNAME'], user_name: ENV['OSEM_SMTP_USERNAME'],
password: CONFIG['MAIL_PASSWORD'], password: ENV['OSEM_SMTP_PASSWORD'],
authentication: CONFIG['MAIL_AUTHENTICATION'] authentication: ENV['OSEM_SMTP_AUTHENTICATION'].try(:to_sym),
domain: ENV['OSEM_SMTP_DOMAIN'],
enable_starttls_auto: true
} }
# Set the secret_key_base from the env, if not set by any other means
config.secret_key_base ||= ENV["SECRET_KEY_BASE"]
end end

View file

@ -41,6 +41,9 @@ Osem::Application.configure do
# Do not perform deliveries on test # Do not perform deliveries on test
config.action_mailer.perform_deliveries = false config.action_mailer.perform_deliveries = false
# Set the secret key base if it's not set via other means
config.secret_key_base ||= 'f4be765bc98e516de82ac01daa8f8aa11c5ca13cb6c911887851ac89457b6c0b056b2361a21b5c08926c9386e0f91eef84fc0b103d522bf00bc0c78ea8ce7c58'
config.after_initialize do config.after_initialize do
ActiveRecord::Base.logger = nil ActiveRecord::Base.logger = nil
# Set Time.now to May 1, 2014 00:01:00 AM (at this instant), but allow it to move forward # Set Time.now to May 1, 2014 00:01:00 AM (at this instant), but allow it to move forward

View file

@ -2,24 +2,21 @@
# Many of these configuration options can be set straight in your model. # Many of these configuration options can be set straight in your model.
Devise.setup do |config| Devise.setup do |config|
# ==> Secret key, generate one with `rake secret`
config.secret_key = Rails.application.secrets.devise_secret_key
# ==> openIDs configuration # ==> openIDs configuration
# Define the available openID providers that can be used to log in # Define the available openID providers that can be used to log in
# Pass each provider to User model in :omniauth_providers (for open_id providers use their name) # Pass each provider to User model in :omniauth_providers (for open_id providers use their name)
config.omniauth :open_id, name: 'suse', identifier: 'http://www.opensuse.org/openid/user' config.omniauth :open_id, name: 'suse', identifier: 'http://www.opensuse.org/openid/user'
config.omniauth :google_oauth2, Rails.application.secrets.google_key, Rails.application.secrets.google_secret, config.omniauth :google_oauth2, (ENV['OSEM_GOOGLE_KEY'] || Rails.application.secrets.google_key), (ENV['OSEM_GOOGLE_SECRET'] || Rails.application.secrets.google_secret),
name: 'google', name: 'google',
scope: 'email' scope: 'email'
config.omniauth :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret config.omniauth :facebook, (ENV['OSEM_FACEBOOK_KEY'] || Rails.application.secrets.facebook_key), (ENV['OSEM_FACEBOOK_SECRET'] || Rails.application.secrets.facebook_secret)
config.omniauth :github, Rails.application.secrets.github_key, Rails.application.secrets.github_secret config.omniauth :github, (ENV['OSEM_GITHUB_KEY'] || Rails.application.secrets.github_key), (ENV['OSEM_GITHUB_SECRET'] || Rails.application.secrets.github_secret)
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter. # note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = CONFIG['sender_for_emails'] config.mailer_sender = ENV['OSEM_EMAIL_ADDRESS'] || 'no-reply@localhost'
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer" # config.mailer = "Devise::Mailer"

View file

@ -1,7 +1,7 @@
HoptoadNotifier.configure do |config| HoptoadNotifier.configure do |config|
# Change this to some sensible data for your errbit instance # Change this to some sensible data for your errbit instance
config.api_key = Rails.application.secrets.errbit_key || '' config.api_key = ENV['OSEM_ERRBIT_APIKEY'] || Rails.application.secrets.errbit_key || ''
config.host = Rails.application.secrets.errbit_host || '' config.host = ENV['OSEM_ERRBIT_HOST']
if config.api_key.blank? || config.host.blank? if config.api_key.blank? || config.host.blank?
config.development_environments = 'production development test' config.development_environments = 'production development test'
else else

View file

@ -1,6 +1,6 @@
Osem::Application.routes.draw do Osem::Application.routes.draw do
if CONFIG['authentication']['ichain']['enabled'] if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
devise_for :users, controllers: { registrations: :registrations } devise_for :users, controllers: { registrations: :registrations }
else else
devise_for :users, devise_for :users,

View file

@ -1,18 +1,9 @@
defaults: &defaults
# You can generate secret keys with 'rake secret'
# For rails cookies
secret_key_base: '12345'
# For devise login tokens
devise_secret_key: '12345'
# Your errbit API key
# errbit_key: '12345'
development: development:
<<: *defaults # Generate your own with rake secret
# Sample data so that mocks work # secret_key_base: '12345'
########## OMNIAUTH Providers ##########
# This is just sample data so mocks work
google_key: 'sample' google_key: 'sample'
google_secret: 'sample' google_secret: 'sample'
@ -23,33 +14,45 @@ development:
suse_secret: 'sample' suse_secret: 'sample'
test: test:
<<: *defaults # Generate your own with rake secret
# secret_key_base: '12345'
production: production:
<<: *defaults # Generate your own with rake secret or use the environment
# Leave the variables' names empty, unless you use the providers, in which case you need to # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
# register your applicaton and add the actual keys.
# If you add more providers, keep the format of the variables: provider_key, provider_secret # Your errbit API key
# errbit_key: '12345'
# Register your appllication with Google from https://code.google.com/apis/console#:access ########## OMNIAUTH Providers ##########
# Leave the variables' names empty, unless you use the providers, in which
# case you need to register your applicaton and add the actual keys.
#
# If you add a provider, keep the format of the variables:
# *provider*_key and *provider*_secret
# If you add a provider that does not require a key, you still have to
# create the 2 variables with sample data or they won't show up in the app.
# Register your appllication with Google from
# https://code.google.com/apis/console#:access
google_key: '' google_key: ''
google_secret: '' google_secret: ''
# Register your application with Facebook from https://developers.facebook.com/ # Register your application with Facebook from
# https://developers.facebook.com/
facebook_key: '' facebook_key: ''
facebook_secret: '' facebook_secret: ''
# Developers do not need to register their application for suse account to work. # Developers do not need to register their application for suse account to
# You must, however, add some sample value to the variables, for the login option to appear. # work. You must, however, add some sample value to the variables, for the
# For example: # login option to appear. For example:
#suse_key: 'sample data' #suse_key: 'sample data'
#suse_secret: 'sample data' #suse_secret: 'sample data'
suse_key: '' suse_key: ''
suse_secret: '' suse_secret: ''
# Register your application with GitHub from https://github.com/settings/applications # Register your application with GitHub from
# https://github.com/settings/applications
github_key: '' github_key: ''
github_secret: '' github_secret: ''
# If you add more providers that do not require a key, you still have to create the 2 variables with sample data

54
dotenv.example Normal file
View file

@ -0,0 +1,54 @@
# Set environment variables for OSEM in this file
# and copy it to .env or .env.rails_environment
# (like env.production or env.development)
#
# The following is a list of variables and default
# values that OSEM uses to configure some aspects
# of the app
# The name of your page
OSEM_NAME="OSEM"
# The host this OSEM instance runs on. Used for
# generating urls in emails sent
OSEM_HOSTNAME="localhost:3000"
# The address OSEM uses for sending mails
OSEM_EMAIL_ADDRESS="no-reply@localhost"
# The api key for transifex.com.
# See TRANSLATION.md for details
OSEM_TRANSIFEX_APIKEY=""
# The errbit host to post exceptions to
OSEM_ERRBIT_HOST=""
# The api key for the errbit host
OSEM_ERRBIT_APIKEY=""
# OMNIAUTH Developer Key/Secret for GOOGLE
OSEM_GOOGLE_KEY=''
OSEM_GOOGLE_SECRET=''
# OMNIAUTH Developer Key/Secret for Facebook
OSEM_FACEBOOK_KEY=''
OSEM_FACEBOOK_SECRET=''
# OMNIAUTH Developer Key/Secret for GitHub
OSEM_GITHUB_KEY=''
OSEM_GITHUB_SECRET=''
# Disable linting of factories in the test suite.
# Speeds up turn around times of tests
OSEM_FACTORY_LINT="false"
# The smtp configuration. See the rails guides for more
# http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
OSEM_SMTP_ADDRESS=""
OSEM_SMTP_PORT=""
OSEM_SMTP_USERNAME=""
OSEM_SMTP_PASSWORD=""
OSEM_SMTP_AUTHENTICATION=""
OSEM_SMTP_DOMAIN=""
# Enable the usage of the devise ichain plugin
OSEM_ICHAIN_ENABLED=false

View file

@ -0,0 +1,41 @@
namespace :data do
namespace :migrate do
desc 'Create a dotenv file from config/config.yml'
task config2dotenv: :environment do
# Create the dotenv file
dot_env = Rails.root.join(".env.#{Rails.env}")
if File.exist?(dot_env)
abort("Sorry can't migrate, #{dot_env} already exists")
else
dot_env = File.open(dot_env, 'w')
end
# Load the configuration file
config_yml = Rails.root.join('config', 'config.yml')
begin
CONFIG = YAML.load_file(config_yml)[Rails.env]
rescue
CONFIG = {}
end
# Write the dotenv file
dot_env.puts '# OSEM environment variables. Check INSTALL.md for more information'
dot_env.puts "OSEM_NAME=\"#{CONFIG['name']}\""
dot_env.puts "OSEM_HOSTNAME=\"#{CONFIG['url_for_emails']}\""
dot_env.puts "OSEM_EMAIL_ADDRESS=\"#{CONFIG['sender_for_emails']}\""
dot_env.puts "OSEM_ICHAIN_ENABLED=\"#{CONFIG['authentication']['ichain']['enabled']}\"" if CONFIG.has_key?(:authentication)
dot_env.puts "OSEM_TRANSIFEX_APIKEY=\"#{CONFIG['transifex_live_api_key']}\""
dot_env.puts "OSEM_ERRBIT_HOST=\"#{CONFIG['errbit_host']}\""
dot_env.puts "OSEM_FACTORY_LINT=\"#{CONFIG['factory_girl_lint']}\""
dot_env.puts "OSEM_SMTP_ADDRESS=\"#{CONFIG['mail_address']}\""
dot_env.puts "OSEM_SMTP_PORT=\"#{CONFIG['mail_port']}\""
dot_env.puts "OSEM_SMTP_USERNAME=\"#{CONFIG['mail_username']}\""
dot_env.puts "OSEM_SMTP_PASSWORD=\"#{CONFIG['mail_password']}\""
dot_env.puts "OSEM_SMTP_AUTHENTICATION=\"#{CONFIG['mail_authentication']}\""
dot_env.puts 'OSEM_SMTP_DOMAIN=""'
dot_env.close
puts "Migrated config/config.yml to .env.#{Rails.env}"
end
end
end

View file

@ -3,7 +3,7 @@ require_relative 'external_request'
RSpec.configure do |config| RSpec.configure do |config|
config.before(:suite) do config.before(:suite) do
if CONFIG['factory_girl_lint'] if ENV['OSEM_FACTORY_LINT'] != 'false'
mock_commercial_request mock_commercial_request
FactoryGirl.lint FactoryGirl.lint
end end