-
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.
feat: PPT-1470 Add lookup by email endpoint in domains controller
- Loading branch information
Showing
5 changed files
with
120 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5477,6 +5477,77 @@ paths: | |
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__ContentError' | ||
/api/engine/v2/domains/lookup/{email}: | ||
get: | ||
summary: Find the domain name by looking into domain registerd email domains. | ||
tags: | ||
- Domains | ||
operationId: PlaceOS::Api::Domains_lookup | ||
parameters: | ||
- name: email | ||
in: path | ||
description: User email to lookup domain for | ||
example: [email protected] | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
200: | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/String' | ||
409: | ||
description: Conflict | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__CommonError' | ||
401: | ||
description: Unauthorized | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__CommonError' | ||
403: | ||
description: Forbidden | ||
404: | ||
description: Not Found | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__CommonError' | ||
408: | ||
description: Request Timeout | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__CommonError' | ||
400: | ||
description: Bad Request | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__ParameterError' | ||
422: | ||
description: Unprocessable Entity | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__ParameterError' | ||
406: | ||
description: Not Acceptable | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__ContentError' | ||
415: | ||
description: Unsupported Media Type | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/PlaceOS__Api__Application__ContentError' | ||
/api/engine/v2/domains/{id}: | ||
get: | ||
summary: show the selected domain | ||
|
@@ -20891,6 +20962,11 @@ components: | |
additionalProperties: | ||
type: object | ||
nullable: true | ||
email_domains: | ||
type: array | ||
items: | ||
type: string | ||
nullable: true | ||
id: | ||
type: string | ||
nullable: true | ||
|
@@ -21836,9 +21912,16 @@ components: | |
additionalProperties: | ||
type: object | ||
nullable: true | ||
email_domains: | ||
type: array | ||
items: | ||
type: string | ||
nullable: true | ||
id: | ||
type: string | ||
nullable: true | ||
String: | ||
type: string | ||
PlaceOS__Model__Driver: | ||
type: object | ||
properties: | ||
|
@@ -22396,8 +22479,6 @@ components: | |
id: | ||
type: string | ||
nullable: true | ||
String: | ||
type: string | ||
Array_JSON__Any_: | ||
type: array | ||
items: | ||
|
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,14 @@ | ||
require "../helper" | ||
|
||
module PlaceOS::Api | ||
describe Domains do | ||
it "Lookup domain via user email" do | ||
authority = Model::Generator.authority("https://www.dev-placeos.com", ["placeos.com", "dev-placeos.com"]).save! | ||
email = URI.encode_www_form("[email protected]") | ||
path = "#{Domains.base_route}lookup/#{email}" | ||
result = client.get(path) | ||
result.status_code.should eq(200) | ||
result.body.strip('"').should eq(authority.domain) | ||
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 |
---|---|---|
|
@@ -10,12 +10,12 @@ module PlaceOS::Api | |
before_action :can_read, only: [:index, :show] | ||
before_action :can_write, only: [:create, :update, :destroy, :remove] | ||
|
||
before_action :check_admin, except: [:index, :show] | ||
before_action :check_admin, except: [:index, :show, :lookup] | ||
before_action :check_support, only: [:index, :show] | ||
|
||
############################################################################################### | ||
|
||
@[AC::Route::Filter(:before_action, except: [:index, :create])] | ||
@[AC::Route::Filter(:before_action, except: [:index, :lookup, :create])] | ||
def find_current_domain(id : String) | ||
Log.context.set(authority_id: id) | ||
# Find will raise a 404 (not found) if there is an error | ||
|
@@ -35,6 +35,21 @@ module PlaceOS::Api | |
paginate_results(elastic, query) | ||
end | ||
|
||
# skip authentication for the lookup | ||
skip_action :authorize!, only: :lookup | ||
skip_action :set_user_id, only: :lookup | ||
|
||
# Find the domain name by looking into domain registerd email domains. | ||
@[AC::Route::GET("/lookup/:email")] | ||
def lookup( | ||
@[AC::Param::Info(name: "email", description: "User email to lookup domain for", example: "[email protected]")] | ||
email : String | ||
) : String | ||
authority = ::PlaceOS::Model::Authority.find_by_email(email) | ||
raise Error::NotFound.new("No matching domain found") unless authority | ||
authority.domain | ||
end | ||
|
||
# show the selected domain | ||
@[AC::Route::GET("/:id")] | ||
def show : ::PlaceOS::Model::Authority | ||
|
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