예제 #1
0
def tethys_global_settings_context(request):
    """
    Add the current Tethys app metadata to the template context.
    """
    from .models import Setting
    from termsandconditions.models import TermsAndConditions

    # Get settings
    site_globals = Setting.as_dict()

    # Get terms and conditions

    # Grrr!!! TermsAndConditions has a different interface for Python 2 and 3
    try:
        # for Python 3
        site_globals.update(
            {'documents': TermsAndConditions.get_active_terms_list()})
    except AttributeError:
        # for Python 3
        site_globals.update(
            {'documents': TermsAndConditions.get_active_list(as_dict=False)})

    context = {'site_globals': site_globals}

    return context
예제 #2
0
파일: views.py 프로젝트: jrfreeze/portal
def termsandconditions(request):
    context = {
        'title': 'Terms and Conditions',
        'terms': TermsAndConditions.get_active(),
    }
    #context['terms'] = TermsAndConditions.get_active()
    return render(request, 'designsafe/apps/accounts/termsandconditions.html', context)
예제 #3
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        active_terms = TermsAndConditions.get_active_terms_list()

        if not self.request.user.is_anonymous:
            context['agreed_terms'] = TermsAndConditions.objects.filter(
                userterms__date_accepted__isnull=False,
                userterms__user=self.request.user).order_by('date_created')

            context['not_agreed_terms'] = active_terms.filter(
                Q(userterms=None) | \
                (Q(userterms__date_accepted__isnull=True) & Q(userterms__user=self.request.user)))\
                .order_by('date_created')
        else:
            context['active_terms'] = active_terms.order_by('date_created')

        context['extra_tabs'] = [{
            'login_required': False,
            'icon': 'file-contract',
            'title': "Terms and Conditions",
            'active': True,
        }]
        context['connect_fixed_tabs_with_extra_tabs'] = False

        return context
예제 #4
0
 def handle(self, *args, **options):
     active_terms = TermsAndConditions.get_active_terms_list()
     for term in active_terms:
         old_accepts = UserTermsAndConditions.objects.filter(
             terms__slug=term.slug).exclude(terms__pk=term.pk)
         logger.debug(
             f"About to delete these old terms accepts: {old_accepts}")
         old_accepts.delete()
예제 #5
0
    def process_request(self, request):
        """Process each request to app to ensure terms have been accepted"""
        current_path = request.META['PATH_INFO']
        protected_path = is_path_protected(current_path)

        if request.user.is_authenticated and protected_path:
            for term in TermsAndConditions.get_active_list():
                if not TermsAndConditions.agreed_to_latest(request.user, term):
                    accept_url = getattr(settings, 'ACCEPT_TERMS_PATH',
                                         '/terms/accept/') + term
                    messages.warning(
                        request, '<h4>Please Accept the Terms of Use</h4>'
                        'You have not yet agreed to the current Terms of Use. '
                        'Please <a href="%s">CLICK HERE</a> to review and '
                        'accept the Terms of Use.<br>Acceptance of the Terms of '
                        'Use is required for continued use of the portal '
                        'resources.' % accept_url)
        return None
예제 #6
0
    def process_request(self, request):
        """Process each request to app to ensure terms have been accepted"""
        current_path = request.META['PATH_INFO']
        protected_path = is_path_protected(current_path)

        if request.user.is_authenticated() and protected_path:
            for term in TermsAndConditions.get_active_list():
                if not TermsAndConditions.agreed_to_latest(request.user, term):
                    accept_url = getattr(settings, 'ACCEPT_TERMS_PATH',
                                         '/terms/accept/') + term
                    messages.warning(
                        request, '<h4>Please Accept the Terms of Use</h4>'
                                 'You have not yet agreed to the current Terms of Use. '
                                 'Please <a href="%s">CLICK HERE</a> to review and '
                                 'accept the Terms of Use.<br>Acceptance of the Terms of '
                                 'Use is required for continued use of DesignSafe '
                                 'resources.' % accept_url)
        return None
예제 #7
0
    def __init__(self, data=None, slug='default', initial=None, *args, **kwargs):
        """Lets you pass in a user= to bind this form from"""
        if initial is None:
            terms = TermsAndConditions.get_active(slug)
            text = terms.text
            slug = terms.slug
            version_number = terms.version_number

            initial = dict(text=text, slug=slug, version_number=version_number)

        super(TermsAndConditionsForm, self).__init__(data=data, initial=initial)
