def _create_test_data():
    """
    Create Single experiment with two owners
    """
    user1 = User(username='******',
                 first_name='Thomas',
                 last_name='Atkins',
                 email='*****@*****.**')
    user1.save()
    UserProfile(user=user1).save()

    user2 = User(username='******',
                 first_name='Joe',
                 last_name='Bloggs',
                 email='*****@*****.**')
    user2.save()
    UserProfile(user=user2).save()

    license_ = License(name='Creative Commons Attribution-NoDerivs ' +
                       '2.5 Australia',
                       url='http://creativecommons.org/licenses/by-nd/2.5/au/',
                       internal_description='CC BY 2.5 AU',
                       allows_distribution=True)
    license_.save()
    experiment = Experiment(title='Norwegian Blue',
                            description='Parrot + 40kV',
                            created_by=user1)
    experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
    experiment.license = license_
    experiment.save()
    experiment.author_experiment_set.create(
        order=0, author="John Cleese", url="http://nla.gov.au/nla.party-1")
    experiment.author_experiment_set.create(
        order=1, author="Michael Palin", url="http://nla.gov.au/nla.party-2")

    acl1 = ExperimentACL(experiment=experiment,
                         pluginId='django_user',
                         entityId=str(user1.id),
                         isOwner=True,
                         canRead=True,
                         canWrite=True,
                         canDelete=True,
                         aclOwnershipType=ExperimentACL.OWNER_OWNED)
    acl1.save()

    acl2 = ExperimentACL(experiment=experiment,
                         pluginId='django_user',
                         entityId=str(user2.id),
                         isOwner=True,
                         canRead=True,
                         canWrite=True,
                         canDelete=True,
                         aclOwnershipType=ExperimentACL.OWNER_OWNED)
    acl2.save()

    return (user1, user2, experiment)
Exemplo n.º 2
0
def _create_test_data():
    user = User(username='******',
                first_name='Thomas',
                last_name='Atkins',
                email='*****@*****.**')
    user.save()
    user2 = User(username='******', email='*****@*****.**')
    user2.save()
    map(lambda u: UserProfile(user=u).save(), [user, user2])
    license_ = License(name='Creative Commons Attribution-NoDerivs 2.5 Australia',
                       url='http://creativecommons.org/licenses/by-nd/2.5/au/',
                       internal_description='CC BY 2.5 AU',
                       allows_distribution=True)
    license_.save()
    experiment = Experiment(title='Norwegian Blue',
                            description='Parrot + 40kV',
                            created_by=user)
    experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
    experiment.license = license_
    experiment.save()
    acl = ExperimentACL(experiment=experiment,
                    pluginId='django_user',
                    entityId=str(user2.id),
                    isOwner=True,
                    canRead=True,
                    canWrite=True,
                    canDelete=True,
                    aclOwnershipType=ExperimentACL.OWNER_OWNED)
    acl.save()
    return (user, experiment)
Exemplo n.º 3
0
 def _get_experiment(self, entry, user):
     experimentId, title, public_access = \
         self._get_experiment_details(entry, user)
     try:
         try:
             param_name = ParameterName.objects.\
                 get(name=self.PARAM_EXPERIMENT_ID, \
                     schema=AtomImportSchemas.get_schema(Schema.EXPERIMENT))
             parameter = ExperimentParameter.objects.\
                 get(name=param_name, string_value=experimentId)
         except ExperimentParameter.DoesNotExist:
             raise Experiment.DoesNotExist
         return parameter.parameterset.experiment
     except Experiment.DoesNotExist:
         experiment = Experiment(title=title,
                                 created_by=user,
                                 public_access=public_access)
         experiment.save()
         self._create_experiment_id_parameter_set(experiment, experimentId)
         acl = ExperimentACL(experiment=experiment,
                             pluginId=django_user,
                             entityId=user.id,
                             canRead=True,
                             canWrite=True,
                             canDelete=True,
                             isOwner=True,
                             aclOwnershipType=ExperimentACL.OWNER_OWNED)
         acl.save()
         return experiment
Exemplo n.º 4
0
    def testCantEditLockedExperiment(self):
        login = self.client3.login(username=self.user3.username,
                                   password='******')
        self.assertTrue(login)

        # user3 has acl to write to experiment3
        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(self.user3.id),
            experiment=self.experiment3,
            canRead=True,
            canWrite=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
        )
        acl.save()

        response = self.client3.get('/experiment/edit/%i/' %
                                    (self.experiment3.id))
        self.assertEqual(response.status_code, 403)

        response = self.client3.post(
            '/experiment/edit/%i/' % (self.experiment3.id), {
                'anything': True,
            })
        self.assertEqual(response.status_code, 403)

        acl.delete()
        self.client3.logout()
Exemplo n.º 5
0
    def setUp(self):
        from os import path, mkdir
        from tempfile import mkdtemp

        user = '******'
        pwd = 'secret'
        email = ''
        self.user = User.objects.create_user(user, email, pwd)

        self.userProfile = UserProfile(user=self.user)

        self.test_dir = mkdtemp()

        self.exp = Experiment(title='test exp1',
                              institution_name='monash',
                              created_by=self.user)
        self.exp.save()

        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(self.user.id),
            experiment=self.exp,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
        )
        acl.save()

        self.dataset = \
            Dataset(description='dataset description...')
        self.dataset.save()
        self.dataset.experiments.add(self.exp)
        self.dataset.save()

        self.experiment_path = path.join(
            settings.FILE_STORE_PATH,
            str(self.dataset.get_first_experiment().id))

        self.dataset_path = path.join(self.experiment_path,
                                      str(self.dataset.id))

        if not path.exists(self.experiment_path):
            mkdir(self.experiment_path)
        if not path.exists(self.dataset_path):
            mkdir(self.dataset_path)

        # write test file

        self.filename = 'testfile.txt'

        self.f1 = open(path.join(self.test_dir, self.filename), 'w')
        self.f1.write('Test file 1')
        self.f1.close()

        self.f1_size = path.getsize(path.join(self.test_dir, self.filename))

        self.f1 = open(path.join(self.test_dir, self.filename), 'r')
Exemplo n.º 6
0
 def create_experiment(i):
     experiment = Experiment(title='Text Experiment #%d' % i,
                             institution_name='Test Uni',
                             created_by=user)
     experiment.save()
     acl = ExperimentACL(
         pluginId=django_user,
         entityId=str(user.id),
         experiment=experiment,
         canRead=True,
         isOwner=True,
         aclOwnershipType=ExperimentACL.OWNER_OWNED,
     )
     acl.save()
     return experiment
Exemplo n.º 7
0
    def setUp(self):
        self.ns = {
            'r': 'http://ands.org.au/standards/rif-cs/registryObjects',
            'o': 'http://www.openarchives.org/OAI/2.0/'
        }
        user, client = _create_user_and_login()

        license_ = License(
            name='Creative Commons Attribution-NoDerivs 2.5 Australia',
            url='http://creativecommons.org/licenses/by-nd/2.5/au/',
            internal_description='CC BY 2.5 AU',
            allows_distribution=True)
        license_.save()
        experiment = Experiment(title='Norwegian Blue',
                                description='Parrot + 40kV',
                                created_by=user)
        experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
        experiment.license = license_
        experiment.save()
        acl = ExperimentACL(experiment=experiment,
                            pluginId='django_user',
                            entityId=str(user.id),
                            isOwner=False,
                            canRead=True,
                            canWrite=True,
                            canDelete=False,
                            aclOwnershipType=ExperimentACL.OWNER_OWNED)
        acl.save()

        params = {
            'type': 'website',
            'identifier': 'https://www.google.com/',
            'title': 'Google',
            'notes': 'This is a note.'
        }
        response = client.post(\
                    reverse('tardis.apps.related_info.views.'\
                            +'list_or_create_related_info',
                            args=[experiment.id]),
                    data=json.dumps(params),
                    content_type='application/json')
        # Check related info was created
        expect(response.status_code).to_equal(201)

        self.acl = acl
        self.client = client
        self.experiment = experiment
        self.params = params
Exemplo n.º 8
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser',
                                     '*****@*****.**',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ExperimentACL(
            pluginId='django_user',
            entityId=str(user.id),
            experiment=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
            )
        acl.save()

        dataset = Dataset(description='dataset description...')
        dataset.save()
        dataset.experiments.add(experiment)
        dataset.save()

        def create_datafile(index):
            testfile = path.join(path.dirname(__file__), 'fixtures',
                                 'jeol_sem_test%d.txt' % index)

            size, sha512sum = get_size_and_sha512sum(testfile)

            datafile = Dataset_File(dataset=dataset,
                                    filename=path.basename(testfile),
                                    url='file://'+path.abspath(testfile),
                                    protocol='file',
                                    size=size,
                                    sha512sum=sha512sum)
            datafile.verify()
            datafile.save()
            return datafile

        self.dataset = dataset
        self.datafiles = [create_datafile(i) for i in (1,2)]
Exemplo n.º 9
0
    def setUp(self):
        user, client = _create_user_and_login()

        experiment = Experiment(title='Norwegian Blue',
                                description='Parrot + 40kV',
                                created_by=user)
        experiment.save()
        acl = ExperimentACL(experiment=experiment,
                            pluginId='django_user',
                            entityId=str(user.id),
                            isOwner=False,
                            canRead=True,
                            canWrite=False,
                            canDelete=False,
                            aclOwnershipType=ExperimentACL.OWNER_OWNED)
        acl.save()
        self.client = client
        self.experiment = experiment
Exemplo n.º 10
0
    def setUp(self):
        # Create test owner without enough details
        username, email, password = ('testuser', '*****@*****.**',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()
        # Need UserAuthentication
        UserAuthentication(userProfile=profile,
                           username=username,
                           authenticationMethod='localdb').save()
        # Create staging dir
        from os import path, makedirs
        staging_dir = path.join(settings.STAGING_PATH, username)
        if not path.exists(staging_dir):
            makedirs(staging_dir)
        # Ensure that staging dir is set up properly
        expect(get_full_staging_path(username)).to_be_truthy()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(user.id),
            experiment=experiment,\

            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
            )
        acl.save()

        self.dataset = \
            Dataset(description='dataset description...')
        self.dataset.save()
        self.dataset.experiments.add(experiment)
        self.dataset.save()

        self.username, self.password = (username, password)
Exemplo n.º 11
0
    def testRightsRequireValidOwner(self):
        # Create test owner without enough details
        username, email, password = ('testuser', '*****@*****.**',
                                     'password')
        user = User.objects.create_user(username, email, password)
        profile = UserProfile(user=user, isDjangoAccount=True)
        profile.save()

        # Create test experiment and make user the owner of it
        experiment = Experiment(title='Text Experiment',
                                institution_name='Test Uni',
                                created_by=user)
        experiment.save()
        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(user.id),
            experiment=experiment,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
        )
        acl.save()

        # Create client and login as user
        client = Client()
        login = client.login(username=username, password=password)
        self.assertTrue(login)

        # Get "Choose Rights" page, and check that we're forbidden
        rights_url = reverse('tardis.tardis_portal.views.choose_rights',
                             args=[str(experiment.id)])
        response = client.get(rights_url)
        expect(response.status_code).to_equal(403)

        # Fill in remaining details
        user.first_name = "Voltaire"  # Mononymous persons are just fine
        user.save()

        # Get "Choose Rights" page, and check that we're now allowed access
        response = client.get(rights_url)
        expect(response.status_code).to_equal(200)
Exemplo n.º 12
0
def _create_test_experiment(user, license_):
    experiment = Experiment(title='Norwegian Blue',
                            description='Parrot + 40kV',
                            created_by=user)
    experiment.public_access = Experiment.PUBLIC_ACCESS_FULL
    experiment.license = license_
    experiment.save()
    experiment.author_experiment_set.create(
        order=0, author="John Cleese", url="http://nla.gov.au/nla.party-1")
    experiment.author_experiment_set.create(
        order=1, author="Michael Palin", url="http://nla.gov.au/nla.party-2")
    acl = ExperimentACL(experiment=experiment,
                        pluginId='django_user',
                        entityId=str(user.id),
                        isOwner=True,
                        canRead=True,
                        canWrite=True,
                        canDelete=True,
                        aclOwnershipType=ExperimentACL.OWNER_OWNED)
    acl.save()
    return experiment
Exemplo n.º 13
0
def _create_datafile():
    user = User.objects.create_user('testuser', '*****@*****.**', 'pwd')
    user.save()
    UserProfile(user=user).save()
    full_access = Experiment.PUBLIC_ACCESS_FULL
    experiment = Experiment.objects.create(title="IIIF Test",
                                           created_by=user,
                                           public_access=full_access)
    experiment.save()
    ExperimentACL(experiment=experiment,
                  pluginId='django_user',
                  entityId=str(user.id),
                  isOwner=True,
                  canRead=True,
                  canWrite=True,
                  canDelete=True,
                  aclOwnershipType=ExperimentACL.OWNER_OWNED).save()
    dataset = Dataset()
    dataset.save()
    dataset.experiments.add(experiment)
    dataset.save()

    # Create new Datafile
    tempfile = TemporaryUploadedFile('iiif_stored_file', None, None, None)
    with Image(filename='magick:rose') as img:
        img.format = 'tiff'
        img.save(file=tempfile.file)
        tempfile.file.flush()
    datafile = Dataset_File(dataset=dataset)
    datafile.size = os.path.getsize(tempfile.file.name)
    #os.remove(tempfilename)
    datafile.filename = 'iiif_named_file'
    datafile.url = write_uploaded_file_to_dataset(dataset, tempfile)
    datafile.verify(allowEmptyChecksums=True)
    datafile.save()
    return datafile
Exemplo n.º 14
0
def createhpcexperiment(request, user, dl):

    from django.contrib.auth.models import User
    from tardis.tardis_portal.views import _registerExperimentDocument
    import os
    import tempfile

    #TODO
    temp = tempfile.TemporaryFile()
    for chunk in dl.chunks():
        temp.write(chunk)
    temp.seek(0)

    metadata = {}

    for line in temp:
        key, value = line.split('~')
        metadata[key] = value
    temp.close()

    author = metadata['Name']
    title = metadata['Experiment']
    ds_desc = metadata['Facility']
    desc = metadata['Description']
    fname = metadata['FolderName']
    counter = metadata['Counter']
    package = metadata['Package']

    exp = Experiment(
        title=title,
        institution_name="RMIT University",
        description=desc,
        created_by=User.objects.get(id=user.pk),
    )
    exp.save()
    eid = exp.id
    # Store the author for the dataset
    ae = models.Author_Experiment(experiment=exp, author=author, order='1')
    ae.save()

    auth_key = settings.DEFAULT_AUTH

    try:
        e = Experiment.objects.get(pk=eid)
    except Experiment.DoesNotExist:
        logger.exception(
            'Experiment for eid %i in CreateHPCExperiment does not exist' %
            eid)

    acl = ExperimentACL(experiment=e,
                        pluginId=django_user,
                        entityId=str(user.id),
                        canRead=True,
                        canWrite=True,
                        canDelete=True,
                        isOwner=True,
                        aclOwnershipType=ExperimentACL.OWNER_OWNED)
    acl.save()

    folder_desc = "%s.%s.%s.%s" % (ds_desc.strip(), package.strip(),
                                   fname.strip(), counter.strip())
    logger.debug('folder_desc = %s' % folder_desc)
    return eid, exp, folder_desc
