RedHatInsights / insights-rbac

Role based access control API service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Principal/policy counts seem incorrect

lcouzens opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'api/rbac/v1/groups'
  2. Create a group
  3. Add principal to group
  4. Create role/policy
  5. Add second user to group
  6. Check group principal/policy counts

Expected behavior
Counts should match principals and policies independently.

Context (please complete the following information):

  • OS: Fedora
  • Browser: FireFox
  • Commit Hash from status endpoint: "6e05d8cb2ac3f6fa26fe19a1e8797a73bb312e91"

Additional context

{
            "uuid": "745ac0cd-b8a3-4a92-a480-bebea168c2e4",
            "name": "test_group_PuAKHCGnWX",
            "description": "Group for admin tests",
            "principalCount": 2,
            "policyCount": 2,
            "created": "2019-07-15T10:57:00.728610Z",
            "modified": "2019-07-15T10:59:33.001129Z"
        }

Looking at the code I believe the issue is with Group.objects.annotate here
https://github.com/RedHatInsights/insights-rbac/blob/master/rbac/management/group/view.py#L66

While investigating we found this https://docs.djangoproject.com/en/2.2/topics/db/aggregation/#combining-multiple-aggregations

@lcouzens This is now available for testing in CI from PR: #100

Please close when verified.

Verified!