예제 #8
0
    def __init__(self, *args, **kwargs):
        kwargs.pop('instance', None)

        terms_list = kwargs.get('initial', {}).get('terms', None)

        if terms_list is None:  # pragma: nocover
            terms_list = TermsAndConditions.get_active_terms_list()

        self.terms = forms.ModelMultipleChoiceField(
            terms_list, widget=forms.MultipleHiddenInput)

        super(UserTermsAndConditionsModelForm, self).__init__(*args, **kwargs)
예제 #9
0
    def save(self, source='DesignSafe', pi_eligibility=INELIGIBLE):
        data = self.cleaned_data
        data['source'] = source
        data['piEligibility'] = pi_eligibility

        safe_data = data.copy()
        safe_data['password'] = safe_data['confirmPassword'] = '******'

        logger.info('Attempting new user registration: %s' % safe_data)
        tas_user = TASClient().save_user(None, data)

        # create local user
        UserModel = get_user_model()
        try:
            # the user should not exist
            user = UserModel.objects.get(username=data['username'])
            logger.warning('On TAS registration, local user already existed? '
                           'user=%s' % user)
        except UserModel.DoesNotExist:
            user = UserModel.objects.create_user(
                username=data['username'],
                first_name=tas_user['firstName'],
                last_name=tas_user['lastName'],
                email=tas_user['email'],
                agree_to_account_limit=data['agree_to_account_limit'])

        # extended profile information
        try:
            # again, this should not exist
            ds_profile = DesignSafeProfile.objects.get(user=user)
            ds_profile.ethnicity = data['ethnicity']
            ds_profile.gender = data['gender']
        except DesignSafeProfile.DoesNotExist:
            ds_profile = DesignSafeProfile(user=user,
                                           ethnicity=data['ethnicity'],
                                           gender=data['gender'])
        ds_profile.save()

        # terms of use
        logger.info(
            'Prior to Registration, %s %s <%s> agreed to Terms of Use' %
            (data['firstName'], data['lastName'], data['email']))
        try:
            terms = TermsAndConditions.get_active()
            user_terms = UserTermsAndConditions(user=user, terms=terms)
            user_terms.save()
        except:
            logger.exception('Error saving UserTermsAndConditions for user=%s',
                             user)

        return tas_user
예제 #10
0
    def save(self, source='DesignSafe', pi_eligibility=INELIGIBLE):
        data = self.cleaned_data
        data['source'] = source
        data['piEligibility'] = pi_eligibility

        safe_data = data.copy()
        safe_data['password'] = safe_data['confirmPassword'] = '******'

        logger.info('Attempting new user registration: %s' % safe_data)
        tas_user = TASClient().save_user(None, data)

        # create local user
        UserModel = get_user_model()
        try:
            # the user should not exist
            user = UserModel.objects.get(username=data['username'])
            logger.warning('On TAS registration, local user already existed? '
                           'user=%s' % user)
        except UserModel.DoesNotExist:
            user = UserModel.objects.create_user(
                username=data['username'],
                first_name=tas_user['firstName'],
                last_name=tas_user['lastName'],
                email=tas_user['email'],
                )

        # extended profile information
        try:
            # again, this should not exist
            ds_profile = DesignSafeProfile.objects.get(user=user)
            ds_profile.ethnicity = data['ethnicity']
            ds_profile.gender = data['gender']
        except DesignSafeProfile.DoesNotExist:
            ds_profile = DesignSafeProfile(
                user=user,
                ethnicity=data['ethnicity'],
                gender=data['gender']
                )
        ds_profile.save()

        # terms of use
        logger.info('Prior to Registration, %s %s <%s> agreed to Terms of Use' % (
            data['firstName'], data['lastName'], data['email']))
        try:
            terms = TermsAndConditions.get_active()
            user_terms = UserTermsAndConditions(user=user, terms=terms)
            user_terms.save()
        except:
            logger.exception('Error saving UserTermsAndConditions for user=%s', user)

        return tas_user
예제 #11
0
def tethys_global_settings_context(request):
    """
    Add the current Tethys app metadata to the template context.
    """
    from .models import Setting
    from termsandconditions.models import TermsAndConditions

    # Get settings
    site_globals = Setting.as_dict()

    # Get terms and conditions
    site_globals.update({'documents': TermsAndConditions.get_active_list(as_dict=False)})
    context = {'site_globals': site_globals}

    return context
예제 #12
0
    def __init__(self, *args, **kwargs):
        kwargs.pop("instance", None)

        terms_list = kwargs.get("initial", {}).get("terms", None)

        if terms_list is None:  # pragma: nocover
            terms_list = TermsAndConditions.get_active_terms_list()

        if terms_list is QuerySet:
            self.terms = forms.ModelMultipleChoiceField(
                terms_list, widget=forms.MultipleHiddenInput)
        else:
            self.terms = terms_list

        super().__init__(*args, **kwargs)
예제 #13
0
def tethys_global_settings_context(request):
    """
    Add the current Tethys app metadata to the template context.
    """
    from .models import Setting
    from termsandconditions.models import TermsAndConditions

    # Get settings
    site_globals = Setting.as_dict()

    # Get terms and conditions
    site_globals.update(
        {'documents': TermsAndConditions.get_active_list(as_dict=False)})
    context = {'site_globals': site_globals}

    return context
예제 #14
0
    def __init__(self, *args, **kwargs):
        kwargs.pop('instance', None)

        terms_list = kwargs.get('initial', {}).get('terms', None)

        if terms_list is None:  # pragma: nocover
            terms_list = TermsAndConditions.get_active_terms_list()

        if terms_list is QuerySet:
            self.terms = forms.ModelMultipleChoiceField(
                terms_list,
                widget=forms.MultipleHiddenInput
            )
        else:
            self.terms = terms_list

        super(UserTermsAndConditionsModelForm, self).__init__(*args, **kwargs)
예제 #15
0
    def test_accept(self):
        """Validate that accepting terms works"""

        LOGGER.debug('Test user1 login for accept')
        login_response = self.c.login(username='******', password='******')
        self.assertTrue(login_response)

        LOGGER.debug('Test /terms/accept/ get')
        logged_in_response = self.c.get('/terms/accept/', follow=True)
        self.assertContains(logged_in_response, "Accept")

        LOGGER.debug('Test /terms/accept/ post')
        logged_in_response = self.c.post('/terms/accept/',
                {'slug': 'site-terms', 'version_number': '2.00', 'returnTo': '/secure/'}, follow=True)
        LOGGER.debug(logged_in_response)
        self.assertContains(logged_in_response, "Contributor")

        self.assertEquals(True, TermsAndConditions.agreed_to_latest(user=self.user1, slug='site-terms'))
예제 #16
0
    def __init__(self, *args, **kwargs):
        if 'instance' in kwargs:
            kwargs.pop('instance')

        terms_list = None

        if 'initial' in kwargs:
            initial = kwargs.get('initial')

            if 'terms' in initial:
                terms_list = initial.get('terms')

        if terms_list is None:
            terms_list = TermsAndConditions.get_active_list(as_dict=False)

        self.terms = forms.ModelMultipleChoiceField(
            terms_list,
            widget=forms.MultipleHiddenInput)

        super(UserTermsAndConditionsModelForm, self).__init__(*args, **kwargs)
예제 #17
0
    def test_terms_and_conditions_models(self):
        """Various tests of the TermsAndConditions Module"""

        # Testing Direct Assignment of Acceptance
        UserTermsAndConditions.objects.create(user=self.user1, terms=self.terms1)
        UserTermsAndConditions.objects.create(user=self.user2, terms=self.terms3)

        self.assertEquals(1.0, self.user1.userterms.get().terms.version_number)
        self.assertEquals(1.5, self.user2.userterms.get().terms.version_number)

        self.assertEquals('user1', self.terms1.users.all()[0].username)

        # Testing the get_active static method of TermsAndConditions
        self.assertEquals(2.0, TermsAndConditions.get_active(slug='site-terms').version_number)
        self.assertEquals(1.5, TermsAndConditions.get_active(slug='contrib-terms').version_number)

        # Testing the agreed_to_latest static method of TermsAndConditions
        self.assertEquals(False, TermsAndConditions.agreed_to_latest(user=self.user1, slug='site-terms'))
        self.assertEquals(True, TermsAndConditions.agreed_to_latest(user=self.user2, slug='contrib-terms'))

        # Testing the unicode method of TermsAndConditions
        self.assertEquals('site-terms-2.00', str(TermsAndConditions.get_active(slug='site-terms')))
        self.assertEquals('contrib-terms-1.50', str(TermsAndConditions.get_active(slug='contrib-terms')))
