# coding=utf-8 import marshmallow from marshmallow import post_load from marshmallow.validate import OneOf from tracim.models.auth import Profile from tracim.models.contents import CONTENT_DEFAULT_TYPE, GlobalStatus, CONTENT_DEFAULT_STATUS from tracim.models.context_models import LoginCredentials, ContentFilter from tracim.models.data import UserRoleInWorkspace class ProfileSchema(marshmallow.Schema): slug = marshmallow.fields.String( attribute='name', validate=OneOf(Profile._NAME), example='managers', ) class Meta: description = 'User Profile, give user right on whole Tracim instance.' class UserSchema(marshmallow.Schema): user_id = marshmallow.fields.Int(dump_only=True, example=3) email = marshmallow.fields.Email( required=True, example='suri.cate@algoo.fr' ) display_name = marshmallow.fields.String( example='Suri Cate', ) created = marshmallow.fields.DateTime( format='iso8601', description='User account creation date (iso8601 format).', ) is_active = marshmallow.fields.Bool( example=True, # TODO - G.M - Explains this value. ) # TODO - G.M - 17-04-2018 - Restrict timezone values timezone = marshmallow.fields.String( example="Paris/Europe", ) # TODO - G.M - 17-04-2018 - check this, relative url allowed ? caldav_url = marshmallow.fields.Url( allow_none=True, relative=True, attribute='calendar_url', example="/api/v2/calendar/user/3.ics/", description="The url for calendar CalDAV direct access", ) avatar_url = marshmallow.fields.Url( allow_none=True, example="/api/v2/assets/avatars/suri-cate.jpg", description="avatar_url is the url to the image file. " "If no avatar, then set it to null " "(and frontend will interpret this with a default avatar)", ) profile = marshmallow.fields.Nested( ProfileSchema, many=False, ) class Meta: description = 'User account of Tracim' # Path Schemas class UserIdPathSchema(marshmallow.Schema): user_id = marshmallow.fields.Int(example=3, required=True) class WorkspaceIdPathSchema(marshmallow.Schema): workspace_id = marshmallow.fields.Int(example=4, required=True) class ContentIdPathSchema(marshmallow.Schema): content_id = marshmallow.fields.Int(example=6, required=True) class WorkspaceAndContentIdPathSchema(WorkspaceIdPathSchema, ContentIdPathSchema): pass class FilterContentQuerySchema(marshmallow.Schema): parent_id = workspace_id = marshmallow.fields.Int( example=2, default=None, description='allow to filter items in a folder.' ' If not set, then return all contents.' ' If set to 0, then return root contents.' ' If set to another value, return all contents' ' directly included in the folder parent_id' ) show_archived = marshmallow.fields.Int( example=0, default=0, description='if set to 1, then show archived contents.' ' Default is 0 - hide archived content' ) show_deleted = marshmallow.fields.Int( example=0, default=0, description='if set to 1, then show deleted contents.' ' Default is 0 - hide deleted content' ) show_active = marshmallow.fields.Int( example=1, default=1, description='f set to 1, then show active contents. ' 'Default is 1 - show active content.' ' Note: active content are content ' 'that is neither archived nor deleted. ' 'The reason for this parameter to exist is for example ' 'to allow to show only archived documents' ) @post_load def make_content_filter(self, data): return ContentFilter(**data) ### class BasicAuthSchema(marshmallow.Schema): email = marshmallow.fields.Email( example='suri.cate@algoo.fr', required=True ) password = marshmallow.fields.String( example='8QLa$