Skip to content

Commit

Permalink
fix: Return users in project.all_members() (HumanSignal#5991)
Browse files Browse the repository at this point in the history
#### Change has impacts in these area(s)
_(check all that apply)_
- [x] Backend (API)



### Describe the reason for change
project.all_members() returned member ids instead of user ids


#### What does this fix?
all_members() returns user ids now. 


#### What is the new behavior?
Data manager filters display the correct user list. 



#### What is the current behavior?
Data manager filters displayed empty user items. 

![image](https://github.com/HumanSignal/label-studio/assets/501780/67daf1d8-acf9-416e-9efc-9917872be121)

### What level of testing was included in the change?
_(check all that apply)_
- [ ] e2e
- [ ] integration
- [ ] unit
  • Loading branch information
makseq authored Jun 14, 2024
1 parent 59e89cb commit c346a78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 8 additions & 5 deletions label_studio/projects/mixins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Mapping, Optional

from core.redis import start_job_async_or_sync
from django.db.models import QuerySet
from django.utils.functional import cached_property

from core.redis import start_job_async_or_sync
from users.models import User


class ProjectMixin:
def rearrange_overlap_cohort(self):
Expand Down Expand Up @@ -85,9 +88,9 @@ def _can_use_overlap(self):
return True

@cached_property
def all_members(self):
def all_members(self) -> QuerySet[User]:
"""
Returns all members of project
:return:
Returns all users of project
:return: List[User]
"""
return self.organization.members.values_list('user__id', flat=True)
return User.objects.filter(id__in=self.organization.members.values_list('user__id'))
12 changes: 11 additions & 1 deletion label_studio/tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json

import pytest

from django.db.models.query import QuerySet
from users.models import User
from tests.utils import make_project


Expand Down Expand Up @@ -29,3 +31,11 @@ def test_update_tasks_counters_and_task_states(business_client):
ids = set(project.tasks.all().values_list('id', flat=True))
obj = project._update_tasks_counters_and_task_states(ids, True, True, True)
assert obj == 0

@pytest.mark.django_db
def test_project_all_members(business_client):
project = make_project({}, business_client.user, use_ml_backend=False)
members = project.all_members

assert isinstance(members, QuerySet)
assert isinstance(members.first(), User)

0 comments on commit c346a78

Please sign in to comment.