예제 #1
0
    def test_set_inherit_and_test_sub_objects (self):
        DEPTH = 3
        OBJ_PER_LVL = 1
        deepcoll = user = None
        test_coll_path = self.coll_path + "/test"
        try:
            deepcoll = helpers.make_deep_collection(self.sess, test_coll_path, object_content = 'arbitrary',
                                                    depth=DEPTH, objects_per_level=OBJ_PER_LVL)
            user = self.sess.users.create('bob','rodsuser')
            user.modify ('password','bpass')

            acl_inherit = iRODSAccess('inherit', deepcoll.path)
            acl_read = iRODSAccess('read', deepcoll.path, 'bob')

            self.sess.permissions.set(acl_read)
            self.sess.permissions.set(acl_inherit)

            # create one new object and one new collection *after* ACL's are applied
            new_object_path = test_coll_path + "/my_data_obj"
            with self.sess.data_objects.open( new_object_path ,'w') as f: f.write(b'some_content')

            new_collection_path = test_coll_path + "/my_colln_obj"
            new_collection = self.sess.collections.create( new_collection_path )

            coll_IDs = [c[Collection.id] for c in
                            self.sess.query(Collection.id).filter(Like(Collection.name , deepcoll.path + "%"))]

            D_rods = list(self.sess.query(Collection.name,DataObject.name).filter(
                                                                          In(DataObject.collection_id, coll_IDs )))

            self.assertEqual (len(D_rods), OBJ_PER_LVL*DEPTH+1) # counts the 'older' objects plus one new object

            with iRODSSession (port=self.sess.port, zone=self.sess.zone, host=self.sess.host,
                               user='******', password='******') as bob:

                D = list(bob.query(Collection.name,DataObject.name).filter(
                                                                    In(DataObject.collection_id, coll_IDs )))

                # - bob should only see the new data object, but none existing before ACLs were applied

                self.assertEqual( len(D), 1 )
                D_names = [_[Collection.name] + "/" + _[DataObject.name] for _ in D]
                self.assertEqual( D[0][DataObject.name], 'my_data_obj' )

                # - bob should be able to read the new data object

                with bob.data_objects.get(D_names[0]).open('r') as f:
                    self.assertGreater( len(f.read()), 0)

                C = list(bob.query(Collection).filter( In(Collection.id, coll_IDs )))
                self.assertEqual( len(C), 2 ) # query should return only the top-level and newly created collections
                self.assertEqual( sorted([c[Collection.name] for c in C]),
                                  sorted([new_collection.path, deepcoll.path]) )
        finally:
            if user: user.remove()
            if deepcoll: deepcoll.remove(force = True, recurse = True)
예제 #2
0
 def test_raw_acls__207(self):
     data = helpers.make_object(self.sess,"/".join((self.coll_path,"test_obj")))
     eg = eu = fg = fu = None
     try:
         eg = self.sess.user_groups.create ('egrp')
         eu = self.sess.users.create ('edith','rodsuser')
         eg.addmember(eu.name,eu.zone)
         fg = self.sess.user_groups.create ('fgrp')
         fu = self.sess.users.create ('frank','rodsuser')
         fg.addmember(fu.name,fu.zone)
         my_ownership = set([('own', self.sess.username, self.sess.zone)])
         #--collection--
         perms1data = [ iRODSAccess ('write',self.coll_path, eg.name, self.sess.zone),
                        iRODSAccess ('read', self.coll_path, fu.name, self.sess.zone)
                      ]
         for perm in perms1data: self.sess.permissions.set ( perm )
         p1 = self.sess.permissions.get ( self.coll, report_raw_acls = True)
         self.assertEqual(self.perms_lists_symm_diff( perms1data, p1 ), my_ownership)
         #--data object--
         perms2data = [ iRODSAccess ('write',data.path, fg.name, self.sess.zone),
                        iRODSAccess ('read', data.path, eu.name, self.sess.zone)
                      ]
         for perm in perms2data: self.sess.permissions.set ( perm )
         p2 = self.sess.permissions.get ( data, report_raw_acls = True)
         self.assertEqual(self.perms_lists_symm_diff( perms2data, p2 ), my_ownership)
     finally:
         ids_for_delete = [ u.id for u in (fu,fg,eu,eg) if u is not None ]
         for u in [ iRODSUser(self.sess.users,row)
                    for row in self.sess.query(User).filter(In(User.id, ids_for_delete)) ]:
             u.remove()
예제 #3
0
 def test_query_with_in_condition(self):
     collection = self.coll_path
     filename = 'test_query_id_in_list.txt'
     file_path = '{collection}/{filename}'.format(**locals())
     obj1 = helpers.make_object(self.sess, file_path+'-1')
     obj2 = helpers.make_object(self.sess, file_path+'-2')
     ids = [x.id for x in (obj1,obj2)]
     for number in range(3):  # slice for empty(:0), first(:1) or both(:2)
         search_tuple = (ids[:number] if number >= 1 else [0] + ids[:number])
         q = self.sess.query(DataObject.name).filter(In( DataObject.id, search_tuple ))
         self.assertEqual (number, rows_returned(q))
예제 #4
0
def users_by_ids(session, ids=()):
    try:
        ids = list(iter(ids))
    except TypeError:
        if type(ids) in (str, ) + six.integer_types: ids = int(ids)
        else: raise
    cond = () if not ids \
           else (In(User.id,list(map(int,ids))),) if len(ids)>1 \
           else (User.id == int(ids[0]),)
    return [
        iRODSUser(session.users, i) for i in session.query(
            User.id, User.name, User.type, User.zone).filter(*cond)
    ]