Skip to content

Commit

Permalink
Changed Member API filters to convay the updated hidded fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptypjeu committed Oct 22, 2024
1 parent 5fd212d commit fdf4b9b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
24 changes: 12 additions & 12 deletions teknologr/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ class MemberFilter(BaseFilter):
method='filter_n_decorations',
label='Antalet betygelser är mellan',
)

# Public but hidable fields (hidden Members are not included)
HIDABLE = Member.HIDABLE_FIELDS + ['address']
address = django_filters.CharFilter(
# NOTE: Custom field name, but added manually to HIDABLE
method='filter_address',
label='Adressen innehåller',
)
email = CharFilterWithKeywords(
lookup_expr='icontains',
label='E-postadressen innehåller',
)
degree_programme = CharFilterWithKeywords(
lookup_expr='icontains',
label='Studieprogrammet innehåller',
Expand All @@ -129,6 +117,18 @@ class MemberFilter(BaseFilter):
label='Utexamineringsåret är mellan',
)

# Public but hidable fields (hidden Members are not included)
HIDABLE = Member.HIDABLE_FIELDS + ['address']
address = django_filters.CharFilter(
# NOTE: Custom field name, but added manually to HIDABLE
method='filter_address',
label='Adressen innehåller',
)
email = CharFilterWithKeywords(
lookup_expr='icontains',
label='E-postadressen innehåller',
)

# Staff only filters
STAFF_ONLY = Member.STAFF_ONLY_FIELDS
birth_date = django_filters.DateFromToRangeFilter(
Expand Down
8 changes: 4 additions & 4 deletions teknologr/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def test_post_for_superuser(self):
'n_functionaries': int,
'n_groups': int,
'n_decorations': int,
'degree_programme': str,
'enrolment_year': int,
'graduated': bool,
'graduated_year': int,
}
# Shown if member is not hidden
MEMBER_PERSONAL = {
Expand All @@ -265,10 +269,6 @@ def test_post_for_superuser(self):
'country': str,
'phone': str,
'email': str,
'degree_programme': str,
'enrolment_year': int,
'graduated': bool,
'graduated_year': int,
}
# Shown only to admins
MEMBER_ADMIN = {
Expand Down
12 changes: 4 additions & 8 deletions teknologr/api/tests_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def setUp(self):
super().setUp()

self.query = 'degree_programme=Svakar'
self.n_normal = 1
self.n_normal = 2
self.n_staff = 2

# Should be found by all
Expand Down Expand Up @@ -386,7 +386,7 @@ def setUp(self):
super().setUp()

self.query = 'graduated=true'
self.n_normal = 2
self.n_normal = 3
self.n_staff = 3

# Should be found by all
Expand All @@ -405,8 +405,6 @@ def setUp(self):
graduated_year=2000,
allow_publish_info=True,
)

# Should only be found by staff
Member.objects.create(
# Graduated, but hidden
given_names='Test',
Expand All @@ -430,7 +428,7 @@ def setUp(self):

# Dummy member included
self.query = 'graduated=false'
self.n_normal = 2
self.n_normal = 3
self.n_staff = 3

# Should be found by all
Expand All @@ -440,8 +438,6 @@ def setUp(self):
graduated=False,
allow_publish_info=True,
)

# Should only be found by staff
Member.objects.create(
# Graduated and has graduated year
given_names='Test',
Expand Down Expand Up @@ -485,7 +481,7 @@ def setUp(self):
# Dummy member included
# XXX: This should probably return all Members, but now the filter is being recognized as "set", so all hidden Members will be filtered out for normal users
self.query = 'graduated=unknown'
self.n_normal = 4
self.n_normal = 5
self.n_staff = 5

class MemberFilterGraduatedYearTest(BaseAPITest, TestCases):
Expand Down
2 changes: 1 addition & 1 deletion teknologr/members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def search_by_name(self, queries, staff_search=False):
class Member(SuperClass):
objects = MemberManager()
STAFF_ONLY_FIELDS = ['birth_date', 'student_id', 'dead', 'subscribed_to_modulen', 'allow_publish_info', 'allow_studentbladet', 'comment', 'username', 'bill_code']
HIDABLE_FIELDS = ['street_address', 'postal_code', 'city', 'country', 'phone', 'email', 'degree_programme', 'enrolment_year', 'graduated', 'graduated_year']
HIDABLE_FIELDS = ['street_address', 'postal_code', 'city', 'country', 'phone', 'email']
# NOTE: given_names is semi-hidable

# NAMES
Expand Down

0 comments on commit fdf4b9b

Please sign in to comment.