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/doc/active_docs/account_management_api.json b/doc/active_docs/account_management_api.json index f0c648f323..6e1e582393 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" ], @@ -3152,12 +3152,10 @@ "content": {} } } - } - }, - "/admin/api/account_plans/{account_plan_id}/features/{id}.xml": { + }, "post": { - "summary": "Account Plan Features Create", - "description": "Associate an account feature to an account plan.", + "summary": "Account Plan Feature Enable", + "description": "Enables an account feature on 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,10 +3201,12 @@ "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.", + "summary": "Account Plan Feature Disable", + "description": "Disables an account feature on an account plan.", "tags": [ "Account Plans" ], @@ -3680,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" ], @@ -3713,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" ], @@ -3764,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" ], @@ -7384,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" ], @@ -7417,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" ], @@ -7468,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 Feature Disable", + "description": "Disables a feature on a service plan.", "tags": [ "Service Plans" ], 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 }