def __init__(self, app, config_models): """Constructor :param Flask app: Flask application :param ConfigModels config_models: Helper for ORM models """ super(UsersController, self).__init__("User", 'users', 'user', 'users', app, config_models) self.User = self.config_models.model('users') self.UserInfo = self.config_models.model('user_infos') self.Group = self.config_models.model('groups') self.Role = self.config_models.model('roles') # get custom user info fields try: user_info_fields = json.loads( os.environ.get('USER_INFO_FIELDS', '[]')) except Exception as e: app.logger.error("Could not load USER_INFO_FIELDS:\n%s" % e) user_info_fields = [] # show TOTP fields? self.totp_enabled = os.environ.get('TOTP_ENABLED', 'False') == 'True' UserForm.add_custom_fields(user_info_fields)
def __init__(self, app, handler): """Constructor :param Flask app: Flask application :param handler: Tenant config handler """ super(UsersController, self).__init__("User", 'users', 'user', 'users', app, handler) # get custom user info fields try: handler_config = self.handler().config().get( "user_info_fields", "[]") # this type separation is needed because # the handler return two different types # depending on where he reads the config # str --> read from env variable # list --> read from adminGuiConfig.json if type(handler_config) is str: user_info_fields = json.loads(handler_config) else: # json.dumps converts the list object to a string # and makes sure that all python strings # are in double quotes and not single quotes user_info_fields = json.loads(json.dumps(handler_config)) except Exception as e: app.logger.error("Could not load USER_INFO_FIELDS:\n%s" % e) user_info_fields = [] # show TOTP fields? self.totp_enabled = self.handler().config().get("totp_enabled", False) in (True, 'True') UserForm.add_custom_fields(user_info_fields)