Skip to content

Commit

Permalink
Merge pull request #1358 from dmm-com/bugfix/role-export-api
Browse files Browse the repository at this point in the history
Fix filtering of inactive users and groups in RoleExportAPI
  • Loading branch information
hinashi authored Jan 24, 2025
2 parents 72294e5 + a49ffab commit da9f438
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions role/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def _get_permission_data(permission_obj):
"id": instance.id,
"name": instance.name,
"description": instance.description,
"users": [x.username for x in instance.users.all()],
"groups": [x.name for x in instance.groups.all()],
"admin_users": [x.username for x in instance.admin_users.all()],
"admin_groups": [x.name for x in instance.admin_groups.all()],
"users": [x.username for x in instance.users.filter(is_active=True)],
"groups": [x.name for x in instance.groups.filter(is_active=True)],
"admin_users": [x.username for x in instance.admin_users.filter(is_active=True)],
"admin_groups": [x.name for x in instance.admin_groups.filter(is_active=True)],
"permissions": [_get_permission_data(x) for x in instance.permissions.all()],
}

Expand Down
10 changes: 10 additions & 0 deletions role/tests/test_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def test_export(self):
role = self._create_role("test-role")
entity = self.create_entity(admin, "Entity")
entity.full.roles.add(role)
user = User.objects.create(username="test_user")
group = Group.objects.create(name="test_group")

# Associate user and group with the role
role.users.set([user.id])
role.groups.set([group.id])

# Delete the user and group
user.delete()
group.delete()

resp = self.client.get("/role/api/v2/export")
data = yaml.safe_load(resp.content.decode("utf-8"))
Expand Down

0 comments on commit da9f438

Please sign in to comment.