def __init__(self, siteconfig, *args, **kwargs): """Initialize the form.""" from reviewboard.accounts.backends import get_registered_auth_backends super(AuthenticationSettingsForm, self).__init__(siteconfig, *args, **kwargs) self.auth_backend_forms = {} cur_auth_backend = (self['auth_backend'].data or self.fields['auth_backend'].initial) if cur_auth_backend == self.CUSTOM_AUTH_ID: custom_auth_form = LegacyAuthModuleSettingsForm(siteconfig, *args, **kwargs) else: custom_auth_form = LegacyAuthModuleSettingsForm(siteconfig) self.auth_backend_forms[self.CUSTOM_AUTH_ID] = custom_auth_form backend_choices = [] builtin_auth_choice = None for backend in get_registered_auth_backends(): backend_id = backend.backend_id try: if backend.settings_form: if cur_auth_backend == backend_id: backend_form = backend.settings_form(siteconfig, *args, **kwargs) else: backend_form = backend.settings_form(siteconfig) self.auth_backend_forms[backend_id] = backend_form backend_form.load() choice = (backend_id, backend.name) if backend_id == 'builtin': builtin_auth_choice = choice else: backend_choices.append(choice) except Exception as e: logging.error('Error loading authentication backend %s: %s' % (backend_id, e), exc_info=1) backend_choices.sort(key=lambda x: x[1]) backend_choices.insert(0, builtin_auth_choice) backend_choices.append(self.CUSTOM_AUTH_CHOICE) self.fields['auth_backend'].choices = backend_choices
def __init__(self, siteconfig, *args, **kwargs): """Initialize the form.""" from reviewboard.accounts.backends import get_registered_auth_backends super(AuthenticationSettingsForm, self).__init__(siteconfig, *args, **kwargs) self.auth_backend_forms = {} cur_auth_backend = (self['auth_backend'].data or self.fields['auth_backend'].initial) if cur_auth_backend == self.CUSTOM_AUTH_ID: custom_auth_form = LegacyAuthModuleSettingsForm( siteconfig, *args, **kwargs) else: custom_auth_form = LegacyAuthModuleSettingsForm(siteconfig) self.auth_backend_forms[self.CUSTOM_AUTH_ID] = custom_auth_form backend_choices = [] builtin_auth_choice = None for backend in get_registered_auth_backends(): backend_id = backend.backend_id try: if backend.settings_form: if cur_auth_backend == backend_id: backend_form = backend.settings_form( siteconfig, *args, **kwargs) else: backend_form = backend.settings_form(siteconfig) self.auth_backend_forms[backend_id] = backend_form backend_form.load() choice = (backend_id, backend.name) if backend_id == 'builtin': builtin_auth_choice = choice else: backend_choices.append(choice) except Exception as e: logging.error('Error loading authentication backend %s: %s' % (backend_id, e), exc_info=1) backend_choices.sort(key=lambda x: x[1]) backend_choices.insert(0, builtin_auth_choice) backend_choices.append(self.CUSTOM_AUTH_CHOICE) self.fields['auth_backend'].choices = backend_choices
def __init__(self, siteconfig, *args, **kwargs): from reviewboard.accounts.backends import get_registered_auth_backends super(AuthenticationSettingsForm, self).__init__(siteconfig, *args, **kwargs) self.auth_backend_forms = {} cur_auth_backend = self["auth_backend"].data or self.fields["auth_backend"].initial if cur_auth_backend == self.CUSTOM_AUTH_ID: custom_auth_form = LegacyAuthModuleSettingsForm(siteconfig, *args, **kwargs) else: custom_auth_form = LegacyAuthModuleSettingsForm(siteconfig) self.auth_backend_forms[self.CUSTOM_AUTH_ID] = custom_auth_form backend_choices = [] builtin_auth_choice = None for backend_id, backend in get_registered_auth_backends(): try: if backend.settings_form: if cur_auth_backend == backend_id: backend_form = backend.settings_form(siteconfig, *args, **kwargs) else: backend_form = backend.settings_form(siteconfig) self.auth_backend_forms[backend_id] = backend_form backend_form.load() choice = (backend_id, backend.name) if backend_id == "builtin": builtin_auth_choice = choice else: backend_choices.append(choice) except Exception, e: logging.error("Error loading authentication backend %s: %s" % (backend_id, e), exc_info=1)
def load_site_config(): """ Loads any stored site configuration settings and populates the Django settings object with any that need to be there. """ def apply_setting(settings_key, db_key, default=None): db_value = siteconfig.settings.get(db_key) if db_value: setattr(settings, settings_key, db_value) elif default: setattr(settings, settings_key, default) try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: raise ImproperlyConfigured, \ "The site configuration entry does not exist in the database. " \ "Re-run `./manage.py` syncdb to fix this." except: # We got something else. Likely, this doesn't exist yet and we're # doing a syncdb or something, so silently ignore. return # Populate defaults if they weren't already set. if not siteconfig.get_defaults(): siteconfig.add_defaults(defaults) # The default value for DEFAULT_EMAIL_FROM (webmaster@localhost) # is less than good, so use a better one if it's set to that or if # we haven't yet set this value in siteconfig. mail_default_from = \ siteconfig.settings.get('mail_default_from', global_settings.DEFAULT_FROM_EMAIL) if (not mail_default_from or mail_default_from == global_settings.DEFAULT_FROM_EMAIL): domain = siteconfig.site.domain.split(':')[0] siteconfig.set('mail_default_from', 'noreply@' + domain) # Populate the settings object with anything relevant from the siteconfig. apply_django_settings(siteconfig, settings_map) # Now for some more complicated stuff... # Do some dependency checks and disable things if we don't support them. if not get_can_enable_search()[0]: siteconfig.set('search_enable', False) if not get_can_enable_syntax_highlighting()[0]: siteconfig.set('diffviewer_syntax_highlighting', False) # Site administrator settings apply_setting("ADMINS", None, ( (siteconfig.get("site_admin_name", ""), siteconfig.get("site_admin_email", "")), )) apply_setting("MANAGERS", None, settings.ADMINS) # Explicitly base this off the MEDIA_URL apply_setting("ADMIN_MEDIA_PREFIX", None, settings.MEDIA_URL + "admin/") # Set the auth backends auth_backend_map = dict(get_registered_auth_backends()) auth_backend_id = siteconfig.settings.get("auth_backend", "builtin") builtin_backend_obj = auth_backend_map['builtin'] builtin_backend = "%s.%s" % (builtin_backend_obj.__module__, builtin_backend_obj.__name__) if auth_backend_id == "custom": custom_backends = siteconfig.settings.get("auth_custom_backends") if isinstance(custom_backends, basestring): custom_backends = (custom_backends,) elif isinstance(custom_backends, list): custom_backends = tuple(custom_backends) settings.AUTHENTICATION_BACKENDS = custom_backends if builtin_backend not in custom_backends: settings.AUTHENTICATION_BACKENDS += (builtin_backend,) elif auth_backend_id != "builtin" and auth_backend_id in auth_backend_map: backend = auth_backend_map[auth_backend_id] settings.AUTHENTICATION_BACKENDS = \ ("%s.%s" % (backend.__module__, backend.__name__), builtin_backend) else: settings.AUTHENTICATION_BACKENDS = (builtin_backend,) # Set the storage backend storage_backend = siteconfig.settings.get('storage_backend', 'builtin') if storage_backend in storage_backend_map: settings.DEFAULT_FILE_STORAGE = storage_backend_map[storage_backend] else: settings.DEFAULT_FILE_STORAGE = storage_backend_map['builtin'] # These blow up if they're not the perfectly right types settings.AWS_ACCESS_KEY_ID = str(siteconfig.get('aws_access_key_id')) settings.AWS_SECRET_ACCESS_KEY = str(siteconfig.get('aws_secret_access_key')) settings.AWS_STORAGE_BUCKET_NAME = str(siteconfig.get('aws_s3_bucket_name')) settings.AWS_CALLING_FORMAT = int(siteconfig.get('aws_calling_format'))
def load_site_config(): """ Loads any stored site configuration settings and populates the Django settings object with any that need to be there. """ def apply_setting(settings_key, db_key, default=None): db_value = siteconfig.settings.get(db_key) if db_value: setattr(settings, settings_key, db_value) elif default: setattr(settings, settings_key, default) try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: raise ImproperlyConfigured, \ "The site configuration entry does not exist in the database. " \ "Re-run `./manage.py` syncdb to fix this." except: # We got something else. Likely, this doesn't exist yet and we're # doing a syncdb or something, so silently ignore. return # Populate defaults if they weren't already set. if not siteconfig.get_defaults(): siteconfig.add_defaults(defaults) # The default value for DEFAULT_EMAIL_FROM (webmaster@localhost) # is less than good, so use a better one if it's set to that or if # we haven't yet set this value in siteconfig. mail_default_from = \ siteconfig.settings.get('mail_default_from', global_settings.DEFAULT_FROM_EMAIL) if (not mail_default_from or mail_default_from == global_settings.DEFAULT_FROM_EMAIL): domain = siteconfig.site.domain.split(':')[0] siteconfig.set('mail_default_from', 'noreply@' + domain) # Populate the settings object with anything relevant from the siteconfig. apply_django_settings(siteconfig, settings_map) # Now for some more complicated stuff... # Do some dependency checks and disable things if we don't support them. if not get_can_enable_search()[0]: siteconfig.set('search_enable', False) if not get_can_enable_syntax_highlighting()[0]: siteconfig.set('diffviewer_syntax_highlighting', False) # Site administrator settings apply_setting("ADMINS", None, ((siteconfig.get( "site_admin_name", ""), siteconfig.get("site_admin_email", "")), )) apply_setting("MANAGERS", None, settings.ADMINS) # Explicitly base this off the MEDIA_URL apply_setting("ADMIN_MEDIA_PREFIX", None, settings.MEDIA_URL + "admin/") # Set the auth backends auth_backend_map = dict(get_registered_auth_backends()) auth_backend_id = siteconfig.settings.get("auth_backend", "builtin") builtin_backend_obj = auth_backend_map['builtin'] builtin_backend = "%s.%s" % (builtin_backend_obj.__module__, builtin_backend_obj.__name__) if auth_backend_id == "custom": custom_backends = siteconfig.settings.get("auth_custom_backends") if isinstance(custom_backends, basestring): custom_backends = (custom_backends, ) elif isinstance(custom_backends, list): custom_backends = tuple(custom_backends) settings.AUTHENTICATION_BACKENDS = custom_backends if builtin_backend not in custom_backends: settings.AUTHENTICATION_BACKENDS += (builtin_backend, ) elif auth_backend_id != "builtin" and auth_backend_id in auth_backend_map: backend = auth_backend_map[auth_backend_id] settings.AUTHENTICATION_BACKENDS = \ ("%s.%s" % (backend.__module__, backend.__name__), builtin_backend) else: settings.AUTHENTICATION_BACKENDS = (builtin_backend, ) # Set the storage backend storage_backend = siteconfig.settings.get('storage_backend', 'builtin') if storage_backend in storage_backend_map: settings.DEFAULT_FILE_STORAGE = storage_backend_map[storage_backend] else: settings.DEFAULT_FILE_STORAGE = storage_backend_map['builtin'] # These blow up if they're not the perfectly right types settings.AWS_ACCESS_KEY_ID = str(siteconfig.get('aws_access_key_id')) settings.AWS_SECRET_ACCESS_KEY = str( siteconfig.get('aws_secret_access_key')) settings.AWS_STORAGE_BUCKET_NAME = str( siteconfig.get('aws_s3_bucket_name')) try: settings.AWS_CALLING_FORMAT = int(siteconfig.get('aws_calling_format')) except ValueError: settings.AWS_CALLING_FORMAT = 0
def load_site_config(): """ Loads any stored site configuration settings and populates the Django settings object with any that need to be there. """ def apply_setting(settings_key, db_key, default=None): db_value = siteconfig.settings.get(db_key) if db_value: setattr(settings, settings_key, db_value) elif default: setattr(settings, settings_key, default) try: siteconfig = SiteConfiguration.objects.get_current() except SiteConfiguration.DoesNotExist: raise ImproperlyConfigured( "The site configuration entry does not exist in the database. " "Re-run `./manage.py` syncdb to fix this." ) except: # We got something else. Likely, this doesn't exist yet and we're # doing a syncdb or something, so silently ignore. return # Populate defaults if they weren't already set. if not siteconfig.get_defaults(): siteconfig.add_defaults(defaults) # The default value for DEFAULT_EMAIL_FROM (webmaster@localhost) # is less than good, so use a better one if it's set to that or if # we haven't yet set this value in siteconfig. mail_default_from = siteconfig.settings.get("mail_default_from", global_settings.DEFAULT_FROM_EMAIL) if not mail_default_from or mail_default_from == global_settings.DEFAULT_FROM_EMAIL: domain = siteconfig.site.domain.split(":")[0] siteconfig.set("mail_default_from", "noreply@" + domain) # STATIC_* and MEDIA_* must be different paths, and differ in meaning. # If site_static_* is empty or equal to media_static_*, we're probably # migrating from an earlier Review Board install. site_static_root = siteconfig.settings.get("site_static_root", "") site_media_root = siteconfig.settings.get("site_media_root") if site_static_root == "" or site_static_root == site_media_root: siteconfig.set("site_static_root", settings.STATIC_ROOT) site_static_url = siteconfig.settings.get("site_static_url", "") site_media_url = siteconfig.settings.get("site_media_url") if site_static_url == "" or site_static_url == site_media_url: siteconfig.set("site_static_url", settings.STATIC_URL) # Populate the settings object with anything relevant from the siteconfig. apply_django_settings(siteconfig, settings_map) # Now for some more complicated stuff... # Do some dependency checks and disable things if we don't support them. if not get_can_enable_search()[0]: siteconfig.set("search_enable", False) if not get_can_enable_syntax_highlighting()[0]: siteconfig.set("diffviewer_syntax_highlighting", False) # Site administrator settings apply_setting("ADMINS", None, ((siteconfig.get("site_admin_name", ""), siteconfig.get("site_admin_email", "")),)) apply_setting("MANAGERS", None, settings.ADMINS) # Explicitly base this off the STATIC_URL apply_setting("ADMIN_MEDIA_PREFIX", None, settings.STATIC_URL + "admin/") # Set the auth backends auth_backend_map = dict(get_registered_auth_backends()) auth_backend_id = siteconfig.settings.get("auth_backend", "builtin") builtin_backend_obj = auth_backend_map["builtin"] builtin_backend = "%s.%s" % (builtin_backend_obj.__module__, builtin_backend_obj.__name__) if auth_backend_id == "custom": custom_backends = siteconfig.settings.get("auth_custom_backends") if isinstance(custom_backends, six.string_types): custom_backends = (custom_backends,) elif isinstance(custom_backends, list): custom_backends = tuple(custom_backends) settings.AUTHENTICATION_BACKENDS = custom_backends if builtin_backend not in custom_backends: settings.AUTHENTICATION_BACKENDS += (builtin_backend,) elif auth_backend_id != "builtin" and auth_backend_id in auth_backend_map: backend = auth_backend_map[auth_backend_id] settings.AUTHENTICATION_BACKENDS = ("%s.%s" % (backend.__module__, backend.__name__), builtin_backend) else: settings.AUTHENTICATION_BACKENDS = (builtin_backend,) # Set the storage backend storage_backend = siteconfig.settings.get("storage_backend", "builtin") if storage_backend in storage_backend_map: settings.DEFAULT_FILE_STORAGE = storage_backend_map[storage_backend] else: settings.DEFAULT_FILE_STORAGE = storage_backend_map["builtin"] # These blow up if they're not the perfectly right types settings.AWS_QUERYSTRING_AUTH = siteconfig.get("aws_querystring_auth") settings.AWS_ACCESS_KEY_ID = six.text_type(siteconfig.get("aws_access_key_id")) settings.AWS_SECRET_ACCESS_KEY = six.text_type(siteconfig.get("aws_secret_access_key")) settings.AWS_STORAGE_BUCKET_NAME = six.text_type(siteconfig.get("aws_s3_bucket_name")) try: settings.AWS_CALLING_FORMAT = int(siteconfig.get("aws_calling_format")) except ValueError: settings.AWS_CALLING_FORMAT = 0