Skip to content

Commit

Permalink
Add has_initiatives to current user api
Browse files Browse the repository at this point in the history
  • Loading branch information
gannetson committed Aug 17, 2022
1 parent 1a5c33a commit 99499dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bluebottle/members/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,18 @@ class CurrentUserSerializer(BaseUserPreviewSerializer):
segments = serializers.PrimaryKeyRelatedField(
many=True, queryset=Segment.objects
)
has_initiatives = serializers.SerializerMethodField()

def get_has_initiatives(self, obj):
return obj.own_initiatives.exists()

class Meta(object):
model = BB_USER_MODEL
fields = UserPreviewSerializer.Meta.fields + (
'id_for_ember', 'primary_language', 'email', 'full_name', 'phone_number',
'last_login', 'date_joined', 'location',
'verified', 'permissions', 'matching_options_set',
'organization', 'segments', 'required'
'organization', 'segments', 'required', 'has_initiatives'
)


Expand Down
12 changes: 12 additions & 0 deletions bluebottle/members/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from bluebottle.auth.middleware import authorization_logger
from bluebottle.clients import properties
from bluebottle.initiatives.tests.factories import InitiativeFactory
from bluebottle.members.models import MemberPlatformSettings, UserActivity, Member
from bluebottle.offices.tests.factories import LocationFactory
from bluebottle.segments.tests.factories import SegmentTypeFactory, SegmentFactory
Expand Down Expand Up @@ -1079,6 +1080,17 @@ def test_get_current_user_with_unverified_required_location(self):
response = self.client.get(self.current_user_url, token=self.user_token)
self.assertEqual(response.json()['required'], [])

def test_get_current_user_with_initiatives(self):
InitiativeFactory.create(
owner=self.user
)
response = self.client.get(self.current_user_url, token=self.user_token)
self.assertEqual(response.json()['has_initiatives'], True)

def test_get_current_user_without_initiatives(self):
response = self.client.get(self.current_user_url, token=self.user_token)
self.assertEqual(response.json()['has_initiatives'], False)


class MemberSettingsAPITestCase(BluebottleTestCase):

Expand Down

0 comments on commit 99499dc

Please sign in to comment.