Created
May 7, 2012 19:24
-
-
Save will-moore/2629829 to your computer and use it in GitHub Desktop.
Script to create Groups & Users for 4.4 Permissions testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from omero.gateway import BlitzGateway | |
import omero | |
from omero.rtypes import rtime, rlong, rstring, rlist, rint | |
from omero_model_ExperimenterI import ExperimenterI | |
from omero_model_ExperimenterGroupI import ExperimenterGroupI | |
from omero_model_PermissionsI import PermissionsI | |
conn = BlitzGateway('root', 'omero', host='localhost'); | |
print conn.connect() | |
admin = conn.getAdminService() | |
uuid = admin.getEventContext().sessionUuid | |
uuid = "" #" _%s" % uuid | |
group1name = "private%s" % uuid | |
group2name = "read-only%s" % uuid | |
group3name = "read-ann%s" % uuid | |
group4name = "read-edit%s" % uuid | |
ownerName = "owner%s" % uuid | |
user1name = "user1%s" % uuid | |
user2name = "user2%s" % uuid | |
### create three users (plus 'root') in 3 groups | |
listOfGroups = list() | |
listOfGroups.append(admin.lookupGroup("user")) # all users need to be in 'user' group to do anything! | |
#group1 - private | |
new_gr1 = ExperimenterGroupI() | |
new_gr1.name = rstring(group1name) | |
new_gr1.details.permissions = PermissionsI('rw----') | |
gid = admin.createGroup(new_gr1) | |
privateGroup = admin.getGroup(gid) | |
listOfGroups.append(privateGroup) | |
#group2 - read-only | |
new_gr2 = ExperimenterGroupI() | |
new_gr2.name = rstring(group2name) | |
new_gr2.details.permissions = PermissionsI('rwr---') | |
gid2 = admin.createGroup(new_gr2) | |
readOnlyGroup = admin.getGroup(gid2) | |
listOfGroups.append(readOnlyGroup) | |
#group3 - read-ann | |
new_gr3 = ExperimenterGroupI() | |
new_gr3.name = rstring(group3name) | |
new_gr3.details.permissions = PermissionsI('rwra--') | |
gid3 = admin.createGroup(new_gr3) | |
readAnnGroup = admin.getGroup(gid3) | |
listOfGroups.append(readAnnGroup) | |
#group4 - read-write | |
new_gr4 = ExperimenterGroupI() | |
new_gr4.name = rstring(group4name) | |
new_gr4.details.permissions = PermissionsI('rwrw--') | |
gid4 = admin.createGroup(new_gr4) | |
readWriteGroup = admin.getGroup(gid4) | |
listOfGroups.append(readWriteGroup) | |
# Add 'root' to each group, except first 'user' group in list | |
admin.addGroups(ExperimenterI(0, False), listOfGroups[1:]) | |
#new user (group owner) | |
owner = ExperimenterI() | |
owner.omeName = rstring(ownerName) | |
owner.firstName = rstring("Group") | |
owner.lastName = rstring("Owner") | |
owner.email = rstring("[email protected]") | |
ownerId = admin.createExperimenterWithPassword(owner, rstring("ome"), privateGroup, listOfGroups) | |
newOwner = admin.getExperimenter(ownerId) | |
admin.setGroupOwner(privateGroup, newOwner) | |
admin.setGroupOwner(readOnlyGroup, newOwner) | |
admin.setGroupOwner(readAnnGroup, newOwner) | |
admin.setGroupOwner(readWriteGroup, newOwner) | |
#new user1 | |
new_exp = ExperimenterI() | |
new_exp.omeName = rstring(user1name) | |
new_exp.firstName = rstring("Will") | |
new_exp.lastName = rstring("Moore") | |
new_exp.email = rstring("[email protected]") | |
eid = admin.createExperimenterWithPassword(new_exp, rstring("ome"), privateGroup, listOfGroups) | |
#new user2 | |
new_exp2 = ExperimenterI() | |
new_exp2.omeName = rstring(user2name) | |
new_exp2.firstName = rstring("User") | |
new_exp2.lastName = rstring("Test2") | |
new_exp2.email = rstring("[email protected]") | |
eid2 = admin.createExperimenterWithPassword(new_exp2, rstring("ome"), privateGroup, listOfGroups) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script creates 4 groups with various permissions
Also creates 3 users plus 'root'