mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Add support for CUSTOM_LOGO and CUSTOM_LOGIN_INFO settings, add support to migrate from local_settings.json and custom_console_logo.png.
This commit is contained in:
@@ -5,16 +5,8 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
# Tower
|
||||
from awx.conf import fields, register
|
||||
|
||||
|
||||
class PendoTrackingStateField(fields.ChoiceField):
|
||||
|
||||
def to_internal_value(self, data):
|
||||
# Any false/null values get converted to 'off'.
|
||||
if data in fields.NullBooleanField.FALSE_VALUES or data in fields.NullBooleanField.NULL_VALUES:
|
||||
return 'off'
|
||||
return super(PendoTrackingStateField, self).to_internal_value(data)
|
||||
from awx.conf import register, fields
|
||||
from awx.ui.fields import * # noqa
|
||||
|
||||
|
||||
register(
|
||||
@@ -30,3 +22,35 @@ register(
|
||||
category=_('UI'),
|
||||
category_slug='ui',
|
||||
)
|
||||
|
||||
register(
|
||||
'CUSTOM_LOGIN_INFO',
|
||||
field_class=fields.CharField,
|
||||
allow_blank=True,
|
||||
default='',
|
||||
label=_('Custom Login Info'),
|
||||
help_text=_('If needed, you can add specific information (such as a legal '
|
||||
'notice or a disclaimer) to a text box in the login modal using '
|
||||
'this setting. Any content added must be in plain text, as '
|
||||
'custom HTML or other markup languages are not supported. If '
|
||||
'multiple paragraphs of text are needed, new lines (paragraphs) '
|
||||
'must be escaped as `\\n` within the block of text.'),
|
||||
category=_('UI'),
|
||||
category_slug='ui',
|
||||
feature_required='rebranding',
|
||||
)
|
||||
|
||||
register(
|
||||
'CUSTOM_LOGO',
|
||||
field_class=CustomLogoField,
|
||||
allow_blank=True,
|
||||
default='',
|
||||
label=_('Custom Logo'),
|
||||
help_text=_('To set up a custom logo, provide a file that you create. For '
|
||||
'the custom logo to look its best, use a `.png` file with a '
|
||||
'transparent background. GIF, PNG and JPEG formats are supported.'),
|
||||
placeholder='data:image/gif;base64,R0lGODlhAQABAAAAADs=',
|
||||
category=_('UI'),
|
||||
category_slug='ui',
|
||||
feature_required='rebranding',
|
||||
)
|
||||
|
||||
43
awx/ui/fields.py
Normal file
43
awx/ui/fields.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2016 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
# Python
|
||||
import base64
|
||||
import re
|
||||
|
||||
# Django
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
# Tower
|
||||
from awx.conf import fields, register
|
||||
|
||||
|
||||
class PendoTrackingStateField(fields.ChoiceField):
|
||||
|
||||
def to_internal_value(self, data):
|
||||
# Any false/null values get converted to 'off'.
|
||||
if data in fields.NullBooleanField.FALSE_VALUES or data in fields.NullBooleanField.NULL_VALUES:
|
||||
return 'off'
|
||||
return super(PendoTrackingStateField, self).to_internal_value(data)
|
||||
|
||||
|
||||
class CustomLogoField(fields.CharField):
|
||||
|
||||
CUSTOM_LOGO_RE = re.compile(r'^data:image/(?:png|jpeg|gif);base64,([A-Za-z0-9+/=]+?)$')
|
||||
|
||||
default_error_messages = {
|
||||
'invalid_format': _('Invalid format for custom logo. Must be a data URL with a base64-encoded GIF, PNG or JPEG image.'),
|
||||
'invalid_data': _('Invalid base64-encoded data in data URL.'),
|
||||
}
|
||||
|
||||
def to_internal_value(self, data):
|
||||
data = super(CustomLogoField, self).to_internal_value(data)
|
||||
match = self.CUSTOM_LOGO_RE.match(data)
|
||||
if not match:
|
||||
self.fail('invalid_format')
|
||||
b64data = match.group(1)
|
||||
try:
|
||||
base64.b64decode(b64data)
|
||||
except TypeError:
|
||||
self.fail('invalid_data')
|
||||
return data
|
||||
Reference in New Issue
Block a user