Skip to content
Snippets Groups Projects
Commit 768dbda4 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Extranet domains

parent be8a44e1
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,6 @@ class Admin::Communication::ExtranetsController < Admin::Communication::Applicat ...@@ -55,6 +55,6 @@ class Admin::Communication::ExtranetsController < Admin::Communication::Applicat
def extranet_params def extranet_params
params.require(:communication_extranet) params.require(:communication_extranet)
.permit(:name, :domain) .permit(:name, :domain, :logo, :logo_delete)
end end
end end
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include WithErrors include WithErrors
include WithLocale include WithLocale
include WithUniversity include WithDomain
def breadcrumb def breadcrumb
add_breadcrumb t('home'), root_path add_breadcrumb t('home'), root_path
......
module ApplicationController::WithDomain
extend ActiveSupport::Concern
included do
def current_extranet
@current_extranet ||= Communication::Extranet.with_host(request.host)
end
helper_method :current_extranet
def current_university
@current_university ||= begin
current_extranet.present? ? current_extranet.university
: University.with_host(request.host)
end
end
helper_method :current_university
def current_context
@current_context ||= begin
# Take the extranet as a context
context = current_extranet
# If no extranet, university becomes the context
context ||= current_university
# Return context, might be nil if neither extranet nor university
context
end
end
helper_method :current_context
end
end
module ApplicationController::WithUniversity
extend ActiveSupport::Concern
included do
# Raises ActiveRecord::RecordNotFound to prevent access from non-listed hosts
def current_university
@current_university ||= University.with_host(request.host)
end
helper_method :current_university
end
end
...@@ -22,6 +22,12 @@ class Communication::Extranet < ApplicationRecord ...@@ -22,6 +22,12 @@ class Communication::Extranet < ApplicationRecord
validates_presence_of :name, :domain validates_presence_of :name, :domain
has_one_attached_deletable :logo
def self.with_host(host)
find_by domain: host
end
def url def url
"https://#{domain}" "https://#{domain}"
end end
......
...@@ -14,7 +14,7 @@ module University::WithIdentifier ...@@ -14,7 +14,7 @@ module University::WithIdentifier
end end
def self.with_host(host) def self.with_host(host)
find_by!(identifier: extract_identifier_from(host)) find_by identifier: extract_identifier_from(host)
end end
private private
......
...@@ -8,6 +8,22 @@ ...@@ -8,6 +8,22 @@
<div class="card-body"> <div class="card-body">
<%= f.input :name %> <%= f.input :name %>
<%= f.input :domain %> <%= f.input :domain %>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= t('logo') %></h5>
</div>
<div class="card-body">
<%= f.input :logo,
as: :single_deletable_file,
input_html: { accept: '.jpg,.jpeg,.png,.svg' },
preview: 200,
direct_upload: true %>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
<div class="col-sm-10 mx-auto"> <div class="col-sm-10 mx-auto">
<h1 class="my-5 py-5 text-center"> <h1 class="my-5 py-5 text-center">
<%= link_to root_path do %> <%= link_to root_path do %>
<% if current_university.logo.attached? %> <% if current_context.logo.attached? %>
<%= image_tag current_university.logo, width: 200, alt: current_university.to_s %> <%= image_tag current_context.logo, width: 200, alt: current_context.to_s %>
<% else %> <% else %>
<%= current_university %> <%= current_context %>
<% end %> <% end %>
<% end %> <% end %>
</h1> </h1>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment