コード例 #1
0
ファイル: test_forms.py プロジェクト: conkiztador/mytardis
    def test_ensures_suitable_license(self):
        suitableCombinations = (
            (Experiment.PUBLIC_ACCESS_NONE, ''),
            (Experiment.PUBLIC_ACCESS_METADATA, ''),
            (Experiment.PUBLIC_ACCESS_NONE, self.restrictiveLicense.id),
            (Experiment.PUBLIC_ACCESS_METADATA, self.restrictiveLicense.id),
            (Experiment.PUBLIC_ACCESS_FULL, self.permissiveLicense.id),
        )
        unsuitableCombinations = (
            (Experiment.PUBLIC_ACCESS_NONE, self.permissiveLicense.id),
            (Experiment.PUBLIC_ACCESS_METADATA, self.permissiveLicense.id),
            (Experiment.PUBLIC_ACCESS_METADATA, self.inactiveLicense.id),
            (Experiment.PUBLIC_ACCESS_FULL, self.inactiveLicense.id),
            (Experiment.PUBLIC_ACCESS_FULL, ''),
            (Experiment.PUBLIC_ACCESS_FULL, self.restrictiveLicense.id),
        )

        # Check we accept valid input
        for public_access, license_id in suitableCombinations:
            print "Suitable combination: %d %s" % (public_access, license_id)
            data = {'public_access': str(public_access),
                    'license': license_id }
            form = RightsForm(data)
            ensure(form.is_valid(), True, form.errors);

        # Check we reject invalid input
        for public_access, license_id in unsuitableCombinations:
            print "Unsuitable combination: %d %s" % (public_access, license_id)
            data = {'public_access': str(public_access),
                    'license': license_id }
            form = RightsForm(data)
            ensure(form.is_valid(), False);
コード例 #2
0
    def test_ensures_suitable_license(self):
        suitableCombinations = (
            (Experiment.PUBLIC_ACCESS_NONE, ''),
            (Experiment.PUBLIC_ACCESS_METADATA, ''),
            (Experiment.PUBLIC_ACCESS_NONE, self.restrictiveLicense.id),
            (Experiment.PUBLIC_ACCESS_METADATA, self.restrictiveLicense.id),
            (Experiment.PUBLIC_ACCESS_FULL, self.permissiveLicense.id),
        )
        unsuitableCombinations = (
            (Experiment.PUBLIC_ACCESS_NONE, self.permissiveLicense.id),
            (Experiment.PUBLIC_ACCESS_METADATA, self.permissiveLicense.id),
            (Experiment.PUBLIC_ACCESS_METADATA, self.inactiveLicense.id),
            (Experiment.PUBLIC_ACCESS_FULL, self.inactiveLicense.id),
            (Experiment.PUBLIC_ACCESS_FULL, ''),
            (Experiment.PUBLIC_ACCESS_FULL, self.restrictiveLicense.id),
        )

        # Check we accept valid input
        for public_access, license_id in suitableCombinations:
            print "Suitable combination: %d %s" % (public_access, license_id)
            data = {'public_access': str(public_access), 'license': license_id}
            form = RightsForm(data)
            ensure(form.is_valid(), True, form.errors)

        # Check we reject invalid input
        for public_access, license_id in unsuitableCombinations:
            print "Unsuitable combination: %d %s" % (public_access, license_id)
            data = {'public_access': str(public_access), 'license': license_id}
            form = RightsForm(data)
            ensure(form.is_valid(), False)
コード例 #3
0
def choose_rights(request, experiment_id):
    '''
    Choose access rights and licence.
    '''
    experiment = Experiment.objects.get(id=experiment_id)

    def is_valid_owner(owner):
        if not settings.REQUIRE_VALID_PUBLIC_CONTACTS:
            return True

        userProfile, created = UserProfile.objects.get_or_create(user=owner)

        return userProfile.isValidPublicContact()

    # Forbid access if no valid owner is available (and show error message)
    if not any([is_valid_owner(owner) for owner in experiment.get_owners()]):
        c = {'no_valid_owner': True, 'experiment': experiment}
        return HttpResponseForbidden(
            render_response_index(
                request, 'tardis_portal/ajax/unable_to_choose_rights.html', c))

    # Process form or prepopulate it
    if request.method == 'POST':
        form = RightsForm(request.POST)
        if form.is_valid():
            experiment.public_access = form.cleaned_data['public_access']
            experiment.license = form.cleaned_data['license']
            experiment.save()
    else:
        form = RightsForm({
            'public_access': experiment.public_access,
            'license': experiment.license_id
        })

    c = {'form': form, 'experiment': experiment}
    return HttpResponse(
        render_response_index(request, 'tardis_portal/ajax/choose_rights.html',
                              c))
コード例 #4
0
def choose_rights(request, experiment_id):
    '''
    Choose access rights and licence.
    '''
    experiment = Experiment.objects.get(id=experiment_id)

    def is_valid_owner(owner):
        if not settings.REQUIRE_VALID_PUBLIC_CONTACTS:
            return True

        userProfile, created = UserProfile.objects.get_or_create(
            user=owner)

        return userProfile.isValidPublicContact()

    # Forbid access if no valid owner is available (and show error message)
    if not any([is_valid_owner(owner) for owner in experiment.get_owners()]):
        c = {'no_valid_owner': True, 'experiment': experiment}
        return HttpResponseForbidden(render_response_index(
            request,
            'tardis_portal/ajax/unable_to_choose_rights.html', c))

    # Process form or prepopulate it
    if request.method == 'POST':
        form = RightsForm(request.POST)
        if form.is_valid():
            experiment.public_access = form.cleaned_data['public_access']
            experiment.license = form.cleaned_data['license']
            experiment.save()
    else:
        form = RightsForm({'public_access': experiment.public_access,
                           'license': experiment.license_id})

    c = {'form': form, 'experiment': experiment}
    return HttpResponse(render_response_index(request,
                        'tardis_portal/ajax/choose_rights.html', c))