schemas.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. # coding=utf-8
  2. import marshmallow
  3. from marshmallow import post_load
  4. from marshmallow.validate import OneOf
  5. from tracim.models.auth import Profile
  6. from tracim.models.context_models import LoginCredentials
  7. from tracim.models.data import UserRoleInWorkspace
  8. class ProfileSchema(marshmallow.Schema):
  9. slug = marshmallow.fields.String(
  10. attribute='name',
  11. validate=OneOf(Profile._NAME),
  12. example='managers',
  13. )
  14. class Meta:
  15. description = 'User Profile, give user right on whole Tracim instance.'
  16. class UserSchema(marshmallow.Schema):
  17. user_id = marshmallow.fields.Int(dump_only=True, example=3)
  18. email = marshmallow.fields.Email(
  19. required=True,
  20. example='suri.cate@algoo.fr'
  21. )
  22. display_name = marshmallow.fields.String(
  23. example='Suri Cate',
  24. )
  25. created = marshmallow.fields.DateTime(
  26. format='iso8601',
  27. description='User account creation date (iso8601 format).',
  28. )
  29. is_active = marshmallow.fields.Bool(
  30. example=True,
  31. # TODO - G.M - Explains this value.
  32. )
  33. # TODO - G.M - 17-04-2018 - Restrict timezone values
  34. timezone = marshmallow.fields.String(
  35. example="Paris/Europe",
  36. )
  37. # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
  38. caldav_url = marshmallow.fields.Url(
  39. allow_none=True,
  40. relative=True,
  41. attribute='calendar_url',
  42. example="/api/v2/calendar/user/3.ics/",
  43. description="The url for calendar CalDAV direct access",
  44. )
  45. avatar_url = marshmallow.fields.Url(
  46. allow_none=True,
  47. example="/api/v2/assets/avatars/suri-cate.jpg",
  48. description="avatar_url is the url to the image file. "
  49. "If no avatar, then set it to null "
  50. "(and frontend will interpret this with a default avatar)",
  51. )
  52. profile = marshmallow.fields.Nested(
  53. ProfileSchema,
  54. many=False,
  55. )
  56. class Meta:
  57. description = 'User account of Tracim'
  58. class UserIdPathSchema(marshmallow.Schema):
  59. user_id = marshmallow.fields.Int(example=3)
  60. class WorkspaceIdPathSchema(marshmallow.Schema):
  61. workspace_id = marshmallow.fields.Int(example=4)
  62. class BasicAuthSchema(marshmallow.Schema):
  63. email = marshmallow.fields.Email(
  64. example='suri.cate@algoo.fr',
  65. required=True
  66. )
  67. password = marshmallow.fields.String(
  68. example='8QLa$<w',
  69. required=True,
  70. load_only=True,
  71. )
  72. class Meta:
  73. description = 'Entry for HTTP Basic Auth'
  74. @post_load
  75. def make_login(self, data):
  76. return LoginCredentials(**data)
  77. class LoginOutputHeaders(marshmallow.Schema):
  78. expire_after = marshmallow.fields.String()
  79. class NoContentSchema(marshmallow.Schema):
  80. class Meta:
  81. description = 'Empty Schema'
  82. pass
  83. class WorkspaceMenuEntrySchema(marshmallow.Schema):
  84. slug = marshmallow.fields.String(example='markdown-pages')
  85. label = marshmallow.fields.String(example='Markdown Documents')
  86. route = marshmallow.fields.String(
  87. example='/#/workspace/{workspace_id}/contents/?type=mardown-page',
  88. description='the route is the frontend route. '
  89. 'It may include workspace_id '
  90. 'which must be replaced on backend size '
  91. '(the route must be ready-to-use)'
  92. )
  93. icon = marshmallow.fields.String(
  94. example='file-text-o',
  95. description='CSS class of the icon. Example: file-o for using Fontawesome file-text-o icon', # nopep8
  96. )
  97. hexcolor = marshmallow.fields.String(
  98. example='#F0F9DC',
  99. description='Hexadecimal color of the entry.'
  100. )
  101. class Meta:
  102. description = 'Entry element of a workspace menu'
  103. class WorkspaceDigestSchema(marshmallow.Schema):
  104. id = marshmallow.fields.Int(example=4)
  105. label = marshmallow.fields.String(example='Intranet')
  106. sidebar_entries = marshmallow.fields.Nested(
  107. WorkspaceMenuEntrySchema,
  108. many=True,
  109. )
  110. class Meta:
  111. description = 'Digest of workspace informations'
  112. class WorkspaceSchema(WorkspaceDigestSchema):
  113. slug = marshmallow.fields.String(example='intranet')
  114. description = marshmallow.fields.String(example='All intranet data.')
  115. class Meta:
  116. description = 'Full workspace informations'
  117. class WorkspaceMemberSchema(marshmallow.Schema):
  118. role_slug = marshmallow.fields.String(
  119. example='contributor',
  120. validate=OneOf(UserRoleInWorkspace.get_all_role_slug())
  121. )
  122. user_id = marshmallow.fields.Int(example=3)
  123. workspace_id = marshmallow.fields.Int(example=4)
  124. user = marshmallow.fields.Nested(
  125. UserSchema(only=('display_name', 'avatar_url'))
  126. )
  127. class Meta:
  128. description = 'Workspace Member information'
  129. class ApplicationConfigSchema(marshmallow.Schema):
  130. pass
  131. # TODO - G.M - 24-05-2018 - Set this
  132. class ApplicationSchema(marshmallow.Schema):
  133. label = marshmallow.fields.String(example='Calendar')
  134. slug = marshmallow.fields.String(example='calendar')
  135. icon = marshmallow.fields.String(
  136. example='file-o',
  137. description='CSS class of the icon. Example: file-o for using Fontawesome file-o icon', # nopep8
  138. )
  139. hexcolor = marshmallow.fields.String(
  140. example='#FF0000',
  141. description='HTML encoded color associated to the application. Example:#FF0000 for red' # nopep8
  142. )
  143. is_active = marshmallow.fields.Boolean(
  144. example=True,
  145. description='if true, the application is in use in the context',
  146. )
  147. config = marshmallow.fields.Nested(
  148. ApplicationConfigSchema,
  149. )
  150. class Meta:
  151. description = 'Tracim Application informations'