def test_policy_versioning(self): assert DataPrivacyPolicy.current_version() == 0 DataPrivacyPolicy.objects.create(content='Foo') assert DataPrivacyPolicy.current_version() == Decimal('1.0') DataPrivacyPolicy.objects.create(content='Foo1') assert DataPrivacyPolicy.current_version() == Decimal('2.0') DataPrivacyPolicy.objects.create(content='Foo2', version=Decimal('2.6')) assert DataPrivacyPolicy.current_version() == Decimal('2.6') DataPrivacyPolicy.objects.create(content='Foo3') assert DataPrivacyPolicy.current_version() == Decimal('3.0')
def test_list_view_current_version(self): baker.make(DataPrivacyPolicy, content='Foo', version=None) baker.make(DataPrivacyPolicy, content='Bar', version=None) latest = baker.make(DataPrivacyPolicy, content='FooBar', version=None) assert DataPrivacyPolicy.current() == latest resp = self.client.get(self.list_url) assert resp.context_data["current_version"] == latest.version
def dispatch(self, request, *args, **kwargs): # check if the user has an active disclaimer if DataPrivacyPolicy.current_version() > 0 and request.user.is_authenticated \ and not has_active_data_privacy_agreement(request.user): return HttpResponseRedirect( reverse('accounts:data_privacy_review') + '?next=' + request.path) return super().dispatch(request, *args, **kwargs)
def wrap(request, *args, **kwargs): if (DataPrivacyPolicy.current_version() > 0 and request.user.is_authenticated and not has_active_data_privacy_agreement(request.user)): return HttpResponseRedirect( reverse('accounts:data_privacy_review') + '?next=' + request.path) return view_func(request, *args, **kwargs)
def home(request): if DataPrivacyPolicy.current_version() > 0 and request.user.is_authenticated \ and not has_active_data_privacy_agreement(request.user): return HttpResponseRedirect( reverse('profile:data_privacy_review') + '?next=' + request.path ) reviews = Review.objects.filter(selected=True).order_by('-submission_date') return TemplateResponse( request, 'website/index.html', {'nav_section': 'home', 'testimonials': reviews} )
def page(request, page_name): page = get_object_or_404(Page, name=page_name) if not page.active and not request.user.is_staff: return HttpResponseRedirect(reverse(settings.PERMISSION_DENIED_URL)) if page.restricted: if request.user.is_anonymous: return HttpResponseRedirect( reverse('website:restricted_page_not_logged_in') ) elif not request.user.is_staff and not \ request.user.has_perm('website.can_view_restricted'): return HttpResponseRedirect(reverse(settings.PERMISSION_DENIED_URL)) elif ( DataPrivacyPolicy.current_version() > 0 and request.user.is_authenticated and not has_active_data_privacy_agreement(request.user) ): return HttpResponseRedirect( reverse('profile:data_privacy_review') + '?next=' + request.path ) template = TEMPLATES['no-img'] if page.pictures.count() > 0: template = TEMPLATES[page.layout] try: select_template( ['website/{}_extra.html'.format(page_name)] ) include_html = 'website/{}_extra.html'.format(page_name) except TemplateDoesNotExist: include_html = '' context = { 'page': page, 'include_html': include_html, 'nav_section': 'more' } return TemplateResponse(request, template, context)
def test_add_policy(self): DataPrivacyPolicy.objects.all().delete() self.client.post(reverse("studioadmin:add_data_privacy_policy"), {"content": "A new policy"}) assert DataPrivacyPolicy.objects.count() == 1 assert DataPrivacyPolicy.current().content == "A new policy"
def active_data_privacy_cache_key(user): from accounts.models import DataPrivacyPolicy current_version = DataPrivacyPolicy.current_version() return 'user_{}_active_data_privacy_agreement_version_{}'.format( user.id, current_version )
def test_cannot_make_new_version_with_same_content(self): DataPrivacyPolicy.objects.create(content='Foo') assert DataPrivacyPolicy.current_version() == Decimal('1.0') with pytest.raises(ValidationError): DataPrivacyPolicy.objects.create(content='Foo')
def test_no_policy_version(self): assert DataPrivacyPolicy.current_version() == 0
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["current_version"] = DataPrivacyPolicy.current_version() return context