"""Master Contact Schema.""" from marshmallow import Schema from marshmallow import fields from marshmallow import post_load class CreateMasterContactSchema(Schema): """Create Vendor schema. Properties: -email (str): the email for this contact -brand (str): brand under which this user is being created -first_name (str): first name of user -last_name (str): last name of user -vendor_id (str): uuid of created vendor -localization (str): language preference of user 639-1 format 12 supported languages -master_contact (bool): set as True for creation of master contact """ email = fields.String(required=True) brand = fields.String(required=False, default='orchard') first_name = fields.String(required=True) last_name = fields.String(required=True) vendor_id = fields.Integer(required=True) localization = fields.String(required=False) master_contact = fields.String(required=False, missing='TRUE') roles = fields.List(fields.String(), required=False) is_admin = fields.String(required=False) @post_load def convert_to_boolean(self, item, **kwargs): """Convert string to boolean.""" # All master_contact users should be admins by default if item.get('master_contact'): item['master_contact'] = \ True if item['master_contact'].upper() == 'TRUE' else False if item.get('is_admin'): item['is_admin'] = True if ( item['is_admin'].upper() == 'TRUE' or item['master_contact']) \ else False return item