# coding=utf-8 import marshmallow from marshmallow import post_load from marshmallow.validate import OneOf from marshmallow.validate import Range from tracim.lib.utils.utils import DATETIME_FORMAT from tracim.models.auth import Profile from tracim.models.contents import GlobalStatus from tracim.models.contents import open_status from tracim.models.contents import ContentTypeLegacy as ContentType from tracim.models.contents import ContentStatusLegacy as ContentStatus from tracim.models.context_models import ContentCreation from tracim.models.context_models import UserCreation from tracim.models.context_models import SetEmail from tracim.models.context_models import SetPassword from tracim.models.context_models import UserInfos from tracim.models.context_models import UserProfile from tracim.models.context_models import CommentCreation from tracim.models.context_models import TextBasedContentUpdate from tracim.models.context_models import SetContentStatus from tracim.models.context_models import CommentPath from tracim.models.context_models import MoveParams from tracim.models.context_models import WorkspaceAndContentPath from tracim.models.context_models import ContentFilter from tracim.models.context_models import LoginCredentials from tracim.models.data import UserRoleInWorkspace class UserDigestSchema(marshmallow.Schema): """ Simple user schema """ user_id = marshmallow.fields.Int(dump_only=True, example=3) 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)", ) public_name = marshmallow.fields.String( example='Suri Cate', ) class UserSchema(UserDigestSchema): """ Complete user schema """ email = marshmallow.fields.Email( required=True, example='suri.cate@algoo.fr' ) created = marshmallow.fields.DateTime( format=DATETIME_FORMAT, description='User account creation date', ) is_active = marshmallow.fields.Bool( example=True, description='Is user account activated ?' ) # TODO - G.M - 17-04-2018 - Restrict timezone values timezone = marshmallow.fields.String( example="Europe/Paris", ) # 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", ) profile = marshmallow.fields.String( attribute='profile', validate=OneOf(Profile._NAME), example='managers', ) class Meta: description = 'User account of Tracim' class LoggedInUserPasswordSchema(marshmallow.Schema): loggedin_user_password = marshmallow.fields.String( required=True, ) class SetEmailSchema(LoggedInUserPasswordSchema): email = marshmallow.fields.Email( required=True, example='suri.cate@algoo.fr' ) @post_load def create_set_email_object(self, data): return SetEmail(**data) class SetPasswordSchema(LoggedInUserPasswordSchema): new_password = marshmallow.fields.String( example='8QLa$