winterhazel opened a new pull request, #9590:
URL: https://github.com/apache/cloudstack/pull/9590

   ### Description
   
   When credits are added to an account, an entry that represents the operation 
is created in `cloud_usage.quota_credits`. Some information about these entries 
is currently returned alongside an account's balance through the `quotaBalance` 
API. However, this is not consistent with the API's purpose (viewing an 
account's balance), and it is not possible to view the credit addition history 
for a whole domain with a single API call.
   
   In order to make `quotaBalance` more consistent with its purpose, the credit 
addition history will be removed from its response alongside some enhancements 
to the API in the future. To list the credit addition history, this PR adds the 
`quotaCreditsList`, which has the following parameters:
   
   - `accountid`: ID of the account for which the credit statement will be 
generated.
   - `domainid`: ID of the domain for which credit statement will be generated. 
Available only for administrators.
   - `isrecursive`: Whether to generate the credit statement for the provided 
domain and its children. Defaults to false.
   - `startdate`: Start date of the statement. If not provided, the first day 
of the current month will be considered as the start date.
   - `enddate`: End date of the statement. If not provided, the current date 
will be considered as the end date.
   
   No parameters are flagged as required, but at least `accountid` or 
`domainid` must be provided.
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [X] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [X] Minor
   
   
   ### How Has This Been Tested?
   
   In my environment, there were the following domains and accounts:
   - `ROOT`: admin (root admin)
   - `ROOT/d1`: d1 (domain admin), u1 (user)
   
   First, in the root admin account, I added 100 credits to the three accounts; 
in the domain admin account, I added credits to d1 and u1. Then, I tested the 
behavior of the API for each account.
   
   #### For the root admin account:
   - I listed admin's credits history and verified that the response had the 
expected results (`accountid` tested).
   
   ```
   (admin) 🐢 > quota creditslist accountid=60b92e66-28b2-11ef-a04e-6ac09c2b3d6b 
   {
     "count": 1,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:39+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed d1's credits history and verified that the response had the 
expected results.
   
   ```
   (admin) 🐢 > quota creditslist accountid=a6b8f3b0-0f4f-4762-86eb-df229fe602ed 
   {
     "count": 2,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:53+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:06+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed u1's credits history and verified that the response had the 
expected results.
   
   ```
   (admin) 🐢 > quota creditslist accountid=2560f486-38f1-42bf-aa0f-c68abe7ad15e 
   {
     "count": 2,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:58+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:10+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed d1's credits specifying the interval so that only the first 
addition was shown (`enddate` tested).
   
   ```
   (admin) 🐢 > quota creditslist accountid=a6b8f3b0-0f4f-4762-86eb-df229fe602ed 
enddate=2024-08-18T22:46:00+0000
   {
     "count": 1,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:53+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed d1's credits specifying the interval so that only the last 
addition was shown (`startdate` tested).
   
   ```
   (admin) 🐢 > quota creditslist accountid=a6b8f3b0-0f4f-4762-86eb-df229fe602ed 
startdate=2024-08-18T22:46:00+0000
   {
     "count": 1,
     "credit": [
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:06+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed `ROOT`'s credits and verified that the response had the expected 
results (`domainid` tested).
   
   ```
   (admin) 🐢 > quota creditslist domainid=40815ad7-28b2-11ef-a04e-6ac09c2b3d6b 
   {
     "count": 1,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:39+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed `ROOT`'s credits recursively and verified that the response had 
the expected results (`isrecursive` tested).
   
   ```
   (admin) 🐢 > quota creditslist domainid=40815ad7-28b2-11ef-a04e-6ac09c2b3d6b 
isrecursive=true
   {
     "count": 5,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:39+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:53+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:58+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:06+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:10+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   #### For the domain admin account:
   - I tried to list admin's credits history and verified that my permission 
was denied.
   
   ```
   (d1) 🐢 > quota creditslist accountid=2
   🙈 Error: (HTTP 531, error code 4365) Caller does not have permission to 
operate with provided resource.
   ```
   
   - I listed d1's credits history and verified that the response had the 
expected results.
   
   ```
   (d1) 🐢 > quota creditslist accountid=a6b8f3b0-0f4f-4762-86eb-df229fe602ed 
   {
     "count": 2,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:53+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:06+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed u1's credits history and verified that the response had the 
expected results.
   
   ```
   (d1) 🐢 > quota creditslist accountid=2560f486-38f1-42bf-aa0f-c68abe7ad15e 
   {
     "count": 2,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:58+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:10+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I listed `ROOT/d1`'s credits history and verified that the response had 
the expected results.
   
   ```
   (d1) 🐢 > quota creditslist domainid=02da877c-615f-4a7d-a68d-bde6b6d5d01c 
   {
     "count": 4,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:53+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:58+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:06+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:10+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   #### For the user account:
   - I tried to list admin's credits history and verified that my permission 
was denied.
   
   ```
   (u1) 🐢 > quota creditslist accountid=2
   🙈 Error: (HTTP 531, error code 4365) Caller does not have permission to 
operate with provided resource.
   ```
   
   - I tried to list d1's credits history and verified that my permission was 
denied.
   
   ```
   (u1) 🐢 > quota creditslist accountid=a6b8f3b0-0f4f-4762-86eb-df229fe602ed 
   🙈 Error: (HTTP 531, error code 4365) Caller does not have permission to 
operate with provided resource.
   ```
   
   - I listed u1's credits history and verified that the response had the 
expected results.
   
   ```
   (u1) 🐢 > quota creditslist accountid=2560f486-38f1-42bf-aa0f-c68abe7ad15e
   {
     "count": 2,
     "credit": [
       {
         "credit": 100,
         "creditedon": "2024-08-18T22:45:58+0000",
         "creditoruserid": "60ba931c-28b2-11ef-a04e-6ac09c2b3d6b",
         "creditorusername": "admin",
         "currency": "$"
       },
       {
         "credit": 200,
         "creditedon": "2024-08-18T22:46:10+0000",
         "creditoruserid": "5bd602d7-5d43-4d68-9619-d413d0458a2d",
         "creditorusername": "d1",
         "currency": "$"
       }
     ]
   }
   ```
   
   - I tried to list the credits history for `ROOT/d1` and verified that my 
permission was denied.
   
   ```
   (u1) 🐢 > quota creditslist domainid=2
   🙈 Error: (HTTP 531, error code 4365) Regular users are not allowed to 
generate domain statements.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to