class NewsSchema(Schema): id = fields.UUID(dump_only=True, attribute='uuid') status = fields.Integer() news_id = fields.String() timestamp_publish = fields.DateTime("%Y-%m-%dT%H:%M:%S+00:00") title = fields.String() news_type = fields.String() site = fields.String() lang = fields.String() excerpt = fields.String() news_category = fields.String() url = fields.Url() image_url = fields.String() body = fields.String() body_markdown = fields.String() # self links def get_top_level_links(self, data, many): if many: self_link = "/news/" else: self_link = "/news/{}".format(data['id']) return {'self': self_link} class Meta: type_ = 'news'
class RouteOutputSchema(JSONAPISchema): id = fields.UUID() origin = fields.Dict() origin_name = fields.String() destination = fields.Dict() destination_name = fields.String() polyline = fields.Dict() bounds = fields.Dict() created = fields.DateTime() class Meta: type_ = 'routes' strict = True inflect = dasherize @pre_dump(pass_many=True) def convert_geojson_to_dict(self, data, many): fields = ['origin', 'destination', 'polyline'] if many: for item in data: for field in fields: item[field] = escape.json_decode(item[field]) else: for field in fields: data[field] = escape.json_decode(data[field]) return data
class ProfileSchema(Schema): class Meta: type_ = 'profiles' self_view = 'profiles_api.profile_detail' self_view_kwargs = {'profile_id': '<id>'} self_view_many = 'profiles_api.profiles_list' id = fields.Int(dump_only=True) data = fields.String() description = fields.Str() display_name = fields.Str() expiration_date = fields.DateTime() identifier = fields.Str() organization = fields.Str() uuid = fields.UUID() removal_disallowed = fields.Boolean() version = fields.Int() scope = fields.Str() removal_date = fields.DateTime() duration_until_removal = fields.Int() consent_en = fields.Str() tags = Relationship(related_view='api_app.tag_detail', related_view_kwargs={'tag_id': '<id>'}, many=True, schema='TagSchema', type_='tags')
class ExampleSchema(marshmallow_jsonapi.Schema): id = fields.UUID(required=True) body = fields.Str() is_active = fields.Boolean(attribute='active') class Meta: type_ = 'example'
class ChildSchema(marshmallow_jsonapi.Schema): id = fields.UUID(required=True) name = fields.Str() class Meta: type_ = 'childs' strict = True
class TestSchema(marshmallow_jsonapi.Schema): id = fields.UUID() f1 = fields.Str(required=True) f2 = fields.Str(required=True) class Meta: type_ = 'test' strict = True
class RatingSchema(Schema): id = fields.UUID(dump_only=True, attribute='uid', required=True) type = fields.String() average = fields.Float(dump_only=True) n = fields.Integer(dump_only=True) class Meta: type_ = 'rating'
class ParentSchema(marshmallow_jsonapi.Schema): id = fields.UUID(required=True) name = fields.Str() children = fields.Relationship(schema=ChildSchema, type_='childs', many=True) class Meta: type_ = 'parents' include_resource_linkage = True strict = True
class ExampleSchema(marshmallow_jsonapi.Schema): id = fields.UUID(required=True) first_body = fields.Str() second_body = fields.Str() is_active = fields.Boolean(attribute='active') related = fields.Relationship(attribute='related_id') other_related = fields.Relationship(id_field='id') class Meta: type_ = 'example'
class ExampleSchema(marshmallow_jsonapi.Schema): id = fields.UUID(required=True) body = fields.Str() class Meta: type_ = 'example' self_view_many = 'example_list' self_view = 'example_detail' self_view_kwargs = {'example_id': '<id>'} strict = True
class ItemSchema(Schema): id = fields.UUID(dump_only=True) name = fields.Str() description = fields.Str() price = fields.Decimal(places=2) class Meta: type_ = "items" self_view = "items.items" self_view_kwargs = {"item_id": "<id>"} self_view_many = "items.items" strict = True
class ChannelsSchema(BaseSchema): id = fields.UUID(dump_only=True) publisher_id = fields.Integer() title = fields.Str() link = fields.Url() publication_updated_datetime = fields.DateTime() public_channel_id = fields.Str() class Meta: type_ = 'channels' strict = True
class ObjectSchema(Schema): id = fields.UUID() label = fields.String() digest = Digest() size = fields.Integer() mimetype = fields.String() create_dt = fields.DateTime() expire_dt = fields.DateTime() class Meta: type_ = 'paste' strict = True
class ActivitySchema(Schema): class Meta: type_ = 'activity' self_url = '/activity/{id}' self_url_kwargs = {'id': '<id>'} strict = True id = fields.UUID() uid = fields.String(required=True) activity_type = fields.Integer() content_type = fields.Integer() content_id = fields.String() created_at = fields.DateTime() updated_at = fields.DateTime()
class RouteInputSchema(JSONAPISchema): id = fields.UUID() origin = fields.Nested(GeoJSONSchema, required=True) origin_name = fields.String(required=True) destination = fields.Nested(GeoJSONSchema, required=True) destination_name = fields.String(required=True) waypoints = fields.List(fields.Float) waypoints_names = fields.List(fields.String) polyline = fields.Nested(GeoJSONSchema, required=True) bounds = fields.Dict() created = fields.DateTime(allow_none=True) class Meta: type_ = 'routes' strict = True inflect = dasherize
class InstalledProfileSchema(Schema): class Meta: type_ = 'installed_profiles' self_view = 'api_app.installed_profile_detail' self_view_kwargs = {'installed_profile_id': '<id>'} self_view_many = 'api_app.installed_profiles_list' id = fields.Int(dump_only=True) has_removal_password = fields.Bool() is_encrypted = fields.Bool() payload_description = fields.Str() payload_display_name = fields.Str() payload_identifier = fields.Str() payload_organization = fields.Str() payload_removal_disallowed = fields.Boolean() payload_uuid = fields.UUID()
class DEPAccountSchema(Schema): """DEP Account Details""" class Meta: type_ = 'dep_accounts' self_view = 'dep_app.dep_account_detail' self_view_kwargs = {'dep_account_id': '<id>'} self_view_many = 'dep_app.dep_accounts_list' strict = True id = fields.Int(dump_only=True) # stoken consumer_key = fields.String() consumer_secret = fields.String(load_only=True) access_token = fields.String() access_secret = fields.String(load_only=True) access_token_expiry = fields.DateTime(dump_only=True) token_updated_at = fields.DateTime(dump_only=True) auth_session_token = fields.String(load_only=True) # org server_name = fields.String() server_uuid = fields.UUID() admin_id = fields.String() facilitator_id = fields.String() org_name = fields.String() org_email = fields.Email() org_phone = fields.String() org_address = fields.String() # urls = fields.Nested(MDMServiceURL, many=True) org_type = fields.String() org_version = fields.String() org_id = fields.String() org_id_hash = fields.String() url = fields.String() cursor = fields.String() more_to_follow = fields.Boolean() fetched_until = fields.DateTime() dep_profiles = Relationship(related_view='dep_app.dep_profile_detail', related_view_kwargs={'dep_profile_id': '<id>'}, many=True, include_resource_linkage=True, schema='DEPProfileSchema', type_='dep_profiles')
class OrderSchema(Schema): id = fields.UUID(dump_only=True) items = Relationship( related_view="orders.orders_items", related_view_kwargs={"order_id": "<id>"}, many=True, include_resource_linkage=True, type_="items", ) status = EnumField(OrderStatus) class Meta: type_ = "orders" self_view = "orders.orders_get" self_view_kwargs = {"order_id": "<id>"} self_view_many = "orders.orders_all" strict = True
class CommunityPostSchema(Schema): class Meta: type_ = 'community_post' self_url = '/community/post/{id}' self_url_kwargs = {'id': '<id>'} strict = True id = fields.UUID() uid = fields.String(required=True) content = fields.String() image = fields.Boolean() likes = fields.Integer() shares = fields.Integer() hatsoffs = fields.Integer() public_flag = fields.Boolean() created_at = fields.DateTime() updated_at = fields.DateTime()
class SnippetsSchema(BaseSchema): id = fields.UUID(dump_only=True) desktop_redirect = fields.Url(required=True) desktop_redirect_count = fields.Integer(dump_only=True) mobile_redirect = fields.Url() mobile_redirect_count = fields.Integer(dump_only=True) tablet_redirect = fields.Url() tablet_redirect_count = fields.Integer(dump_only=True) short_url = fields.Url() time_since_creation = fields.Function( lambda obj: get_time_since_creation(obj), dump_only=True, ) class Meta: type_ = 'snippets' strict = True
class NewsSchema(Schema): id = fields.UUID(attribute="uuid") title = fields.Str() body_markdown = fields.Str() excerpt = fields.Str() timestamp_publish = fields.DateTime("%Y-%m-%dT%H:%M:%S+00:00") url = fields.Url() image_url = fields.Url(allow_none=True) lang = fields.Str() @pre_dump def empty_image_url_to_none(self, data): if not data.image_url: data.image_url = None return data class Meta: type_ = "news" strict = True
class DEPDeviceSchema(Schema): """The Device dictionary returned by the DEP Devices fetch endpoint. See Also: https://mdmenrollment.apple.com/server/devices """ serial_number = fields.String() model = fields.String() description = fields.String() color = fields.String() asset_tag = fields.String() profile_status = fields.String() profile_uuid = fields.UUID() profile_assign_time = fields.DateTime() profile_push_time = fields.DateTime() device_assigned_date = fields.DateTime() device_assigned_by = fields.Email() os = fields.String() device_family = fields.String()
class TaskSchema(Schema): id = fields.UUID() title = fields.Str(required=True, validate=validate.Length(min=1)) is_completed = fields.Boolean() created_at = fields.DateTime() class Meta: type_ = 'tasks' strict = True self_view = 'task_detail' self_view_kwargs = {'id': '<id>'} self_view_many = 'task_list' dateformat = '%Y-%m-%dT%H:%M:%S.%fZ' @validates('title') def validate_title(self, data): if data != data.strip(): raise ValidationError( 'Must not have leading or trailing whitespace.')
class EntriesSchema(BaseSchema): id = fields.UUID(dump_only=True) publisher_id = fields.Integer() channel_id = fields.Integer() title = fields.Str() channel_title = fields.Str() link = fields.Url() description = fields.Str() content = fields.Str() content_type = fields.Str() media_image_url = fields.Url() public_entry_id = fields.Str() published_updated_datetime = fields.DateTime() published_datetime = fields.DateTime() class Meta: type_ = 'entries' strict = True
class UserSchema(Schema): # not_blank = validate.Length(min=1, error='Field cannot be blank') id = fields.UUID(dump_only=True, attribute='uid', required=True) auth0_user_id = fields.String(dump_only=True) name = fields.String() # nickname? email = fields.String() location = fields.String() gender = fields.String() status = fields.String() created_at = fields.Date(dump_only=True, attribute='_created_at') updated_at = fields.Date(dump_only=True, attribute='_updated_at') spoken_languages = fields.Nested(LanguageSchema, many=True) learning_languages = fields.Nested(LanguageSchema, many=True) ratings = fields.Nested(RatingSchema, dump_only=True, many=True) # self links def get_top_level_links(self, data, many): return {'self': "/users/{}".format(data['id'])} class Meta: type_ = 'user'
class VideoSchema(Schema): id = fields.UUID(dump_only=True, attribute='uuid') status = fields.Integer(required=True) video_id = fields.String() timestamp_publish = fields.DateTime("%Y-%m-%dT%H:%M:%S+00:00") url = fields.Url() site = fields.String() title = fields.String() description = fields.String() thumbnail_url = fields.Url() description_snippet = fields.String() # self links def get_top_level_links(self, data, many): if many: self_link = "/videos/" else: self_link = "/videos/{}".format(data['id']) return {'self': self_link} class Meta: type_ = 'video'
class LanguageSchema(Schema): id = fields.UUID(dump_only=True, attribute='uid', required=True) name = fields.String(required=True) class Meta: type_ = 'language'
class DeviceSchema(Schema): class Meta: type_ = 'devices' self_view = 'api_app.device_detail' self_view_kwargs = {'device_id': '<id>'} self_view_many = 'api_app.devices_list' strict = True id = fields.Int(dump_only=True) udid = fields.Str(dump_only=True) topic = fields.Str() build_version = fields.Str() # device_name and hostname are "pseudo" read-only in that writing them does not affect the field but enqueues # an MDM command to change the name. device_name = fields.Str() hostname = fields.Str() local_hostname = fields.Str(dump_only=True) model = fields.Str() model_name = fields.Str() os_version = fields.Str() product_name = fields.Str() serial_number = fields.Str() awaiting_configuration = fields.Bool() last_seen = fields.DateTime(dump_only=True) available_device_capacity = fields.Float() device_capacity = fields.Float() wifi_mac = fields.Str() bluetooth_mac = fields.Str() # private # push_magic = fields.Str() # token = fields.Str() # unlock_token = fields.Str() tokenupdate_at = fields.DateTime() # SecurityInfo passcode_present = fields.Bool() passcode_compliant = fields.Bool() passcode_compliant_with_profiles = fields.Bool() fde_enabled = fields.Bool() fde_has_prk = fields.Bool() fde_has_irk = fields.Bool() firewall_enabled = fields.Bool() block_all_incoming = fields.Bool() stealth_mode_enabled = fields.Bool() sip_enabled = fields.Bool() battery_level = fields.Float(dump_only=True) imei = fields.Str(dump_only=True) is_cloud_backup_enabled = fields.Bool(dump_only=True) itunes_store_account_is_active = fields.Bool(dump_only=True) last_cloud_backup_date = fields.DateTime(dump_only=True) # TODO: Relationship to dep_config # certificate = Relationship( # self_view='api_app.device_certificate', # self_view_kwargs={'certificate_id': '<id>'}, # related_view='api_app.certificate_detail', # related_view_kwargs={'certificate_id': '<id>'}, # ) # DEP is_dep = fields.Bool() description = fields.Str(dump_only=True) color = fields.Str(dump_only=True) asset_tag = fields.Str(dump_only=True) profile_status = fields.Str(dump_only=True) profile_uuid = fields.UUID(dump_only=True) profile_assign_time = fields.DateTime(dump_only=True) profile_push_time = fields.DateTime(dump_only=True) device_assigned_date = fields.DateTime(dump_only=True) device_assigned_by = fields.Str(dump_only=True) os = fields.Str(dump_only=True) device_family = fields.Str(dump_only=True) commands = Relationship(related_view='api_app.commands_list', related_view_kwargs={'device_id': '<id>'}, many=True, schema='CommandSchema', type_='commands') installed_certificates = Relationship( related_view='api_app.installed_certificates_list', related_view_kwargs={'device_id': '<id>'}, many=True, schema='InstalledCertificateSchema', type_='installed_certificates') installed_applications = Relationship( related_view='api_app.installed_applications_list', related_view_kwargs={'device_id': '<id>'}, many=True, schema='InstalledApplicationSchema', type_='installed_applications') tags = Relationship(related_view='api_app.tags_list', related_view_kwargs={'device_id': '<id>'}, many=True, schema='TagSchema', type_='tags') available_os_updates = Relationship( related_view='api_app.available_os_updates_list', related_view_kwargs={'device_id': '<id>'}, many=True, schema='AvailableOSUpdateSchema', type_='available_os_updates') dep_profile = Relationship( related_view='dep_app.dep_profile_detail', related_view_kwargs={'dep_profile_id': '<dep_profile_id>'}, many=False, schema='DEPProfileSchema', type_='dep_profiles', )
class DEPProfileSchema(Schema): """marshmallow schema for a DEP profile. See Also: - `/profile endpoint <https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/MobileDeviceManagementProtocolRef/4-Profile_Management/ProfileManagement.html#//apple_ref/doc/uid/TP40017387-CH7-SW6>`_. - `Mobile Device Management Protocol Reference <https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf>`_ "Define Profile" pg. 120 """ class Meta: type_ = 'dep_profiles' self_view = 'dep_app.dep_profile_detail' self_view_kwargs = {'dep_profile_id': '<id>'} self_view_many = 'dep_app.dep_profiles_list' strict = True id = fields.Int(dump_only=True) uuid = fields.UUID(dump_only=True) """str: The Apple assigned UUID of this DEP Profile""" profile_name = fields.String(required=True) """str: A human-readable name for the profile.""" url = fields.Url(required=False) # Should be required """str: The URL of the MDM server.""" allow_pairing = fields.Boolean(default=True) """bool: If true, any device can pair with this device, supervision certs are not required.""" is_supervised = fields.Boolean(default=False) """bool: If true, the device must be supervised""" is_multi_user = fields.Boolean(default=False) """bool: If true, tells the device to configure for Shared iPad.""" is_mandatory = fields.Boolean(default=False) """bool: If true, the user may not skip applying the profile returned by the MDM server""" await_device_configured = fields.Boolean() """bool: If true, Setup Assistant does not continue until the MDM server sends DeviceConfigured.""" is_mdm_removable = fields.Boolean() """bool: If false, the MDM payload delivered by the configuration URL cannot be removed by the user via the user interface on the device""" support_phone_number = fields.String(allow_none=True) """str: A support phone number for the organization.""" auto_advance_setup = fields.Boolean() """bool: If set to true, the device will tell tvOS Setup Assistant to automatically advance though its screens.""" support_email_address = fields.String( allow_none=True) # No need to perform validation here """str: A support email address for the organization.""" org_magic = fields.String(allow_none=True) """str: A string that uniquely identifies various services that are managed by a single organization.""" anchor_certs = fields.List(fields.String()) """List[str]: Each string should contain a DER-encoded certificate converted to Base64 encoding. If provided, these certificates are used as trusted anchor certificates when evaluating the trust of the connection to the MDM server URL.""" supervising_host_certs = fields.List(fields.String()) """List[str]: Each string contains a DER-encoded certificate converted to Base64 encoding. If provided, the device will continue to pair with a host possessing one of these certificates even when allow_pairing is set to false""" skip_setup_items = fields.List(EnumField(SetupAssistantStep)) """Set[SetupAssistantStep]: A list of setup panes to skip""" department = fields.String(allow_none=True) """str: The user-defined department or location name.""" last_upload_at = fields.DateTime(dump_only=True) """datetime: The last time this profile was uploaded/synced to apple. null if it was never synced.""" devices = Relationship(related_view='api_app.devices_list', related_view_kwargs={'dep_profile_id': '<id>'}, many=True, include_resource_linkage=True, schema='DeviceSchema', type_='devices') dep_account = Relationship( self_view='dep_app.dep_profile_dep_account', self_view_kwargs={'dep_profile_id': '<id>'}, related_view='dep_app.dep_account_detail', related_view_kwargs={'dep_account_id': '<dep_account_id>'}, many=False, include_resource_linkage=True, schema='DEPAccountSchema', type_='dep_accounts')