-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from etalab/features/subdomain
Enable subdomain restrictions on app
- Loading branch information
Showing
23 changed files
with
217 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,17 @@ Then go to [http://localhost:3000](http://localhost:3000) | |
|
||
For mailer preview: [http://localhost:3000/rails/mailers](http://localhost:3000/rails/mailers) | ||
|
||
### Avec un sous-domaine référencé | ||
|
||
Il est possible de restreindre l'application à un sous-ensemble de type | ||
d'habilitation à travers un sous nom de domaine. Cela permet de restreindre les | ||
demandeurs à ce sous-ensemble. | ||
|
||
Par exemple pour API Entreprise: [http://api-entreprise.localtest.me:3000/](http://api-entreprise.localtest.me:3000/) | ||
|
||
Il est possible de bypass le login via MonComptePro de cette manière en local : | ||
[http://api-entreprise.localtest.me:3000/[email protected]](http://api-entreprise.localtest.me:3000/[email protected]) | ||
|
||
## Tests | ||
|
||
With docker: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module SubdomainsHelper | ||
delegate :host, to: :request | ||
|
||
def registered_subdomain | ||
Subdomain.find(app_subdomain) | ||
rescue ActiveRecord::RecordNotFound | ||
nil | ||
end | ||
|
||
def registered_subdomain? | ||
registered_subdomain.present? | ||
end | ||
|
||
def app_subdomain | ||
case Rails.env | ||
when 'development', 'test' | ||
host.split('.').first | ||
when 'sandbox', 'staging' | ||
host.split('.')[1] | ||
when 'production' | ||
top_level, second_level = host.split('.')[0..1] | ||
|
||
if top_level.start_with?('production') | ||
second_level | ||
else | ||
top_level | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Subdomain < StaticApplicationRecord | ||
attr_accessor :id, | ||
:name, | ||
:title, | ||
:tagline, | ||
:authorization_definitions | ||
|
||
def self.all | ||
Rails.application.config_for(:subdomains).map do |uid, hash| | ||
build(uid, hash) | ||
end | ||
end | ||
|
||
def self.build(uid, hash) | ||
new( | ||
hash.slice( | ||
:name, | ||
:title, | ||
:tagline, | ||
).merge( | ||
id: uid.to_s, | ||
authorization_definitions: AuthorizationDefinition.where(id: hash[:authorization_definition_ids]), | ||
) | ||
) | ||
end | ||
|
||
def authorization_request_types | ||
authorization_definitions.map(&:authorization_request_class).flatten.uniq.map(&:to_s) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class APIEntrepriseNotifier < ApplicationNotifier | ||
AuthorizationRequest.state_machine.states.each do |state| | ||
# rubocop:disable Lint/EmptyBlock | ||
define_method(state.name) do |_params| | ||
end | ||
# rubocop:enable Lint/EmptyBlock | ||
end | ||
|
||
def submitted(_params) | ||
Instruction::AuthorizationRequestMailer.with( | ||
authorization_request: | ||
).submitted.deliver_later | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class UserContext | ||
attr_reader :user, :host | ||
|
||
def initialize(user, host = nil) | ||
@user = user | ||
@host = host | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
shared: | ||
api-entreprise: | ||
name: 'API Entreprise' | ||
title: 'DataPass - API Entreprise' | ||
tagline: 'Habilitations juridiques pour API Entreprise' | ||
authorization_definition_ids: | ||
- 'api_entreprise' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# language: fr | ||
|
||
Fonctionnalité: Tableau de bord pour un sous-domaine spécifique | ||
Cette page est la page principale de l'utilisateur, où il peut voir les diverses actions | ||
qu'il doit effectuer. Cette version du tableau de bord est restreinte à un sous-ensemble d'habilitations | ||
régie par le sous-domaine | ||
|
||
Contexte: | ||
Sachant que je suis un demandeur | ||
Et que je consulte le site ayant le sous-domaine "api-entreprise" | ||
Et que je me connecte | ||
|
||
Scénario: Je vois sur l'écran principal l'ensemble de mes habilitations uniquement lié au sous-domaine, quelque soit leur état | ||
Quand j'ai 1 demande d'habilitation "API Entreprise" en brouillon | ||
Et j'ai 1 demande d'habilitation "API Entreprise" en attente | ||
Et j'ai 1 demande d'habilitation "API Entreprise" refusée | ||
Et j'ai 1 demande d'habilitation "API Entreprise" validée | ||
Et j'ai 1 demande d'habilitation "API Particulier" validée | ||
Et que mon organisation a 1 demande d'habilitation "API Entreprise" | ||
Et que je vais sur la page du tableau de bord | ||
Alors je vois 4 demandes d'habilitation | ||
Et la page contient "Vous êtes le demandeur" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.