Exemplo n.º 15
0
    def setUp(self):

        # create a couple of test users
        self.user1 = User.objects.create_user('testuser1', '', 'secret')
        self.user2 = User.objects.create_user('testuser2', '', 'secret')
        self.user3 = User.objects.create_user('testuser3', '', 'secret')
        self.user4 = User.objects.create_user('testuser4', '', 'secret')

        # with standard permissions
        for user in [self.user1, self.user2, self.user3, self.user4]:
            user.user_permissions.add(
                Permission.objects.get(codename='add_experiment'))
            user.user_permissions.add(
                Permission.objects.get(codename='change_experiment'))
            user.user_permissions.add(
                Permission.objects.get(codename='change_group'))
            user.user_permissions.add(
                Permission.objects.get(codename='change_userauthentication'))
            user.user_permissions.add(
                Permission.objects.get(codename='change_experimentacl'))

        self.userProfile1 = UserProfile(user=self.user1)
        self.userProfile2 = UserProfile(user=self.user2)
        self.userProfile3 = UserProfile(user=self.user3)
        self.userProfile4 = UserProfile(user=self.user4)

        # each user will have their own client
        self.client1 = Client()
        self.client2 = Client()
        self.client3 = Client()
        self.client4 = Client()

        # user1 will own experiment1
        self.experiment1 = Experiment(
            title='Experiment1',
            institution_name='Australian Synchrotron',
            approved=True,
            public_access=Experiment.PUBLIC_ACCESS_NONE,
            created_by=self.user1,
        )
        self.experiment1.save()

        # user2 will own experiment2
        self.experiment2 = Experiment(
            title='Experiment2',
            institution_name='Australian Synchrotron',
            approved=True,
            public_access=Experiment.PUBLIC_ACCESS_NONE,
            created_by=self.user2,
        )
        self.experiment2.save()

        # experiment3 is public & locked
        self.experiment3 = Experiment(
            title='Experiment3',
            institution_name='Australian Synchrotron',
            approved=True,
            locked=True,
            public_access=Experiment.PUBLIC_ACCESS_FULL,
            created_by=self.user3,
        )
        self.experiment3.save()

        # experiment4 will be accessible based on location information
        self.experiment4 = Experiment(
            title='Experiment4',
            institution_name='Australian Synchrotron',
            approved=True,
            public_access=Experiment.PUBLIC_ACCESS_NONE,
            created_by=self.user1,
        )
        self.experiment4.save()

        # user1 owns experiment1
        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(self.user1.id),
            experiment=self.experiment1,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
        )
        acl.save()

        # user2 owns experiment2
        acl = ExperimentACL(
            pluginId=django_user,
            entityId=str(self.user2.id),
            experiment=self.experiment2,
            canRead=True,
            isOwner=True,
            aclOwnershipType=ExperimentACL.OWNER_OWNED,
        )
        acl.save()

        # experiment4 is accessible via location
        acl = ExperimentACL(
            pluginId='ip_address',
            entityId='127.0.0.1',
            experiment=self.experiment4,
            canRead=True,
            aclOwnershipType=ExperimentACL.SYSTEM_OWNED,
        )
        acl.save()
def _registerExperimentDocument(filename,
                                created_by,
                                expid=None,
                                owners=[],
                                username=None):
    '''
    Register the experiment document and return the experiment id.

    :param filename: path of the document to parse (METS or notMETS)
    :type filename: string
    :param created_by: a User instance
    :type created_by: :py:class:`django.contrib.auth.models.User`
    :param expid: the experiment ID to use
    :type expid: int
    :param owners: a list of owners
    :type owner: list
    :param username: **UNUSED**
    :rtype: int

    '''

    f = open(filename)
    firstline = f.readline()
    f.close()

    sync_root = ''
    if firstline.startswith('<experiment'):
        logger.debug('processing simple xml')
        processExperiment = ProcessExperiment()
        eid, sync_root = processExperiment.process_simple(
            filename, created_by, expid)
    else:
        logger.debug('processing METS')
        eid, sync_root = parseMets(filename, created_by, expid)

    auth_key = ''
    try:
        auth_key = settings.DEFAULT_AUTH
    except AttributeError:
        logger.error('no default authentication for experiment' +
                     ' ownership set (settings.DEFAULT_AUTH)')

    force_user_create = False
    try:
        force_user_create = settings.DEFAULT_AUTH_FORCE_USER_CREATE
    except AttributeError:
        pass

    if auth_key:
        for owner in owners:
            # for each PI
            if not owner:
                continue

            owner_username = None
            if '@' in owner:
                owner_username = auth_service.getUsernameByEmail(
                    auth_key, owner)
            if not owner_username:
                owner_username = owner

            owner_user = auth_service.getUser(
                auth_key, owner_username, force_user_create=force_user_create)
            # if exist, create ACL
            if owner_user:
                #logger.debug('registering owner: ' + owner)
                e = Experiment.objects.get(pk=eid)

                acl = ExperimentACL(experiment=e,
                                    pluginId=django_user,
                                    entityId=str(owner_user.id),
                                    canRead=True,
                                    canWrite=True,
                                    canDelete=True,
                                    isOwner=True,
                                    aclOwnershipType=ExperimentACL.OWNER_OWNED)
                acl.save()

    return (eid, sync_root)