-
Notifications
You must be signed in to change notification settings - Fork 1
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 #412 from etalab/features/public-id
Introduce public pages for authorization requests
- Loading branch information
Showing
10 changed files
with
90 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module AccessAuthorization | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include Pundit::Authorization | ||
|
||
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized | ||
|
||
def pundit_user | ||
UserContext.new(current_user, request.host) | ||
end | ||
end | ||
|
||
def pundit_user | ||
self.class.pundit_user | ||
end | ||
|
||
def user_not_authorized | ||
flash[:error] = { | ||
title: t('application.user_not_authorized.title') | ||
} | ||
|
||
redirect_to dashboard_path | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
app/controllers/public/authorization_requests_controller.rb
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,17 @@ | ||
class Public::AuthorizationRequestsController < PublicController | ||
helper AuthorizationRequestsHelpers | ||
|
||
helper_method :current_user, :user_signed_in? | ||
|
||
def show | ||
@authorization_request = AuthorizationRequest.find_by(public_id: params[:id]) | ||
|
||
if @authorization_request | ||
@authorization_request = @authorization_request.decorate | ||
|
||
render 'authorization_request_forms/summary', layout: 'authorization_request' | ||
else | ||
redirect_to root_path | ||
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,11 @@ | ||
class PublicController < ApplicationController | ||
include AccessAuthorization | ||
|
||
def current_user | ||
@current_user ||= User.new | ||
end | ||
|
||
def user_signed_in? | ||
false | ||
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
6 changes: 6 additions & 0 deletions
6
db/migrate/20240906081749_add_public_id_to_authorization_requests.rb
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,6 @@ | ||
class AddPublicIdToAuthorizationRequests < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :authorization_requests, :public_id, :uuid, default: 'gen_random_uuid()' | ||
add_index :authorization_requests, :public_id | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
# language: fr | ||
|
||
Fonctionnalité: Consultation d'une demande d'habilitation via sa page public | ||
Chaque demande d'habilitation possède une page public accessible à n'importe quel internaute | ||
|
||
Scénario: Je peux consulter une page de demande d'habilitation sans être connectée | ||
Sachant qu'il existe une demande d'habilitation "API Entreprise" intitulée "Ma superbe demande" | ||
Et que je visite sa page publique | ||
Alors la page contient "API Entreprise" | ||
Et la page contient "Ma superbe demande" |
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