schemas.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # coding=utf-8
  2. import marshmallow
  3. from marshmallow import post_load
  4. from marshmallow.validate import OneOf
  5. from tracim.models.context_models import LoginCredentials
  6. from tracim.models.data import UserRoleInWorkspace
  7. class ProfileSchema(marshmallow.Schema):
  8. id = marshmallow.fields.Int(dump_only=True)
  9. slug = marshmallow.fields.String(attribute='name')
  10. class UserSchema(marshmallow.Schema):
  11. user_id = marshmallow.fields.Int(dump_only=True)
  12. email = marshmallow.fields.Email(required=True)
  13. display_name = marshmallow.fields.String()
  14. created = marshmallow.fields.DateTime(format='iso8601')
  15. is_active = marshmallow.fields.Bool()
  16. # TODO - G.M - 17-04-2018 - Restrict timezone values
  17. timezone = marshmallow.fields.String()
  18. # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
  19. caldav_url = marshmallow.fields.Url(
  20. allow_none=True,
  21. relative=True,
  22. attribute='calendar_url'
  23. )
  24. avatar_url = marshmallow.fields.Url(allow_none=True)
  25. profile = marshmallow.fields.Nested(
  26. ProfileSchema,
  27. many=False,
  28. )
  29. class UserIdPathSchema(marshmallow.Schema):
  30. user_id = marshmallow.fields.Int()
  31. class WorkspaceIdPathSchema(marshmallow.Schema):
  32. workspace_id = marshmallow.fields.Int()
  33. class BasicAuthSchema(marshmallow.Schema):
  34. email = marshmallow.fields.Email(required=True)
  35. password = marshmallow.fields.String(required=True, load_only=True)
  36. @post_load
  37. def make_login(self, data):
  38. return LoginCredentials(**data)
  39. class LoginOutputHeaders(marshmallow.Schema):
  40. expire_after = marshmallow.fields.String()
  41. class NoContentSchema(marshmallow.Schema):
  42. pass
  43. class WorkspaceMenuEntrySchema(marshmallow.Schema):
  44. slug = marshmallow.fields.String()
  45. label = marshmallow.fields.String()
  46. route = marshmallow.fields.String()
  47. hexcolor = marshmallow.fields.String()
  48. icon = marshmallow.fields.String()
  49. class WorkspaceSchema(marshmallow.Schema):
  50. id = marshmallow.fields.Int()
  51. slug = marshmallow.fields.String()
  52. label = marshmallow.fields.String()
  53. description = marshmallow.fields.String()
  54. sidebar_entries = marshmallow.fields.Nested(
  55. WorkspaceMenuEntrySchema,
  56. many=True,
  57. )
  58. class WorkspaceDigestSchema(marshmallow.Schema):
  59. id = marshmallow.fields.Int()
  60. label = marshmallow.fields.String()
  61. sidebar_entries = marshmallow.fields.Nested(
  62. WorkspaceMenuEntrySchema,
  63. many=True,
  64. )
  65. class WorkspaceMemberSchema(marshmallow.Schema):
  66. role_id = marshmallow.fields.Int(validate=OneOf(UserRoleInWorkspace.get_all_role_values())) # nopep8
  67. role_slug = marshmallow.fields.String(validate=OneOf(UserRoleInWorkspace.get_all_role_slug())) # nopep8
  68. user_id = marshmallow.fields.Int()
  69. workspace_id = marshmallow.fields.Int()
  70. user = marshmallow.fields.Nested(
  71. UserSchema(only=('display_name', 'avatar_url'))
  72. )
  73. class ApplicationConfigSchema(marshmallow.Schema):
  74. pass
  75. # TODO - G.M - 24-05-2018 - Set this
  76. class ApplicationSchema(marshmallow.Schema):
  77. label = marshmallow.fields.String()
  78. slug = marshmallow.fields.String()
  79. icon = marshmallow.fields.String()
  80. hexcolor = marshmallow.fields.String()
  81. is_active = marshmallow.fields.Boolean()
  82. config = marshmallow.fields.Nested(
  83. ApplicationConfigSchema,
  84. )