diff --git a/app/views/admin/enterprises/form/_dfc_permissions.html.haml b/app/views/admin/enterprises/form/_dfc_permissions.html.haml index 210cec5e3a..dd12047bf6 100644 --- a/app/views/admin/enterprises/form/_dfc_permissions.html.haml +++ b/app/views/admin/enterprises/form/_dfc_permissions.html.haml @@ -19,7 +19,7 @@ :plain diff --git a/engines/dfc_provider/app/controllers/dfc_provider/platforms_controller.rb b/engines/dfc_provider/app/controllers/dfc_provider/platforms_controller.rb new file mode 100644 index 0000000000..e847dd49cb --- /dev/null +++ b/engines/dfc_provider/app/controllers/dfc_provider/platforms_controller.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module DfcProvider + class PlatformsController < DfcProvider::ApplicationController + before_action :check_enterprise + + def index + render json: <<~JSON + {"@context":"https://cdn.startinblox.com/owl/context-bis.jsonld","@id":"https://mydataserver.com/enterprises/1/platforms","dfc-t:platforms":{"@list":[{"@id":"https://waterlooregionfood.ca/portal/profile","@type":"dfc-t:Platform","_id":{"$oid":"682afcc4966dbb3aa7464d56"},"description":"A super duper portal for the waterloo region","dfc-t:hasAssignedScopes":{"@list":[{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadEnterprise","@type":"dfc-t:Scope","dfc-t:scope":"ReadEnterprise"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteEnterprise","@type":"dfc-t:Scope","dfc-t:scope":"WriteEnterprise"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadProducts","@type":"dfc-t:Scope","dfc-t:scope":"ReadProducts"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteProducts","@type":"dfc-t:Scope","dfc-t:scope":"WriteProducts"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadOrders","@type":"dfc-t:Scope","dfc-t:scope":"ReadOrders"},{"@id":"https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteOrders","@type":"dfc-t:Scope","dfc-t:scope":"WriteOrders"}],"@type":"rdf:List"},"termsandconditions":"https://waterlooregionfood.ca/terms-and-conditions","title":"Waterloo Region Food Portal"},{"@id":"https://anotherplatform.ca/portal/profile","@type":"dfc-t:Platform","_id":{"$oid":"682b2e2b031c28f69cda1645"},"description":"A super duper portal for the waterloo region","dfc-t:hasAssignedScopes":{"@list":[],"@type":"rdf:List"},"termsandconditions":"https://anotherplatform.ca/terms-and-conditions","title":"anotherplatform Portal"}],"@type":"rdf:List"}} + JSON + end + end +end diff --git a/engines/dfc_provider/config/routes.rb b/engines/dfc_provider/config/routes.rb index 647094b96b..690fab9965 100644 --- a/engines/dfc_provider/config/routes.rb +++ b/engines/dfc_provider/config/routes.rb @@ -5,6 +5,7 @@ DfcProvider::Engine.routes.draw do resources :enterprises, only: [:show] do resources :catalog_items, only: [:index, :show, :update] resources :offers, only: [:show, :update] + resources :platforms, only: [:index] resources :supplied_products, only: [:create, :show, :update] resources :social_medias, only: [:show] end diff --git a/engines/dfc_provider/spec/requests/platforms_spec.rb b/engines/dfc_provider/spec/requests/platforms_spec.rb new file mode 100644 index 0000000000..6a27c87bd8 --- /dev/null +++ b/engines/dfc_provider/spec/requests/platforms_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require_relative "../swagger_helper" + +RSpec.describe "Platforms", swagger_doc: "dfc.yaml" do + let!(:user) { create(:oidc_user) } + let!(:enterprise) do + create( + :distributor_enterprise, + id: 10_000, owner: user, name: "Fred's Farm", + ) + end + + before { login_as user } + + path "/api/dfc/enterprises/{enterprise_id}/platforms" do + parameter name: :enterprise_id, in: :path, type: :string + + get "List platforms with scopes" do + produces "application/json" + + response "200", "successful" do + let(:enterprise_id) { enterprise.id } + + run_test! do + expect(json_response["@id"]).to eq "https://mydataserver.com/enterprises/1/platforms" + end + end + end + end +end diff --git a/swagger/dfc.yaml b/swagger/dfc.yaml index 03022bcca1..542698c35e 100644 --- a/swagger/dfc.yaml +++ b/swagger/dfc.yaml @@ -558,6 +558,68 @@ paths: "@type": dfc-b:Person '404': description: not found + "/api/dfc/enterprises/{enterprise_id}/platforms": + parameters: + - name: enterprise_id + in: path + required: true + schema: + type: string + get: + summary: List platforms with scopes + tags: + - Platforms + responses: + '200': + description: successful + content: + application/json: + examples: + test_example: + value: + "@context": https://cdn.startinblox.com/owl/context-bis.jsonld + "@id": https://mydataserver.com/enterprises/1/platforms + dfc-t:platforms: + "@list": + - "@id": https://waterlooregionfood.ca/portal/profile + "@type": dfc-t:Platform + _id: + "$oid": 682afcc4966dbb3aa7464d56 + description: A super duper portal for the waterloo region + dfc-t:hasAssignedScopes: + "@list": + - "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadEnterprise + "@type": dfc-t:Scope + dfc-t:scope: ReadEnterprise + - "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteEnterprise + "@type": dfc-t:Scope + dfc-t:scope: WriteEnterprise + - "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadProducts + "@type": dfc-t:Scope + dfc-t:scope: ReadProducts + - "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteProducts + "@type": dfc-t:Scope + dfc-t:scope: WriteProducts + - "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/ReadOrders + "@type": dfc-t:Scope + dfc-t:scope: ReadOrders + - "@id": https://data-server.cqcm.startinblox.com/enterprises/1/platforms/scopes/WriteOrders + "@type": dfc-t:Scope + dfc-t:scope: WriteOrders + "@type": rdf:List + termsandconditions: https://waterlooregionfood.ca/terms-and-conditions + title: Waterloo Region Food Portal + - "@id": https://anotherplatform.ca/portal/profile + "@type": dfc-t:Platform + _id: + "$oid": 682b2e2b031c28f69cda1645 + description: A super duper portal for the waterloo region + dfc-t:hasAssignedScopes: + "@list": [] + "@type": rdf:List + termsandconditions: https://anotherplatform.ca/terms-and-conditions + title: anotherplatform Portal + "@type": rdf:List "/api/dfc/product_groups/{id}": parameters: - name: enterprise_id