-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionadas verificações de permissão de acesso a alguma chamada pela…
… central de autenticação
- Loading branch information
1 parent
f5c217f
commit 20c1a38
Showing
9 changed files
with
218 additions
and
261 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
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 |
---|---|---|
@@ -1,2 +1,37 @@ | ||
class ApplicationController < ActionController::Base | ||
def admin_access | ||
verify_permission(params[:key], 4) | ||
end | ||
|
||
def basic_api_access | ||
verify_permission(params[:key], 3) | ||
end | ||
|
||
def user_data_access | ||
verify_permission(params[:key], 2) | ||
end | ||
|
||
private | ||
|
||
def verify_permission(key, level) | ||
if key.present? | ||
response = HTTParty.get('http://localhost:3001/api/level?key=' + key, format: :plain) # TODO Alterar essa URL para produção | ||
response = JSON.parse response, symbolize_names: true | ||
if response[:error].present? | ||
render status: 400, json: { | ||
message: response[:error] | ||
}.to_json | ||
elsif response[:api][:level] < level | ||
render status: 401, json: { | ||
message: 'Não foi possível realizar essa ação' | ||
}.to_json | ||
else | ||
response[:api][:cpf] | ||
end | ||
else | ||
render status: 400, json: { | ||
message: 'Chave não encontrada' | ||
}.to_json | ||
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
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.