From a5d6b40c08f42f50b2fdfa3a9d30ea9a850ee8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Thu, 28 Nov 2024 16:51:38 +0100 Subject: [PATCH 1/4] Rename `of_service` scope to `all_available` previous name was hard to understand, and incorrect, since features may belong to service or account plans --- app/models/plan.rb | 11 ++++------- app/views/api/plans/_features.html.erb | 4 ++-- .../user-management-api/service_features_test.rb | 2 +- test/test_helpers/xml_assertions.rb | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/models/plan.rb b/app/models/plan.rb index a021fa8457..af54d79127 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -93,13 +93,10 @@ def visible plan.has_many :plan_metrics, foreign_key: :plan_id, &Logic::MetricVisibility::OfMetricAssociationProxy end - has_many :features_plans, :as => :plan - - # FIXME: this should be a simple HABTM - # No it can't, because it is POLYMORPHIC - has_many :features, :through => :features_plans do - # returns all features owned by issuer, not only enabled by plan - def of_service + has_many :features_plans, as: :plan, dependent: :delete_all + has_many :features, through: :features_plans do # Only enabled features + # returns all features available for this plan, not only enabled ones + def all_available owner = proxy_association.owner owner.issuer.features.with_object_scope(owner) end diff --git a/app/views/api/plans/_features.html.erb b/app/views/api/plans/_features.html.erb index a877e71c2b..875b08e284 100644 --- a/app/views/api/plans/_features.html.erb +++ b/app/views/api/plans/_features.html.erb @@ -15,13 +15,13 @@ - > + > This plan has no features yet. - <%= render :partial => 'api/features/feature', :collection => @plan.features.of_service %> + <%= render :partial => 'api/features/feature', :collection => @plan.features.all_available %> diff --git a/test/integration/user-management-api/service_features_test.rb b/test/integration/user-management-api/service_features_test.rb index b11b98a84e..e148084f02 100644 --- a/test/integration/user-management-api/service_features_test.rb +++ b/test/integration/user-management-api/service_features_test.rb @@ -39,7 +39,7 @@ def setup xml = Nokogiri::XML::Document.parse(@response.body) - assert_all_features_of_service xml, service + assert_all_features_available xml, service end test 'show' do diff --git a/test/test_helpers/xml_assertions.rb b/test/test_helpers/xml_assertions.rb index a84236f5ff..11f9536dd7 100644 --- a/test/test_helpers/xml_assertions.rb +++ b/test/test_helpers/xml_assertions.rb @@ -183,7 +183,7 @@ def assert_an_application_plan(xml, service) assert xml.xpath('.//plan/cancellation_period').presence end - def assert_all_features_of_service(xml, service) + def assert_all_features_available(xml, service) assert xml.xpath('.//features/feature/service_id').presence assert xml.xpath('.//features/feature/service_id') .all? { |service_id| service_id.text == service.id.to_s } From d1b1d00dacac2be64fdf84c60ac2f1b04806369c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Fri, 29 Nov 2024 11:18:20 +0100 Subject: [PATCH 2/4] Fix API Docs to represent the actual API --- doc/active_docs/account_management_api.json | 26 +++++++++------------ 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/doc/active_docs/account_management_api.json b/doc/active_docs/account_management_api.json index f0c648f323..bd4a20f8f1 100644 --- a/doc/active_docs/account_management_api.json +++ b/doc/active_docs/account_management_api.json @@ -3152,11 +3152,9 @@ "content": {} } } - } - }, - "/admin/api/account_plans/{account_plan_id}/features/{id}.xml": { + }, "post": { - "summary": "Account Plan Features Create", + "summary": "Account Plan Features Enable", "description": "Associate an account feature to an account plan.", "tags": [ "Account Plans" @@ -3171,15 +3169,6 @@ "schema": { "type": "integer" } - }, - { - "name": "id", - "in": "path", - "description": "ID of the feature.", - "required": true, - "schema": { - "type": "integer" - } } ], "requestBody": { @@ -3192,10 +3181,15 @@ "access_token": { "type": "string", "description": "A personal Access Token." + }, + "feature_id": { + "type": "integer", + "description": "ID of the feature." } }, "required": [ - "access_token" + "access_token", + "feature_id" ] } } @@ -3207,7 +3201,9 @@ "content": {} } } - }, + } + }, + "/admin/api/account_plans/{account_plan_id}/features/{id}.xml": { "delete": { "summary": "Account Plan Features Delete", "description": "Deletes the association of an account feature to an account plan.", From 60739a78cc1c4b460e2ee16b1c64759f835d594b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Fri, 29 Nov 2024 12:36:45 +0100 Subject: [PATCH 3/4] OAS Spec: Improve endpoint descriptions --- doc/active_docs/account_management_api.json | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/active_docs/account_management_api.json b/doc/active_docs/account_management_api.json index bd4a20f8f1..61b25e1366 100644 --- a/doc/active_docs/account_management_api.json +++ b/doc/active_docs/account_management_api.json @@ -3121,7 +3121,7 @@ "/admin/api/account_plans/{account_plan_id}/features.xml": { "get": { "summary": "Account Plan Features List", - "description": "Returns the list of the features associated to an account plan.", + "description": "Returns the list of the features enabled for an account plan.", "tags": [ "Account Plans" ], @@ -3155,7 +3155,7 @@ }, "post": { "summary": "Account Plan Features Enable", - "description": "Associate an account feature to an account plan.", + "description": "Enables an account feature on an account plan.", "tags": [ "Account Plans" ], @@ -3205,8 +3205,8 @@ }, "/admin/api/account_plans/{account_plan_id}/features/{id}.xml": { "delete": { - "summary": "Account Plan Features Delete", - "description": "Deletes the association of an account feature to an account plan.", + "summary": "Account Plan Features Disable", + "description": "Disables an account feature on an account plan.", "tags": [ "Account Plans" ], @@ -3676,7 +3676,7 @@ "/admin/api/application_plans/{application_plan_id}/features.xml": { "get": { "summary": "Application Plan Feature List", - "description": "Returns the list of features of the application plan.", + "description": "Returns the list of features enabled on the application plan.", "tags": [ "Application Plans" ], @@ -3709,8 +3709,8 @@ } }, "post": { - "summary": "Application Plan Feature Create", - "description": "Associates a feature to an application plan.", + "summary": "Application Plan Feature Enable", + "description": "Enables a feature on an application plan.", "tags": [ "Application Plans" ], @@ -3760,8 +3760,8 @@ }, "/admin/api/application_plans/{application_plan_id}/features/{id}.xml": { "delete": { - "summary": "Application Plan Feature Delete", - "description": "Removes the association of a feature to an application plan.", + "summary": "Application Plan Feature Disable", + "description": "Disable a feature on an application plan.", "tags": [ "Application Plans" ], @@ -7380,7 +7380,7 @@ "/admin/api/service_plans/{service_plan_id}/features.xml": { "get": { "summary": "Service Plan Feature List", - "description": "Returns the list of features of a service plan.", + "description": "Returns the list of features enabled on a service plan.", "tags": [ "Service Plans" ], @@ -7413,8 +7413,8 @@ } }, "post": { - "summary": "Service Plan Feature Add", - "description": "Associates an existing feature to a service plan.", + "summary": "Service Plan Feature Enable", + "description": "Enables an existing feature on a service plan.", "tags": [ "Service Plans" ], @@ -7464,8 +7464,8 @@ }, "/admin/api/service_plans/{service_plan_id}/features/{id}.xml": { "delete": { - "summary": "Service Plan Features Delete", - "description": "Removes the association of a feature to a service plan.", + "summary": "Service Plan Features Disable", + "description": "Disables a feature on a service plan.", "tags": [ "Service Plans" ], From 6afe15008a0c57780e85ce0937ead0b5aa6144a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Wed, 18 Dec 2024 12:51:11 +0100 Subject: [PATCH 4/4] Endpoint descriptions: Feature in singular --- doc/active_docs/account_management_api.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/active_docs/account_management_api.json b/doc/active_docs/account_management_api.json index 61b25e1366..6e1e582393 100644 --- a/doc/active_docs/account_management_api.json +++ b/doc/active_docs/account_management_api.json @@ -3154,7 +3154,7 @@ } }, "post": { - "summary": "Account Plan Features Enable", + "summary": "Account Plan Feature Enable", "description": "Enables an account feature on an account plan.", "tags": [ "Account Plans" @@ -3205,7 +3205,7 @@ }, "/admin/api/account_plans/{account_plan_id}/features/{id}.xml": { "delete": { - "summary": "Account Plan Features Disable", + "summary": "Account Plan Feature Disable", "description": "Disables an account feature on an account plan.", "tags": [ "Account Plans" @@ -7464,7 +7464,7 @@ }, "/admin/api/service_plans/{service_plan_id}/features/{id}.xml": { "delete": { - "summary": "Service Plan Features Disable", + "summary": "Service Plan Feature Disable", "description": "Disables a feature on a service plan.", "tags": [ "Service Plans"