예제 #18
0
 def test_get_active_list(self):
     active_list = TermsAndConditions.get_active_list()
     LOGGER.debug('Active Terms: ' + str(active_list))
     self.assertEqual(2, len(active_list))
예제 #19
0
 def test_termsandconditions_get_active(self):
     """test if right terms are active"""
     active = TermsAndConditions.get_active()
     self.assertEqual(active.slug, self.terms_1.slug)
     self.assertEqual(active.version_number, self.terms_1.version_number)
     self.assertNotEqual(active.version_number, self.terms_2.version_number)
예제 #20
0
    def save(self, source='DesignSafe', pi_eligibility=INELIGIBLE):
        data = self.cleaned_data
        data['source'] = source
        data['piEligibility'] = pi_eligibility

        #pull out specific fields from data for tas and pro profile
        tas_keys = [
            'firstName', 'lastName', 'email', 'confirmEmail', 'phone',
            'institutionId', 'departmentId', 'institution', 'title',
            'countryId', 'citizenshipId', 'ethnicity', 'gender', 'source',
            'piEligibility', 'username', 'password', 'confirmPassword',
            'agree_to_terms', 'agree_to_account_limit'
        ]
        pro_profile_fields = [
            'nh_interests', 'nh_interests_primary', 'nh_technical_domains',
            'bio', 'website', 'orcid_id', 'professional_level',
            'research_activities'
        ]
        pro_profile_data = {}
        tas_data = {}
        for key in data:
            if key in tas_keys:
                tas_data[key] = data[key]
            if key in pro_profile_fields:
                pro_profile_data[key] = data[key]

        safe_data = tas_data.copy()
        safe_data['password'] = safe_data['confirmPassword'] = '******'

        LOGGER.info('Attempting new user registration: %s' % safe_data)
        tas_user = TASClient().save_user(None, tas_data)

        # create local user
        UserModel = get_user_model()
        try:
            # the user should not exist
            user = UserModel.objects.get(username=data['username'])
            LOGGER.warning('On TAS registration, local user already existed? '
                           'user=%s' % user)
        except UserModel.DoesNotExist:
            user = UserModel.objects.create_user(
                username=data['username'],
                first_name=tas_user['firstName'],
                last_name=tas_user['lastName'],
                email=tas_user['email'])

        # extended profile information
        try:
            # again, this should not exist
            ds_profile = DesignSafeProfile.objects.get(user=user)
            ds_profile.ethnicity = data['ethnicity']
            ds_profile.gender = data['gender']
            ds_profile.bio = data['bio']
            ds_profile.website = data['website']
            ds_profile.orcid_id = data['orcid_id']
            ds_profile.professional_level = data['professional_level']
            ds_profile.update_required = False
        except DesignSafeProfile.DoesNotExist:
            ds_profile = DesignSafeProfile(
                user=user,
                ethnicity=data['ethnicity'],
                gender=data['gender'],
                bio=data['bio'],
                website=data['website'],
                orcid_id=data['orcid_id'],
                professional_level=data['professional_level'],
                update_required=False)
        ds_profile.save()

        #save professional profile information
        pro_profile = ProfessionalProfileForm(instance=ds_profile)
        pro_profile.cleaned_data = pro_profile_data
        pro_profile.save()

        # terms of use
        LOGGER.info(
            'Prior to Registration, %s %s <%s> agreed to Terms of Use' %
            (data['firstName'], data['lastName'], data['email']))
        try:
            terms = TermsAndConditions.get_active()
            user_terms = UserTermsAndConditions(user=user, terms=terms)
            user_terms.save()
        except:
            LOGGER.exception('Error saving UserTermsAndConditions for user=%s',
                             user)

        return tas_user