Skip to content

Commit

Permalink
return 204 and 404 instead of 200
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcusk19 committed Jan 10, 2024
1 parent da2f964 commit 3c3a271
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
6 changes: 3 additions & 3 deletions endpoints/api/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ def post(self, orgname):
model.organization_skus.remove_subscription_from_org(
organization.id, subscription_id
)
return ("Deleted", 200)
return ("Deleted", 204)
abort(401)


Expand All @@ -1058,7 +1058,7 @@ def delete(self, orgname, subscription_id):
return ("Organization not valid", 400)

model.organization_skus.remove_subscription_from_org(organization.id, subscription_id)
return ("Deleted", 200)
return ("Deleted", 204)
abort(401)


Expand All @@ -1079,7 +1079,7 @@ def get(self):
user = get_authenticated_user()
account_number = marketplace_users.get_account_number(user)
if not account_number:
return []
raise NotFound()

user_subscriptions = marketplace_subscriptions.get_list_of_subscriptions(account_number)

Expand Down
15 changes: 9 additions & 6 deletions static/js/directives/ui/org-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ angular.module('quay').directive('orgBinding', function() {

if ($scope.organization) {
PlanService.listOrgMarketplaceSubscriptions($scope.organization, function(marketplaceSubscriptions){
// $scope.orgMarketplaceSubscriptions = marketplaceSubscriptions
// group the list of subscriptions by their sku field
$scope.orgMarketplaceSubscriptions = groupSubscriptionsBySku(marketplaceSubscriptions);
for (var i = 0; i < marketplaceSubscriptions.length; i++) {
Expand All @@ -44,6 +43,10 @@ angular.module('quay').directive('orgBinding', function() {
}

PlanService.listUserMarketplaceSubscriptions(function(marketplaceSubscriptions){
if(!marketplaceSubscriptions) {
$scope.marketplaceLoading = false;
return;
}
let notBound = [];
$scope.userMarketplaceSubscriptions = groupSubscriptionsBySku(marketplaceSubscriptions);

Expand All @@ -70,10 +73,10 @@ angular.module('quay').directive('orgBinding', function() {

$scope.bindSku = function(subscriptions, numSubscriptions) {
let subscriptionArr = JSON.parse(subscriptions);
// if(numSubscriptions > subscriptionArr.length){
// displayError("number of subscriptions exceeds total amount");
// return;
// }
if(numSubscriptions > subscriptionArr.length){
displayError("number of subscriptions exceeds total amount");
return;
}
$scope.marketplaceLoading = true;
const requestData = {};
requestData["subscriptions"] = [];
Expand Down Expand Up @@ -104,7 +107,7 @@ angular.module('quay').directive('orgBinding', function() {
requestData["subscriptions"].push(subscriptionObject);
}
PlanService.batchRemoveSku(requestData, $scope.organization, function(resp){
if (resp === "Deleted") {
if (resp == "") {
removeSkuSuccessMessage();
}
else {
Expand Down
15 changes: 9 additions & 6 deletions static/js/services/plan-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,14 @@ function(KeyService, UserService, CookieService, ApiService, Features, Config, $

planService.listUserMarketplaceSubscriptions = function(callback) {
if (!Features.BILLING || !Features.RH_MARKETPLACE) { return; }
ApiService.getUserMarketplaceSubscriptions().then(function(resp) {
callback(resp);
});

var errorHandler = function(resp) {
if (resp.status == 404) {
callback(null);
}
}

ApiService.getUserMarketplaceSubscriptions().then(callback, errorHandler);
};

planService.listOrgMarketplaceSubscriptions = function(orgname, callback) {
Expand Down Expand Up @@ -339,9 +344,7 @@ function(KeyService, UserService, CookieService, ApiService, Features, Config, $
var params = {
'orgname': orgname
};
ApiService.batchRemoveSku(subscriptions, params).then(function(resp) {
callback(resp);
});
ApiService.batchRemoveSku(subscriptions, params).then(callback);
};

return planService;
Expand Down
3 changes: 2 additions & 1 deletion test/test_api_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5120,7 +5120,7 @@ def test_remove_sku_from_org(self):
self.deleteResponse(
resource_name=OrganizationRhSkuSubscriptionField,
params=dict(orgname=SUBSCRIPTION_ORG, subscription_id=12345678),
expected_code=200,
expected_code=204,
)
json = self.getJsonResponse(
resource_name=OrganizationRhSku,
Expand Down Expand Up @@ -5157,6 +5157,7 @@ def test_batch_sku_remove(self):
resource_name=OrganizationRhSkuBatchRemoval,
params=dict(orgname=SUBSCRIPTION_ORG),
data={"subscriptions": [{"subscription_id": 12345678}, {"subscription_id": 11223344}]},
expected_code=204,
)
json = self.getJsonResponse(
resource_name=OrganizationRhSku, params=dict(orgname=SUBSCRIPTION_ORG)
Expand Down

0 comments on commit 3c3a271

Please sign in to comment.