def test_registration_requires_subscribe_choice_with_newsletter(self): options.set('auth.allow-registration', True) with self.feature('auth:register'): resp = self.client.post( self.path, { 'username': '******', 'password': '******', 'name': 'Foo Bar', 'op': 'register', } ) assert resp.status_code == 200 with self.feature('auth:register'): resp = self.client.post( self.path, { 'username': '******', 'password': '******', 'name': 'Foo Bar', 'op': 'register', 'subscribe': '0', } ) assert resp.status_code == 302 user = User.objects.get(username='******') assert user.email == '*****@*****.**' assert user.check_password('foobar') assert user.name == 'Foo Bar' assert not OrganizationMember.objects.filter( user=user, ).exists() assert newsletter.get_subscriptions(user) == {'subscriptions': []}
def manage_subscriptions(request): user = request.user email = UserEmail.get_primary_email(user) if request.method == 'GET': context = csrf(request) context.update({ 'page': 'subscriptions', 'email': email, 'AUTH_PROVIDERS': auth.get_auth_providers(), 'has_newsletters': newsletter.is_enabled, 'subscriptions': newsletter.get_subscriptions(user), }) return render_to_response('sentry/account/subscriptions.html', context, request) subscribed = request.POST.get('subscribed') == '1' try: list_id = int(request.POST.get('listId', '')) except ValueError: return HttpResponse('bad request', status=400) kwargs = { 'list_id': list_id, 'subscribed': subscribed, 'verified': email.is_verified, } if not subscribed: kwargs['unsubscribed_date'] = timezone.now() else: kwargs['subscribed_date'] = timezone.now() newsletter.create_or_update_subscription(user, **kwargs) return HttpResponse()
def test_registration_requires_subscribe_choice_with_newsletter(self): options.set('auth.allow-registration', True) with self.feature('auth:register'): resp = self.client.post( self.path, { 'username': '******', 'password': '******', 'name': 'Foo Bar', 'op': 'register', }) assert resp.status_code == 200 with self.feature('auth:register'): resp = self.client.post( self.path, { 'username': '******', 'password': '******', 'name': 'Foo Bar', 'op': 'register', 'subscribe': '0', }) assert resp.status_code == 302 user = User.objects.get( username='******') assert user.email == '*****@*****.**' assert user.check_password('foobar') assert user.name == 'Foo Bar' assert not OrganizationMember.objects.filter(user=user, ).exists() assert newsletter.get_subscriptions(user) == {'subscriptions': []}
def get(self, request, user): """ Retrieve Account Subscriptions ````````````````````````````````````` Return list of subscriptions for an account :auth: required """ # This returns a dict with `subscriber` and `subscriptions` # Returns `None` if no subscriptions for user sub = newsletter.get_subscriptions(user) if sub is None or not newsletter.is_enabled(): return self.respond([]) return self.respond([{ 'listId': x.get('list_id'), 'listDescription': x.get('list_description'), 'listName': x.get('list_name'), 'email': x.get('email'), 'subscribed': x.get('subscribed'), 'subscribedDate': x.get('subscribed_date'), 'unsubscribedDate': x.get('unsubscribed_date'), } for x in sub['subscriptions']])
def test_unsubscribe(self): self.get_valid_response(self.user.id, listId="123", subscribed=False, status_code=204) results = newsletter.get_subscriptions(self.user)["subscriptions"] assert len(results) == 1 assert results[0].list_id == 123 assert not results[0].subscribed assert results[0].verified
def test_default_subscription(self): self.get_valid_response(self.user.id, method="post", subscribed=True, status_code=204) results = newsletter.get_subscriptions(self.user)["subscriptions"] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert results[0].verified
def manage_subscriptions(request): user = request.user email = UserEmail.get_primary_email(user) if request.method == 'GET': context = csrf(request) context.update( { 'page': 'subscriptions', 'email': email, 'AUTH_PROVIDERS': auth.get_auth_providers(), 'has_newsletters': newsletter.is_enabled, 'subscriptions': newsletter.get_subscriptions(user), } ) return render_to_response('sentry/account/subscriptions.html', context, request) subscribed = request.POST.get('subscribed') == '1' try: list_id = int(request.POST.get('listId', '')) except ValueError: return HttpResponse('bad request', status=400) kwargs = { 'list_id': list_id, 'subscribed': subscribed, 'verified': email.is_verified, } if not subscribed: kwargs['unsubscribed_date'] = timezone.now() else: kwargs['subscribed_date'] = timezone.now() newsletter.create_or_update_subscription(user, **kwargs) return HttpResponse()
def test_registration_subscribe_to_newsletter(self): options.set("auth.allow-registration", True) with self.feature("auth:register"): resp = self.client.post( self.path, { "username": "******", "password": "******", "name": "Foo Bar", "op": "register", "subscribe": "1", }, ) assert resp.status_code == 302 user = User.objects.get( username="******") assert user.email == "*****@*****.**" assert user.check_password("foobar") assert user.name == "Foo Bar" results = newsletter.get_subscriptions(user)["subscriptions"] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert not results[0].verified
def get(self, request, user): """ Retrieve Account Subscriptions ````````````````````````````````````` Return list of subscriptions for an account :auth: required """ # This returns a dict with `subscriber` and `subscriptions` # Returns `None` if no subscriptions for user sub = newsletter.get_subscriptions(user) if sub is None or not newsletter.is_enabled(): return self.respond([]) return self.respond([{ "listId": x.get("list_id"), "listDescription": x.get("list_description"), "listName": x.get("list_name"), "email": x.get("email"), "subscribed": x.get("subscribed"), "subscribedDate": x.get("subscribed_date"), "unsubscribedDate": x.get("unsubscribed_date"), } for x in sub["subscriptions"]])
def test_registration_requires_subscribe_choice_with_newsletter(self): options.set("auth.allow-registration", True) with self.feature("auth:register"): resp = self.client.post( self.path, { "username": "******", "password": "******", "name": "Foo Bar", "op": "register", }, ) assert resp.status_code == 200 with self.feature("auth:register"): resp = self.client.post( self.path, { "username": "******", "password": "******", "name": "Foo Bar", "op": "register", "subscribe": "0", }, ) assert resp.status_code == 302 user = User.objects.get( username="******") assert user.email == "*****@*****.**" assert user.check_password("foobar") assert user.name == "Foo Bar" assert not OrganizationMember.objects.filter(user=user).exists() assert newsletter.get_subscriptions(user) == {"subscriptions": []}
def test_default_subscription(self): response = self.client.post(self.url, data={"subscribed": True}) assert response.status_code == 204, response.content results = newsletter.get_subscriptions(self.user)["subscriptions"] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert results[0].verified
def test_default_subscription(self): response = self.client.post(self.url, data={ 'subscribed': True, }) assert response.status_code == 204, response.content results = newsletter.get_subscriptions(self.user)['subscriptions'] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert results[0].verified
def test_unsubscribe(self): response = self.client.put(self.url, data={ 'listId': '123', 'subscribed': False, }) assert response.status_code == 204, response.content results = newsletter.get_subscriptions(self.user)['subscriptions'] assert len(results) == 1 assert results[0].list_id == 123 assert not results[0].subscribed assert results[0].verified
def test_update_subscriptions(self): response = self.client.put(self.url, data={ 'listId': '123', 'subscribed': True, }) assert response.status_code == 204, response.content results = newsletter.get_subscriptions(self.user)['subscriptions'] assert len(results) == 1 assert results[0].list_id == 123 assert results[0].subscribed assert results[0].verified
def test_add_secondary_email_with_newsletter_no_subscribe(self): response = self.client.post(self.url, data={ 'email': '*****@*****.**', 'newsletter': '0', }) assert response.status_code == 201 assert UserEmail.objects.filter( user=self.user, email='*****@*****.**').exists() assert newsletter.get_subscriptions(self.user) == {'subscriptions': []}
def test_unsubscribe(self): response = self.client.put(self.url, data={ "listId": "123", "subscribed": False }) assert response.status_code == 204, response.content results = newsletter.get_subscriptions(self.user)["subscriptions"] assert len(results) == 1 assert results[0].list_id == 123 assert not results[0].subscribed assert results[0].verified
def test_add_secondary_email_with_newsletter_subscribe(self): response = self.client.post(self.url, data={ 'email': '*****@*****.**', 'newsletter': '1', }) assert response.status_code == 201 assert UserEmail.objects.filter( user=self.user, email='*****@*****.**').exists() results = newsletter.get_subscriptions(self.user)['subscriptions'] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert not results[0].verified
def test_registration_subscribe_to_newsletter(self): options.set('auth.allow-registration', True) with self.feature('auth:register'): resp = self.client.post( self.path, { 'username': '******', 'password': '******', 'name': 'Foo Bar', 'op': 'register', 'subscribe': '1', } ) assert resp.status_code == 302 user = User.objects.get(username='******') assert user.email == '*****@*****.**' assert user.check_password('foobar') assert user.name == 'Foo Bar' results = newsletter.get_subscriptions(user)['subscriptions'] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert not results[0].verified
def test_registration_subscribe_to_newsletter(self): options.set('auth.allow-registration', True) with self.feature('auth:register'): resp = self.client.post( self.path, { 'username': '******', 'password': '******', 'name': 'Foo Bar', 'op': 'register', 'subscribe': '1', }) assert resp.status_code == 302 user = User.objects.get( username='******') assert user.email == '*****@*****.**' assert user.check_password('foobar') assert user.name == 'Foo Bar' results = newsletter.get_subscriptions(user)['subscriptions'] assert len(results) == 1 assert results[0].list_id == newsletter.get_default_list_id() assert results[0].subscribed assert not results[0].verified