Skip to content

Commit

Permalink
Fixes based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 7, 2023
1 parent 207cab0 commit f816959
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- run: bundle exec rails db:setup --trace
- run: bundle exec rails test
- run: bundle exec rails test:system
- run: bundle exec rails test:integration

gitlab-push:
name: Push to GitLab
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/api/admin/tenants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
class Api::Admin::TenantsController < ActionController::Base
before_action :set_tenant, only: %i[destroy]
rescue_from ActiveRecord::RecordNotFound, with: :not_found

def create
@tenant = Tenant.new(tenant_params)
# authorize([:admin, @tenant])
return if @tenant.save

render json: @tenant.errors, status: :unprocessable_entity
render json: { message: @tenant.errors.full_messages[0] }, status: :unprocessable_entity
end

def destroy
# authorize([:admin, @tenant])
return if @tenant.destroy

render json: @tenant.errors, status: :unprocessable_entity
render json: { message: @tenant.errors.full_messages[0] }, status: :unprocessable_entity
end

private
Expand All @@ -24,4 +26,8 @@ def set_tenant
def tenant_params
params.require(:tenant).permit(:name)
end

def not_found
render json: { message: 'not found' }, status: :not_found
end
end
134 changes: 134 additions & 0 deletions public/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
openapi: 3.1.0

info:
title: GovBox Pro API
version: 0.0.1

description: Rozhranie na prácu s prostredníctvom služby GovBox

contact:
name: Služby Slovensko.Digital, s.r.o.
url: https://ekosystem.slovensko.digital/sluzby/govbox
email: [email protected]

servers:
- description: Server Govbox Pro v PROD prostredí
url: https://pro.govbox.sk
- description: Server Govbox Pro v Staging prostredí
url: https://govbox-pro.staging.slovensko.digital/

security:
- "API Token": []

paths:
/api/admin/tenants/{id}s:
delete:
tags: [Správa tenantov]
summary: Vymaže tenanta zo systému vrátane všetkých jeho údajov
description: |
Vymaže tenanta zo systému.
parameters:
- $ref: "#/components/parameters/TenantId"
responses:
204:
description: Úspešne vymazaný tenant zo systému.

/api/admin/tenant/:
post:
tags: [Správa tenantov]
summary: Založí nového tenanta v systéme
description: |
Založí nového tenanta.
parameters:
- $ref: "#/components/parameters/MessageId"
responses:
200:
description: Úspešne založený tenant v systéme
content:
application/json:
schema:
type: object
properties:
code:
description: Výsledok odoslania správy na autorizáciu doručenky, hodnota `0` znamená úspešné prijatie správy na autorizáciu doručenky.
type: integer
message_id:
description: eDesk identifikátor prebranej správy.
type: integer
example: 53089851
required:
- code
example:
code: 0

components:
parameters:
tenantId:
description: Govbox Pro identifikátor tenanta.
name: id
in: path
required: true
schema:
type: integer
example: 20378640

schemas:
Tenant:
description: Tenant
properties:
id:
description: Govbox Pro identifikátor tenanta.
type: integer
name:
description: Názov tenanta.
type: string
feature_flags:
description: Aktivované služby tenanta
type: boolean
required:
- id
- name
- system
example:
id: 53089851
parent_id: null
name: Inbox
system: true

securitySchemes:
"API Token":
description: |
Požaduje API token vytvorený treťou stranou, ktorý:
- je zakodovaný algoritmom RS256,
- je podpísaný privátnym kľúčom tretej strany,
- má nastavený `sub` claim na identifikátor tretej strany,
- má nastavený `exp` claim na max. 120 minút,
- má nastavený `jti` claim na identifikátor, ktorý je unikátny počas 120 minút.
Príklad `header` segmentu:
{
"alg": "RS256",
}
Príklad `payload` segmentu:
{
"sub": "SPL_Irvin_50158635_11012019",
"exp": 1543437976,
"jti": "4dee8618-abbe-4dc3-83ba-e984d1396f9f",
}
API token musí byť prítomný buď:
- v hlavičke požiadavky ako `Authorization: Bearer <api-token>`,
- alebo v URL parametri požiadavky ako `?token=<api-token>`.
Poznámky:
- hodnota `jti` sa kontroluje podľa regulárneho výrazu `/\A[0-9a-z\-_]{32,256}\z/i`,
- rovnaké `jti` sa nesmie použiť viac ako jedenkrát počas 120 minút.
type: http
scheme: bearer
bearerFormat: JWT
6 changes: 2 additions & 4 deletions test/integration/tenant_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ class TenantApiTest < ActionDispatch::IntegrationTest
assert_equal "Testovaci tenant", json_response["name"]
assert_not_nil json_response["id"]
assert_empty json_response["feature_flags"]
assert_not_nil Tenant.find(json_response["id"])
assert Tenant.exists?(json_response["id"])
end

test "can destroy tenant" do
tenant = tenants(:solver)
tenant_id = tenant.id
delete "/api/admin/tenants/#{tenant.id}", params: {}, as: :json
assert_response :no_content
assert_raises(ActiveRecord::RecordNotFound) do
Tenant.find(tenant_id)
end
assert_not Tenant.exists?(tenant_id)
end
end

0 comments on commit f816959

Please sign in to comment.