def index(self, **kwargs): # Find out which item was requested. path_str = self.api.get_data().get_str('path_str') if path_str is None: resource = self.guard.get_resource(handle = 'everybody', type = Group) path = SpiffGuard.ResourcePath([resource.get_id()]) else: path = SpiffGuard.ResourcePath(path_str) # Fetch the requested user or group info. errors = [] id = path.get_current_id() if self.api.post_data().get_bool('group_add'): resource = Group('') path = path.append(0) elif self.api.post_data().get_bool('user_add'): resource = User('') path = path.append(0) elif self.api.post_data().get_bool('group_save') and id == 0: resource = Group('') errors = self.__save_resource(resource) if not errors: path = path.crop().append(resource.get_id()) elif self.api.post_data().get_bool('group_save'): resource = self.guard.get_resource(id = id) errors = self.__save_resource(resource) path = path.crop().append(resource.get_id()) elif self.api.post_data().get_bool('user_save') and id == 0: resource = User('') errors = self.__save_resource(resource) if not errors: path = path.crop().append(resource.get_id()) elif self.api.post_data().get_bool('user_save'): resource = self.guard.get_resource(id = id) errors = self.__save_resource(resource) path = path.crop().append(resource.get_id()) elif (self.api.post_data().get_bool('group_delete') and self.api.post_data().get_str('group_delete_really') == 'yes'): resource = self.guard.get_resource(id = id) # Check if the group still has users in it. children = self.guard.get_resource_children(resource) if len(children) > 0: #FIXME: Rather ask what to do with the children. errors = [_("Group can not be deleted because " + "it still has users in it.")] else: errors = self.__delete_resource(resource) path = path.crop() id = path.get_current_id() resource = self.guard.get_resource(id = id) elif (self.api.post_data().get_bool('user_delete') and self.api.post_data().get_str('user_delete_really') == 'yes'): resource = self.guard.get_resource(id = id) errors = self.__delete_resource(resource) path = path.crop() id = path.get_current_id() resource = self.guard.get_resource(id = id) elif path_str is not None: resource = self.guard.get_resource(id = id) # Display the editor. if resource.is_group(): self.__show_group(resource, path, errors) else: self.__show_user(resource, path, errors)