def perms(self, args): import omero from omero_model_ExperimenterGroupI import ExperimenterGroupI as Grp from omero_model_PermissionsI import PermissionsI as Perms perms = self.parse_perms(args) c = self.ctx.conn(args) a = c.sf.getAdminService() gid, g = self.find_group(a, args.id_or_name) old_perms = str(g.details.permissions) if old_perms == str(perms): self.ctx.out("Permissions for group %s (id=%s) already %s" % (g.name.val, gid, perms)) else: try: a.changePermissions(Grp(gid, False), perms) self.ctx.out("Changed permissions for group %s (id=%s) to %s" % (g.name.val, gid, perms)) except omero.GroupSecurityViolation: import traceback self.ctx.dbg(traceback.format_exc()) self.ctx.die( 504, "Cannot change permissions for group %s (id=%s) to %s" % (g.name.val, gid, perms))
def add(self, args): import omero, Ice from omero.rtypes import rstring from omero_model_PermissionsI import PermissionsI as Perms from omero_model_ExperimenterGroupI import ExperimenterGroupI as Grp perms = self.parse_perms(args) c = self.ctx.conn(args) p = c.ic.getProperties() g = Grp() g.name = rstring(args.name) g.details.permissions = perms admin = c.getSession().getAdminService() try: grp = admin.lookupGroup(args.name) if grp: if args.ignore_existing: self.ctx.out("Group exists: %s (id=%s)" % (args.name, grp.id.val)) return else: self.ctx.die( 3, "Group exists: %s (id=%s)" % (args.name, grp.id.val)) except omero.ApiUsageException, aue: pass # Apparently no such group exists
def add(self, args): import omero from omero.rtypes import rbool, rstring from omero_model_ExperimenterGroupI import ExperimenterGroupI as Grp perms = self.parse_perms(args) c = self.ctx.conn(args) g = Grp() g.name = rstring(args.name) g.ldap = rbool(False) g.details.permissions = perms admin = c.getSession().getAdminService() try: grp = admin.lookupGroup(args.name) if grp: if args.ignore_existing: self.ctx.out("Group exists: %s (id=%s)" % (args.name, grp.id.val)) return else: self.ctx.die( 3, "Group exists: %s (id=%s)" % (args.name, grp.id.val)) except omero.ApiUsageException: pass # Apparently no such group exists try: id = admin.createGroup(g) self.ctx.out("Added group %s (id=%s) with permissions %s" % (args.name, id, perms)) except omero.ValidationException as ve: # Possible, though unlikely after previous check if self.exc.is_constraint_violation(ve): self.ctx.die(66, "Group already exists: %s" % args.name) else: self.ctx.die(67, "Unknown ValidationException: %s" % ve.message) except omero.SecurityViolation as se: self.ctx.die(68, "Security violation: %s" % se.message) except omero.ServerError as se: self.ctx.die(4, "%s: %s" % (type(se), se.message))
def add(self, args): email = args.email login = args.username first = args.firstname middle = args.middlename last = args.lastname inst = args.institution pasw = args.userpassword import omero from omero.rtypes import rbool, rstring from omero_model_ExperimenterI import ExperimenterI as Exp from omero_model_ExperimenterGroupI import ExperimenterGroupI as Grp c = self.ctx.conn(args) e = Exp() e.omeName = rstring(login) e.firstName = rstring(first) e.lastName = rstring(last) e.middleName = rstring(middle) e.email = rstring(email) e.institution = rstring(inst) e.ldap = rbool(False) # Fail-fast if no-password is passed and the server does not accept # empty passwords configService = c.getSession().getConfigService() password_required = configService.getConfigValue( "omero.security.password_required").lower() if args.no_password and password_required != 'false': self.ctx.die( 502, "Server does not allow user creation with empty" " passwords") # Check user existence admin = c.getSession().getAdminService() try: usr = admin.lookupExperimenter(login) if usr: if args.ignore_existing: self.ctx.out("User exists: %s (id=%s)" % (login, usr.id.val)) return else: self.ctx.die( 3, "User exists: %s (id=%s)" % (login, usr.id.val)) except omero.ApiUsageException: pass # Apparently no such user exists [gid, groups] = self.list_groups(admin, args, use_context=False) roles = admin.getSecurityRoles() groups.append(Grp(roles.userGroupId, False)) if args.admin: groups.append(Grp(roles.systemGroupId, False)) group = groups.pop(0) try: if args.no_password: id = admin.createExperimenter(e, group, groups) self.ctx.out("Added user %s (id=%s) without password" % (login, id)) else: if pasw is None: pasw = self._ask_for_password(" for your new user (%s)" % login, strict=True) id = admin.createExperimenterWithPassword( e, rstring(pasw), group, groups) self.ctx.out("Added user %s (id=%s) with password" % (login, id)) except omero.ValidationException as ve: # Possible, though unlikely after previous check if self.exc.is_constraint_violation(ve): self.ctx.die(66, "User already exists: %s" % login) else: self.ctx.die(67, "Unknown ValidationException: %s" % ve.message) except omero.SecurityViolation as se: self.ctx.die(68, "Security violation: %s" % se.message)
self.ctx.out("User exists: %s (id=%s)" % (login, usr.id.val)) return else: self.ctx.die( 3, "User exists: %s (id=%s)" % (login, usr.id.val)) except omero.ApiUsageException, aue: pass # Apparently no such user exists try: groups = [admin.lookupGroup(group) for group in args.member_of] except omero.ApiUsageException, aue: self.ctx.die(68, aue.message) roles = admin.getSecurityRoles() groups.append(Grp(roles.userGroupId, False)) if args.admin: groups.append(Grp(roles.systemGroupId, False)) group = groups.pop(0) try: if pasw is None: id = admin.createExperimenter(e, group, groups) self.ctx.out("Added user %s" % id) else: id = admin.createExperimenterWithPassword( e, rstring(pasw), group, groups) self.ctx.out("Added user %s with password" % id) except omero.ValidationException, ve: # Possible, though unlikely after previous check
def add(self, args): email = args.email login = args.username first = args.firstname middle = args.middlename last = args.lastname inst = args.institution pasw = args.userpassword import omero from omero.rtypes import rstring from omero_model_ExperimenterI import ExperimenterI as Exp from omero_model_ExperimenterGroupI import ExperimenterGroupI as Grp c = self.ctx.conn(args) e = Exp() e.omeName = rstring(login) e.firstName = rstring(first) e.lastName = rstring(last) e.middleName = rstring(middle) e.email = rstring(email) e.institution = rstring(inst) admin = c.getSession().getAdminService() try: usr = admin.lookupExperimenter(login) if usr: if args.ignore_existing: self.ctx.out("User exists: %s (id=%s)" % (login, usr.id.val)) return else: self.ctx.die(3, "User exists: %s (id=%s)" % (login, usr.id.val)) except omero.ApiUsageException: pass # Apparently no such user exists groups = self.list_groups(admin, args) roles = admin.getSecurityRoles() groups.append(Grp(roles.userGroupId, False)) if args.admin: groups.append(Grp(roles.systemGroupId, False)) group = groups.pop(0) try: if args.no_password: id = admin.createExperimenter(e, group, groups) self.ctx.out("Added user %s (id=%s) without password" % (login, id)) else: if pasw is None: self._ask_for_password(" for your new user (%s)" % login, strict=True) id = admin.createExperimenterWithPassword(e, rstring(pasw), group, groups) self.ctx.out("Added user %s (id=%s) with password" % (login, id)) except omero.ValidationException, ve: # Possible, though unlikely after previous check if self.exc.is_constraint_violation(ve): self.ctx.die(66, "User already exists: %s" % login) else: self.ctx.die(67, "Unknown ValidationException: %s" % ve.message)