diff --git a/Gemfile.lock b/Gemfile.lock index 0b8762ffb28faf4afff0c361a22a3d1e63aa2405..e2c3650415ef3f51c026db37f44c499ab3ed194b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,27 +65,27 @@ GEM annotate (3.1.1) activerecord (>= 3.2, < 7.0) rake (>= 10.4, < 14.0) - autoprefixer-rails (10.2.5.1) - execjs (> 0) + autoprefixer-rails (10.3.1.0) + execjs (~> 2) aws-eventstream (1.1.1) - aws-partitions (1.478.0) - aws-sdk-core (3.117.0) + aws-partitions (1.484.0) + aws-sdk-core (3.119.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.44.0) - aws-sdk-core (~> 3, >= 3.112.0) + aws-sdk-kms (1.46.0) + aws-sdk-core (~> 3, >= 3.119.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.96.1) - aws-sdk-core (~> 3, >= 3.112.0) + aws-sdk-s3 (1.98.0) + aws-sdk-core (~> 3, >= 3.119.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) aws-sigv4 (1.2.4) aws-eventstream (~> 1, >= 1.0.2) bcrypt (3.1.16) bindex (0.8.1) - bootsnap (1.7.5) + bootsnap (1.7.7) msgpack (~> 1.0) bootstrap (5.0.1) autoprefixer-rails (>= 9.1.0) @@ -106,7 +106,7 @@ GEM xpath (~> 3.2) childprocess (3.0.0) concurrent-ruby (1.1.9) - countries (4.0.0) + countries (4.0.1) i18n_data (~> 0.13.0) sixarm_ruby_unaccent (~> 1.1) country_select (6.0.0) @@ -138,8 +138,8 @@ GEM erubi (1.10.0) execjs (2.8.1) ffi (1.15.3) - globalid (0.4.2) - activesupport (>= 4.2.0) + globalid (0.5.2) + activesupport (>= 5.0) i18n (1.8.10) concurrent-ruby (~> 1.0) i18n_data (0.13.0) @@ -168,10 +168,10 @@ GEM activerecord kaminari-core (= 1.2.1) kaminari-core (1.2.1) - listen (3.5.1) + listen (3.6.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.10.0) + loofah (2.11.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -180,20 +180,20 @@ GEM method_source (1.0.0) mini_magick (4.11.0) mini_mime (1.1.0) - mini_portile2 (2.5.3) + mini_portile2 (2.6.1) minitest (5.14.4) msgpack (1.4.2) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nio4r (2.5.7) - nokogiri (1.11.7) - mini_portile2 (~> 2.5.0) + nio4r (2.5.8) + nokogiri (1.12.2) + mini_portile2 (~> 2.6.1) racc (~> 1.4) orm_adapter (0.5.0) pg (1.2.3) popper_js (2.9.2) public_suffix (4.0.6) - puma (5.3.2) + puma (5.4.0) nio4r (~> 2.0) racc (1.5.2) rack (2.2.3) diff --git a/app/controllers/admin/universities_controller.rb b/app/controllers/admin/universities_controller.rb index 65247b343a648b2e6af24498dc07f0e63deac7ed..e34d9f1cdb18eec7e1176e0e24a266f4d21b4318 100644 --- a/app/controllers/admin/universities_controller.rb +++ b/app/controllers/admin/universities_controller.rb @@ -67,6 +67,6 @@ class Admin::UniversitiesController < Admin::ApplicationController end def university_params - params.require(:university).permit(:name, :address, :zipcode, :city, :country, :private) + params.require(:university).permit(:name, :address, :zipcode, :city, :country, :private, :identifier) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12ab4dfe301535a973e2607fad4efc9d0d..5de4f5fd2a890cf4aeaf91ae734877cdce2de180 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,3 @@ class ApplicationController < ActionController::Base + include WithUniversity end diff --git a/app/controllers/application_controller/with_university.rb b/app/controllers/application_controller/with_university.rb new file mode 100644 index 0000000000000000000000000000000000000000..e8a48d38fccb327e47da7091eb3f75637ffd8f0f --- /dev/null +++ b/app/controllers/application_controller/with_university.rb @@ -0,0 +1,12 @@ +module ApplicationController::WithUniversity + extend ActiveSupport::Concern + + included do + + def current_university + @current_university ||= University.with_host(request.host) + end + helper_method :current_university + + end +end diff --git a/app/models/university.rb b/app/models/university.rb index e3b0f1b206ee52e1fa57e81b689e45fb1ed847db..46e65f75994261895346bb7164967ac31a416f13 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -6,6 +6,7 @@ # address :string # city :string # country :string +# identifier :string # name :string # private :boolean # zipcode :string @@ -16,6 +17,8 @@ class University < ApplicationRecord validates_presence_of :name + include WithIdentifier + def to_s "#{name}" end diff --git a/app/models/university/with_identifier.rb b/app/models/university/with_identifier.rb new file mode 100644 index 0000000000000000000000000000000000000000..d7d92f37c150e5c022a10ce8f619b08beca313db --- /dev/null +++ b/app/models/university/with_identifier.rb @@ -0,0 +1,37 @@ +module University::WithIdentifier + extend ActiveSupport::Concern + + included do + # todo lower case, numbers, -, _ + validates :identifier, presence: true, uniqueness: true + end + + class_methods do + def with_host(host) + find_by(identifier: extract_identifier_from(host)) || first + end + + private + + # University direct urls (not through website) + # Production osuny.osuny.org -> osuny + # Staging osuny.osuny.dev -> osuny + # Dev osuny.osuny -> osuny + def extract_identifier_from(host) + host.remove('.osuny.org') + .remove('.osuny.dev') + .remove('.osuny') + end + end + + def domain_url + case Rails.env + when 'development' + "http://#{identifier}.osuny:3000" + when 'staging' + "https://#{identifier}.osuny.dev" + when 'production' + "https://#{identifier}.osuny.org" + end + end +end diff --git a/app/views/admin/universities/_form.html.erb b/app/views/admin/universities/_form.html.erb index 4668cb803fdce3a9c51097f63e905931474c63b3..67ed4f997db3a685486a98e953dc83ef9cf0f7bc 100644 --- a/app/views/admin/universities/_form.html.erb +++ b/app/views/admin/universities/_form.html.erb @@ -2,6 +2,7 @@ <div class="row"> <div class="col-md-4"> <%= f.input :name %> + <%= f.input :identifier %> <%= f.input :private %> </div> <div class="col-md-8"> diff --git a/app/views/admin/universities/index.html.erb b/app/views/admin/universities/index.html.erb index 5c879055b1eb8c6266adaebde0388f6c06f6139f..3c90b98cd7db75e0f46ecc1bd46dececbba959be 100644 --- a/app/views/admin/universities/index.html.erb +++ b/app/views/admin/universities/index.html.erb @@ -4,10 +4,7 @@ <thead> <tr> <th><%= University.human_attribute_name('name') %></th> - <th><%= University.human_attribute_name('address') %></th> - <th><%= University.human_attribute_name('zipcode') %></th> - <th><%= University.human_attribute_name('city') %></th> - <th><%= University.human_attribute_name('country') %></th> + <th><%= University.human_attribute_name('url') %></th> <th><%= University.human_attribute_name('private') %></th> <th></th> </tr> @@ -16,10 +13,7 @@ <% @universities.each do |university| %> <tr> <td><%= link_to university, [:admin, university] %></td> - <td><%= university.address %></td> - <td><%= university.zipcode %></td> - <td><%= university.city %></td> - <td><%= university.country %></td> + <td><%= link_to university.domain_url, university.domain_url, target: :_blank %></td> <td><%= university.private %></td> <td class="text-end"> <%= edit_link university %> diff --git a/app/views/admin/universities/show.html.erb b/app/views/admin/universities/show.html.erb index 7499baeeb6aa36b16b3bd10ce41e431b6cd61c03..cfae6603abc0a1c7cabf3a2f90d563f7d5f72ad2 100644 --- a/app/views/admin/universities/show.html.erb +++ b/app/views/admin/universities/show.html.erb @@ -1,5 +1,9 @@ <% content_for :title, @university %> +<p> + <%= link_to @university.domain_url, @university.domain_url, target: :_blank %> +</p> + <p> <strong>Address:</strong> <%= @university.address %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a96a2eccd09f92bae5baf4e90bf8ef5e25cfff22..6d36784695f3ea278499ea856aaca16258f84d08 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,9 @@ <%= javascript_include_tag 'application' %> </head> <body> + <nav> + <%= current_university %> + </nav> <%= yield %> </body> </html> diff --git a/config/environments/development.rb b/config/environments/development.rb index dde01b42d759724915977d0369977fe187672038..883c18c4d078b98be7553bfc77c7b60065bdf0e5 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,6 +14,8 @@ Rails.application.configure do # Show full error reports. config.consider_all_requests_local = true + config.hosts.clear + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? diff --git a/db/migrate/20210809084645_add_identifier_to_university.rb b/db/migrate/20210809084645_add_identifier_to_university.rb new file mode 100644 index 0000000000000000000000000000000000000000..149203d29713bf7e84061c899d3a0911da33d895 --- /dev/null +++ b/db/migrate/20210809084645_add_identifier_to_university.rb @@ -0,0 +1,5 @@ +class AddIdentifierToUniversity < ActiveRecord::Migration[6.1] + def change + add_column :universities, :identifier, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 56de58cc5fc65ad8c54016722a9b00184a64d046..03c04b4c69f1d956d5e77e2ac9ff6c38ef4f3dd4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_07_08_122519) do +ActiveRecord::Schema.define(version: 2021_08_09_084645) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -68,6 +68,7 @@ ActiveRecord::Schema.define(version: 2021_07_08_122519) do t.boolean "private" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "identifier" end create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/docs/dev/setup.md b/docs/dev/setup.md new file mode 100644 index 0000000000000000000000000000000000000000..f6ad7c78513247797d48871c48376e83898fb32f --- /dev/null +++ b/docs/dev/setup.md @@ -0,0 +1,31 @@ +# Setup + +As Osuny is multi-university, we need ways to: +- deploy university to production (even without website yet) +- deploy university to staging +- work locally on a specific university + +And as each university is multi-website, we need ways to: +- deploy website to production +- deploy website to staging +- work locally on a specific website + +## Production + +## Staging + +## Dev + +The solution is to set up a host. + +/etc/hosts +``` +127.0.0.1 osuny.osuny +127.0.0.1 bordeauxmontaigne.osuny +127.0.0.1 clermontferrand.osuny +``` + +Then we have access on: +- http://osuny.osuny:3000 +- http://bordeauxmontaigne.osuny:3000 +- http://clermontferrand.osuny:3000 diff --git a/test/fixtures/qualiopi/criterions.yml b/test/fixtures/qualiopi/criterions.yml index f005e9e6d300a98905bc34b574f4d236ef4eef9c..c058191c9ef25096c88e191ada347bc7fe26890c 100644 --- a/test/fixtures/qualiopi/criterions.yml +++ b/test/fixtures/qualiopi/criterions.yml @@ -9,7 +9,6 @@ # created_at :datetime not null # updated_at :datetime not null # -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: number: 1 diff --git a/test/fixtures/qualiopi/indicators.yml b/test/fixtures/qualiopi/indicators.yml index 246a86a4a59bd3f40c47a56d9aee4f191e97e52d..b5e384387ec8b3d7d06679ab148345f23646658e 100644 --- a/test/fixtures/qualiopi/indicators.yml +++ b/test/fixtures/qualiopi/indicators.yml @@ -21,7 +21,6 @@ # # fk_rails_... (criterion_id => qualiopi_criterions.id) # -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: criterion: one diff --git a/test/fixtures/universities.yml b/test/fixtures/universities.yml index 6ea0463396c9387ef0687f252b8b72bc1b6dbfc2..60abd2d59105a5d07d8b720cf570512bc146dc06 100644 --- a/test/fixtures/universities.yml +++ b/test/fixtures/universities.yml @@ -6,6 +6,7 @@ # address :string # city :string # country :string +# identifier :string # name :string # private :boolean # zipcode :string diff --git a/test/models/university_test.rb b/test/models/university_test.rb index 6627ba937f9c555c7524128f709f4b88bd74678d..1960b952e31332a69aeb5e671fcc50fcfdf8b94d 100644 --- a/test/models/university_test.rb +++ b/test/models/university_test.rb @@ -6,6 +6,7 @@ # address :string # city :string # country :string +# identifier :string # name :string # private :boolean # zipcode :string