def find_group(identifier, idtype='name'): if idtype == 'name' and isinstance(identifier, unicode): identifier = identifier.encode(db.encoding) try: try: group = utils.get_group(identifier=identifier, idtype=idtype, grtype='PosixGroup') except utils.EntityLookupError: group = utils.get_group(identifier=identifier, idtype=idtype) except utils.EntityLookupError as e: raise NotFound(str(e)) return group
def find_group(identifier, idtype='name'): if idtype == 'name' and isinstance(identifier, text_type): identifier = identifier try: try: group = utils.get_group(identifier=identifier, idtype=idtype, grtype='PosixGroup') except utils.EntityLookupError: group = utils.get_group(identifier=identifier, idtype=idtype) except utils.EntityLookupError as e: raise NotFound(text_type(e)) return group
def put(self, name): """ Create or update group. """ args = self.new_group_parser.parse_args() args['visibility'] = GroupVisibility.unserialize(args['visibility']) name = name.encode(db.encoding) result_code = 200 try: # find and update all attributes group = utils.get_group(name, 'name', 'Group') changes = False if group.visibility != args['visibility']: group.visibility = args['visibility'] changes = True if group.description != args['description']: group.description = args['description'].encode(db.encoding) changes = True if changes: group.write_db() except utils.EntityLookupError: # create group group = Factory.get('Group')(db.connection) bad_name = group.illegal_name(name) if bad_name: abort(400, message="Illegal group name: {!s}".format(bad_name)) group.new(auth.account.entity_id, args['visibility'], name, args['description']) result_code = 201 return self.group_info(group), result_code