"""Settings Whitelisted Profiles Schema.""" from marshmallow import fields, pre_load from marshmallow.validate import Length, OneOf from permissions.constants import constants from permissions.validations import ma class SettingsWhitelistProfilesSchema(ma.Schema): """Schema for allowed profile types in Settings app. Properties: - profile_type (str): Type of profile. currently 'InsightsProfile' only. - roles (list): List of role. e.g: ['marketing', 'analytics'] """ profile_type = fields.Str( validate=OneOf(constants.SETTINGS_SUPPORT_MAPPING['profileTypes']), required=True ) roles = fields.List( fields.String(validate=OneOf(constants.PROFILE_ROLE_TYPES)), required=True, validate=Length(min=1), ) @pre_load def slugify_roles(self, in_data, **kwargs): """Convert roles values to required format.""" if in_data.get('roles'): in_data['roles'] = [x.lower().strip().replace(' ', '_') for x in in_data['roles']] return in_data