Explorar el Código

validate only enum value for profileSchema

Guénaël Muller hace 6 años
padre
commit
da09b2b478
Se han modificado 2 ficheros con 8 adiciones y 2 borrados
  1. 5 0
      tracim/models/auth.py
  2. 3 2
      tracim/views/core_api/schemas.py

+ 5 - 0
tracim/models/auth.py Ver fichero

@@ -96,6 +96,11 @@ class Profile(object):
96 96
              Group.TIM_MANAGER_GROUPNAME,
97 97
              Group.TIM_ADMIN_GROUPNAME]
98 98
 
99
+    _IDS = [Group.TIM_NOBODY,
100
+            Group.TIM_USER,
101
+            Group.TIM_MANAGER,
102
+            Group.TIM_ADMIN]
103
+
99 104
     # TODO - G.M - 18-04-2018 [Cleanup] Drop this
100 105
     # _LABEL = [l_('Nobody'),
101 106
     #           l_('Users'),

+ 3 - 2
tracim/views/core_api/schemas.py Ver fichero

@@ -3,13 +3,14 @@ import marshmallow
3 3
 from marshmallow import post_load
4 4
 from marshmallow.validate import OneOf
5 5
 
6
+from tracim.models.auth import Profile
6 7
 from tracim.models.context_models import LoginCredentials
7 8
 from tracim.models.data import UserRoleInWorkspace
8 9
 
9 10
 
10 11
 class ProfileSchema(marshmallow.Schema):
11
-    id = marshmallow.fields.Int(dump_only=True)
12
-    slug = marshmallow.fields.String(attribute='name')
12
+    id = marshmallow.fields.Int(dump_only=True, validate=OneOf(Profile._IDS))
13
+    slug = marshmallow.fields.String(attribute='name', validate=OneOf(Profile._NAME))
13 14
 
14 15
 
15 16
 class UserSchema(marshmallow.Schema):