Skip to content

Commit

Permalink
Merge pull request #3949 from 3scale/THREESCALE-11498-api-features-plans
Browse files Browse the repository at this point in the history
THREESCALE-11498: API plans features
  • Loading branch information
jlledom authored Jan 8, 2025
2 parents fd0a66b + 7ccc259 commit 42acfd9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
11 changes: 4 additions & 7 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/api/plans/_features.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<tbody>

<tr class="notice" <%= "style=display:none;" unless @plan.features.of_service.empty? -%>>
<tr class="notice" <%= "style=display:none;" unless @plan.features.all_available.empty? -%>>
<td colspan="4">
<span>This plan has no features yet.</span>
</td>
</tr>

<%= render :partial => 'api/features/feature', :collection => @plan.features.of_service %>
<%= render :partial => 'api/features/feature', :collection => @plan.features.all_available %>
</tbody>
</table>
</div>
54 changes: 25 additions & 29 deletions doc/active_docs/account_management_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand All @@ -3171,15 +3169,6 @@
"schema": {
"type": "integer"
}
},
{
"name": "id",
"in": "path",
"description": "ID of the feature.",
"required": true,
"schema": {
"type": "integer"
}
}
],
"requestBody": {
Expand All @@ -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"
]
}
}
Expand All @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down Expand Up @@ -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"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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
Expand Down
2 changes: 1 addition & 1 deletion test/test_helpers/xml_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 42acfd9

Please sign in to comment.