Page 2 of 2

Re: permission issue on annotation in matlab

PostPosted: Fri Sep 09, 2016 4:27 am
by jacques2020
Hi Josh,

I had a try of your python code but was not successfull (my code attached below). I cannot make the setSecurityContext to work either with
Code: Select all
self.sf=conn.getSession()
or
Code: Select all
self.sf=conn. secSecurityContext
is not a known method in all case. I went through the API doc for BlitzGateway and omero.model.session and it indeed appears nowhere. I tried to find my way in test_permission.py within the source code that appear to do what I tried to do but the test class definition through Pytest etc. are likely beyond my knowledge of python. Anyway, it was just to help and test your code. On my side, the issue in matlab is solved.

Cheers

Jacques



Code: Select all
from omero.gateway import *
from omero.model import *
class RootConn:
    def __init__(self):
      conn = BlitzGateway('root', '**********' host='host', port=4064)
      conn.connect()
      self.sf=conn.getSession()

class MyClass:
    def __init__(self):
      conn = BlitzGateway('J', '*****************', host='host', port=4064)
      connected = conn.connect()
      self.sf=conn
      self.root=RootConn()

    def testUserGroupLinkage(self):
            admin = self.sf.getAdminService()
            update = self.sf.getUpdateService()
            ugid = admin.getSecurityRoles().userGroupId
            ogid = admin.getEventContext().groupId

            # (1) We start off by assuming ogid == 3 as in your example
            # -------------------------------------------------------------------

            # (2) Then create a file annotation in the user's current group
            # -------------------------------------------------------------------
            fa = FileAnnotationI()
            fa = update.saveAndReturnObject(fa)
            assert fa.details.group.id.val == ogid

            # (3) Then we create a dataset in the "user" group (id=1)
            # -------------------------------------------------------------------
            ds = DatasetI()
            ds.setName(rstring("testUserGroupLinkage"))
            ds = update.saveAndReturnObject(ds)
            assert ds.details.group.id.val == ogid
            self.root.sf.setSecurityContext(ExperimenterGroupI(ogid, False))
            self.root.sf.getAdminService().moveToCommonSpace([ds])

            # (4) Now we link the two together.
            # -------------------------------------------------------------------
            dal = DatasetAnnotationLinkI()
            dal.parent = ds.proxy()
            dal.child = fa.proxy()
            dal = update.saveAndReturnObject(dal)

c = MyClass()
c.testUserGroupLinkage()

Re: permission issue on annotation in matlab

PostPosted: Fri Sep 09, 2016 6:47 am
by jmoore
Hi Jacques,

in my code, `self` was the ITest class. It has fields:

  • self.client of type omero.client.BaseClient and
  • self.sf of type omero.api.ServiceFactoryPrx

BaseClient has the field self.sf as well.

Your `conn` object is of type omero.gateway.BlitzGateway and has a field `self.c` of type BaseClient. In short, to get to the `sf` field, you need:

Code: Select all
self.conn.c.sf


Hope that helps.
~Josh.

Re: permission issue on annotation in matlab

PostPosted: Fri Sep 09, 2016 7:34 am
by jacques2020
Great ! thank you.
With the suggested correction, the python code run smoothly. It does not reproduce the matlab bug.

Cheers

Jacques