Pearl1594 opened a new pull request #4316:
URL: https://github.com/apache/cloudstack/pull/4316
## Description
1. When listAll is true, listProjects API doesn't list projects that have
users as members
2. Added defensive checks to overcome NPEs
## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the
boxes that apply: -->
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [X] 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)
## How Has This Been Tested?
This has been verified using the cmk and UI
There exists 7 projects:
```
MariaDB [cloud]> select name, account_id, user_id, created, removed from
project_view;
MariaDB [cloud]> select name, account_id, user_id, created, removed from
project_view where removed is NULL;
+--------------+------------+---------+---------------------+---------+
| name | account_id | user_id | created | removed |
+--------------+------------+---------+---------------------+---------+
| Project2 | 4 | NULL | 2020-09-09 10:08:52 | NULL |
| Project2 | 5 | 6 | 2020-09-09 10:08:52 | NULL |
| p3 | 2 | NULL | 2020-09-09 11:43:50 | NULL |
| p3 | 5 | 5 | 2020-09-09 11:43:50 | NULL |
| Project1 | 2 | NULL | 2020-09-09 12:36:03 | NULL |
| Project1 | 5 | 5 | 2020-09-09 12:36:03 | NULL |
| p1 | 2 | 2 | 2020-09-09 13:16:11 | NULL |
| p1 | 5 | 5 | 2020-09-09 13:16:11 | NULL |
| d1 | 12 | 8 | 2020-09-09 13:21:38 | NULL |
| p1 | 2 | 2 | 2020-09-09 13:16:11 | NULL |
| p1 | 5 | 5 | 2020-09-09 13:16:11 | NULL |
| p4 | 15 | 10 | 2020-09-10 05:54:44 | NULL |
| p41useradmin | 17 | 12 | 2020-09-10 06:23:43 | NULL |
| Project1 | 2 | NULL | 2020-09-09 12:36:03 | NULL |
| Project1 | 5 | 5 | 2020-09-09 12:36:03 | NULL |
+--------------+------------+---------+---------------------+---------+
```
Before fix:
```
(localcloud) SBCM5> > list projects filter=account,owner,name,id,
listall=true
{
"count": 2,
"project": [
{
"id": "cab2a46a-8250-4825-85ff-e18e7275eb18",
"name": "p3",
"owner": [
{
"account": "admin"
}
]
},
{
"id": "f0e64573-3483-4e4c-8164-c92e9efda80f",
"name": "Project2",
"owner": [
{
"account": "ACSUser"
}
]
}
]
}
```
With fix:
```
(localcloud) SBCM5> > list projects filter=account,owner,name,id,
listall=true
{
"count": 7,
"project": [
{
"id": "0f4a6c4f-a95e-4ea2-b840-e16eedf1085a",
"name": "p41useradmin",
"owner": [
{
"account": "u4",
"user": "u41",
"userid": "9d523792-a777-45c2-8b34-84052b8d4b34"
}
]
},
{
"id": "352b9a95-cc6e-412f-ad1a-7671eaebfdff",
"name": "p4",
"owner": [
{
"account": "u3",
"user": "u3",
"userid": "41d2a5e2-f45f-479b-bc2b-3c911d2b7b46"
}
]
},
{
"id": "02b5bc7b-a1e7-4e77-860e-99fd5fb30ec3",
"name": "d1",
"owner": [
{
"account": "dom1",
"user": "dom1",
"userid": "a534379c-804d-4a45-bf09-73e784adacb0"
}
]
},
{
"id": "7ab34cd7-2403-477a-a3cf-9d03c517345c",
"name": "p1",
"owner": [
{
"account": "admin",
"user": "admin",
"userid": "e125c80a-eebf-11ea-ba61-1e006a013aee"
},
{
"account": "user1",
"user": "user1",
"userid": "705136fe-2c09-4031-873f-835ee3dfad02"
}
]
},
{
"id": "f5884fbe-9ce1-4315-9a76-c1564d13dac0",
"name": "Project1",
"owner": [
{
"account": "admin"
},
{
"account": "user1",
"user": "user1",
"userid": "705136fe-2c09-4031-873f-835ee3dfad02"
}
]
},
{
"id": "cab2a46a-8250-4825-85ff-e18e7275eb18",
"name": "p3",
"owner": [
{
"account": "admin"
}
]
},
{
"id": "f0e64573-3483-4e4c-8164-c92e9efda80f",
"name": "Project2",
"owner": [
{
"account": "ACSUser"
}
]
}
]
}
```
<!-- Please read the
[CONTRIBUTING](https://github.com/apache/cloudstack/blob/master/CONTRIBUTING.md)
document -->
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]