浏览代码

add lang support in endpoint,internal lib and tests

Guénaël Muller 6 年前
父节点
当前提交
c45953dfae

+ 6 - 0
backend/tracim_backend/lib/core/user.py 查看文件

314
             email: str=None,
314
             email: str=None,
315
             password: str=None,
315
             password: str=None,
316
             timezone: str=None,
316
             timezone: str=None,
317
+            lang: str=None,
317
             groups: typing.Optional[typing.List[Group]]=None,
318
             groups: typing.Optional[typing.List[Group]]=None,
318
             do_save=True,
319
             do_save=True,
319
     ) -> User:
320
     ) -> User:
330
         if timezone is not None:
331
         if timezone is not None:
331
             user.timezone = timezone
332
             user.timezone = timezone
332
 
333
 
334
+        if lang is not None:
335
+            user.lang = lang
336
+
333
         if groups is not None:
337
         if groups is not None:
334
             # INFO - G.M - 2018-07-18 - Delete old groups
338
             # INFO - G.M - 2018-07-18 - Delete old groups
335
             for group in user.groups:
339
             for group in user.groups:
351
         password: str = None,
355
         password: str = None,
352
         name: str = None,
356
         name: str = None,
353
         timezone: str = '',
357
         timezone: str = '',
358
+        lang: str= None,
354
         groups=[],
359
         groups=[],
355
         do_save: bool=True,
360
         do_save: bool=True,
356
         do_notify: bool=True,
361
         do_notify: bool=True,
362
             email=email,
367
             email=email,
363
             password=password,
368
             password=password,
364
             timezone=timezone,
369
             timezone=timezone,
370
+            lang=lang,
365
             do_save=False,
371
             do_save=False,
366
         )
372
         )
367
         if do_notify:
373
         if do_notify:

+ 8 - 1
backend/tracim_backend/models/context_models.py 查看文件

81
     """
81
     """
82
     Just some user infos
82
     Just some user infos
83
     """
83
     """
84
-    def __init__(self, timezone: str, public_name: str) -> None:
84
+    def __init__(self, timezone: str, public_name: str, lang: str) -> None:
85
         self.timezone = timezone
85
         self.timezone = timezone
86
         self.public_name = public_name
86
         self.public_name = public_name
87
+        self.lang = lang
87
 
88
 
88
 
89
 
89
 class UserProfile(object):
90
 class UserProfile(object):
105
             public_name: str = None,
106
             public_name: str = None,
106
             timezone: str = None,
107
             timezone: str = None,
107
             profile: str = None,
108
             profile: str = None,
109
+            lang: str = None,
108
             email_notification: bool = True,
110
             email_notification: bool = True,
109
     ) -> None:
111
     ) -> None:
110
         self.email = email
112
         self.email = email
113
         self.password = password or password_generator()
115
         self.password = password or password_generator()
114
         self.public_name = public_name or None
116
         self.public_name = public_name or None
115
         self.timezone = timezone or ''
117
         self.timezone = timezone or ''
118
+        self.lang = lang or None
116
         self.profile = profile or Group.TIM_USER_GROUPNAME
119
         self.profile = profile or Group.TIM_USER_GROUPNAME
117
         self.email_notification = email_notification
120
         self.email_notification = email_notification
118
 
121
 
407
         return self.user.timezone
410
         return self.user.timezone
408
 
411
 
409
     @property
412
     @property
413
+    def lang(self) -> str:
414
+        return self.user.lang
415
+
416
+    @property
410
     def profile(self) -> Profile:
417
     def profile(self) -> Profile:
411
         return self.user.profile.name
418
         return self.user.profile.name
412
 
419
 

+ 2 - 0
backend/tracim_backend/tests/functional/test_session.py 查看文件

160
         assert res.json_body['profile'] == 'administrators'
160
         assert res.json_body['profile'] == 'administrators'
161
         assert res.json_body['caldav_url'] is None
161
         assert res.json_body['caldav_url'] is None
162
         assert res.json_body['avatar_url'] is None
162
         assert res.json_body['avatar_url'] is None
163
+        assert res.json_body['lang'] is None
163
 
164
 
164
     def test_api__try_whoami_enpoint__err_401__user_is_not_active(self):
165
     def test_api__try_whoami_enpoint__err_401__user_is_not_active(self):
165
         dbsession = get_tm_session(self.session_factory, transaction.manager)
166
         dbsession = get_tm_session(self.session_factory, transaction.manager)
183
             name='bob',
184
             name='bob',
184
             groups=groups,
185
             groups=groups,
185
             timezone='Europe/Paris',
186
             timezone='Europe/Paris',
187
+            lang='en',
186
             do_save=True,
188
             do_save=True,
187
             do_notify=False,
189
             do_notify=False,
188
         )
190
         )

+ 81 - 2
backend/tracim_backend/tests/functional/test_user.py 查看文件

74
             name='bob',
74
             name='bob',
75
             groups=groups,
75
             groups=groups,
76
             timezone='Europe/Paris',
76
             timezone='Europe/Paris',
77
+            lang='fr',
77
             do_save=True,
78
             do_save=True,
78
             do_notify=False,
79
             do_notify=False,
79
         )
80
         )
198
             name='bob',
199
             name='bob',
199
             groups=groups,
200
             groups=groups,
200
             timezone='Europe/Paris',
201
             timezone='Europe/Paris',
202
+            lang='fr',
201
             do_save=True,
203
             do_save=True,
202
             do_notify=False,
204
             do_notify=False,
203
         )
205
         )
289
             name='bob',
291
             name='bob',
290
             groups=groups,
292
             groups=groups,
291
             timezone='Europe/Paris',
293
             timezone='Europe/Paris',
294
+            lang='fr',
292
             do_save=True,
295
             do_save=True,
293
             do_notify=False,
296
             do_notify=False,
294
         )
297
         )
414
             name='bob',
417
             name='bob',
415
             groups=groups,
418
             groups=groups,
416
             timezone='Europe/Paris',
419
             timezone='Europe/Paris',
420
+            lang='fr',
417
             do_save=True,
421
             do_save=True,
418
             do_notify=False,
422
             do_notify=False,
419
         )
423
         )
702
             name='bob',
706
             name='bob',
703
             groups=groups,
707
             groups=groups,
704
             timezone='Europe/Paris',
708
             timezone='Europe/Paris',
709
+            lang='fr',
705
             do_save=True,
710
             do_save=True,
706
             do_notify=False,
711
             do_notify=False,
707
         )
712
         )
814
             name='bob',
819
             name='bob',
815
             groups=groups,
820
             groups=groups,
816
             timezone='Europe/Paris',
821
             timezone='Europe/Paris',
822
+            lang='fr',
817
             do_save=True,
823
             do_save=True,
818
             do_notify=False,
824
             do_notify=False,
819
         )
825
         )
937
             name='bob',
943
             name='bob',
938
             groups=groups,
944
             groups=groups,
939
             timezone='Europe/Paris',
945
             timezone='Europe/Paris',
946
+            lang='fr',
940
             do_save=True,
947
             do_save=True,
941
             do_notify=False,
948
             do_notify=False,
942
         )
949
         )
1150
             name='bob',
1157
             name='bob',
1151
             groups=groups,
1158
             groups=groups,
1152
             timezone='Europe/Paris',
1159
             timezone='Europe/Paris',
1160
+            lang='fr',
1153
             do_save=True,
1161
             do_save=True,
1154
             do_notify=False,
1162
             do_notify=False,
1155
         )
1163
         )
1231
             name='bob',
1239
             name='bob',
1232
             groups=groups,
1240
             groups=groups,
1233
             timezone='Europe/Paris',
1241
             timezone='Europe/Paris',
1242
+            lang='fr',
1234
             do_save=True,
1243
             do_save=True,
1235
             do_notify=False,
1244
             do_notify=False,
1236
         )
1245
         )
1312
             name='bob',
1321
             name='bob',
1313
             groups=groups,
1322
             groups=groups,
1314
             timezone='Europe/Paris',
1323
             timezone='Europe/Paris',
1324
+            lang='fr',
1315
             do_save=True,
1325
             do_save=True,
1316
             do_notify=False,
1326
             do_notify=False,
1317
         )
1327
         )
1411
             name='bob',
1421
             name='bob',
1412
             groups=groups,
1422
             groups=groups,
1413
             timezone='Europe/Paris',
1423
             timezone='Europe/Paris',
1424
+            lang='fr',
1414
             do_save=True,
1425
             do_save=True,
1415
             do_notify=False,
1426
             do_notify=False,
1416
         )
1427
         )
1492
             name='bob',
1503
             name='bob',
1493
             groups=groups,
1504
             groups=groups,
1494
             timezone='Europe/Paris',
1505
             timezone='Europe/Paris',
1506
+            lang='fr',
1495
             do_save=True,
1507
             do_save=True,
1496
             do_notify=False,
1508
             do_notify=False,
1497
         )
1509
         )
1609
             name='bob',
1621
             name='bob',
1610
             groups=groups,
1622
             groups=groups,
1611
             timezone='Europe/Paris',
1623
             timezone='Europe/Paris',
1624
+            lang='fr',
1612
             do_save=True,
1625
             do_save=True,
1613
             do_notify=False,
1626
             do_notify=False,
1614
         )
1627
         )
1718
             name='bob',
1731
             name='bob',
1719
             groups=groups,
1732
             groups=groups,
1720
             timezone='Europe/Paris',
1733
             timezone='Europe/Paris',
1734
+            lang='fr',
1721
             do_save=True,
1735
             do_save=True,
1722
             do_notify=False,
1736
             do_notify=False,
1723
         )
1737
         )
1799
             name='bob',
1813
             name='bob',
1800
             groups=groups,
1814
             groups=groups,
1801
             timezone='Europe/Paris',
1815
             timezone='Europe/Paris',
1816
+            lang='fr',
1802
             do_save=True,
1817
             do_save=True,
1803
             do_notify=False,
1818
             do_notify=False,
1804
         )
1819
         )
1881
             name='bob',
1896
             name='bob',
1882
             groups=groups,
1897
             groups=groups,
1883
             timezone='Europe/Paris',
1898
             timezone='Europe/Paris',
1899
+            lang='fr',
1884
             do_save=True,
1900
             do_save=True,
1885
             do_notify=False,
1901
             do_notify=False,
1886
         )
1902
         )
1976
             name='bob',
1992
             name='bob',
1977
             groups=groups,
1993
             groups=groups,
1978
             timezone='Europe/Paris',
1994
             timezone='Europe/Paris',
1995
+            lang='fr',
1979
             do_save=True,
1996
             do_save=True,
1980
             do_notify=False,
1997
             do_notify=False,
1981
         )
1998
         )
2120
             name='bob',
2137
             name='bob',
2121
             groups=groups,
2138
             groups=groups,
2122
             timezone='Europe/Paris',
2139
             timezone='Europe/Paris',
2140
+            lang='fr',
2123
             do_save=True,
2141
             do_save=True,
2124
             do_notify=False,
2142
             do_notify=False,
2125
         )
2143
         )
2217
             name='bob',
2235
             name='bob',
2218
             groups=groups,
2236
             groups=groups,
2219
             timezone='Europe/Paris',
2237
             timezone='Europe/Paris',
2238
+            lang='fr',
2220
             do_save=True,
2239
             do_save=True,
2221
             do_notify=False,
2240
             do_notify=False,
2222
         )
2241
         )
2314
             name='bob',
2333
             name='bob',
2315
             groups=groups,
2334
             groups=groups,
2316
             timezone='Europe/Paris',
2335
             timezone='Europe/Paris',
2336
+            lang='fr',
2317
             do_save=True,
2337
             do_save=True,
2318
             do_notify=False,
2338
             do_notify=False,
2319
         )
2339
         )
2423
         assert sidebar_entry['hexcolor'] == "#ad4cf9"
2443
         assert sidebar_entry['hexcolor'] == "#ad4cf9"
2424
         assert sidebar_entry['fa_icon'] == "comments-o"
2444
         assert sidebar_entry['fa_icon'] == "comments-o"
2425
 
2445
 
2426
-
2427
     def test_api__get_user_workspaces__err_403__unallowed_user(self):
2446
     def test_api__get_user_workspaces__err_403__unallowed_user(self):
2428
         """
2447
         """
2429
         Check obtain all workspaces reachables for one user
2448
         Check obtain all workspaces reachables for one user
2509
             name='bob',
2528
             name='bob',
2510
             groups=groups,
2529
             groups=groups,
2511
             timezone='Europe/Paris',
2530
             timezone='Europe/Paris',
2531
+            lang='fr',
2512
             do_save=True,
2532
             do_save=True,
2513
             do_notify=False,
2533
             do_notify=False,
2514
         )
2534
         )
2536
         assert res['public_name'] == 'bob'
2556
         assert res['public_name'] == 'bob'
2537
         assert res['timezone'] == 'Europe/Paris'
2557
         assert res['timezone'] == 'Europe/Paris'
2538
         assert res['is_deleted'] is False
2558
         assert res['is_deleted'] is False
2559
+        assert res['lang'] == 'fr'
2539
 
2560
 
2540
     def test_api__get_user__ok_200__user_itself(self):
2561
     def test_api__get_user__ok_200__user_itself(self):
2541
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2562
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2559
             name='bob',
2580
             name='bob',
2560
             groups=groups,
2581
             groups=groups,
2561
             timezone='Europe/Paris',
2582
             timezone='Europe/Paris',
2583
+            lang='fr',
2562
             do_save=True,
2584
             do_save=True,
2563
             do_notify=False,
2585
             do_notify=False,
2564
         )
2586
         )
2618
             name='bob2',
2640
             name='bob2',
2619
             groups=groups,
2641
             groups=groups,
2620
             timezone='Europe/Paris',
2642
             timezone='Europe/Paris',
2643
+            lang='fr',
2621
             do_save=True,
2644
             do_save=True,
2622
             do_notify=False,
2645
             do_notify=False,
2623
         )
2646
         )
2651
             'password': 'mysuperpassword',
2674
             'password': 'mysuperpassword',
2652
             'profile': 'users',
2675
             'profile': 'users',
2653
             'timezone': 'Europe/Paris',
2676
             'timezone': 'Europe/Paris',
2677
+            'lang': 'fr',
2654
             'public_name': 'test user',
2678
             'public_name': 'test user',
2655
             'email_notification': False,
2679
             'email_notification': False,
2656
         }
2680
         }
2668
         assert res['email'] == 'test@test.test'
2692
         assert res['email'] == 'test@test.test'
2669
         assert res['public_name'] == 'test user'
2693
         assert res['public_name'] == 'test user'
2670
         assert res['timezone'] == 'Europe/Paris'
2694
         assert res['timezone'] == 'Europe/Paris'
2671
-
2695
+        assert res['lang'] == 'fr'
2672
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2696
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2673
         admin = dbsession.query(models.User) \
2697
         admin = dbsession.query(models.User) \
2674
             .filter(models.User.email == 'admin@admin.admin') \
2698
             .filter(models.User.email == 'admin@admin.admin') \
2708
         assert res['email'] == 'test@test.test'
2732
         assert res['email'] == 'test@test.test'
2709
         assert res['public_name'] == 'test'
2733
         assert res['public_name'] == 'test'
2710
         assert res['timezone'] == ''
2734
         assert res['timezone'] == ''
2735
+        assert res['lang'] is None
2711
 
2736
 
2712
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2737
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2713
         admin = dbsession.query(models.User) \
2738
         admin = dbsession.query(models.User) \
2744
             name='bob',
2769
             name='bob',
2745
             groups=groups,
2770
             groups=groups,
2746
             timezone='Europe/Paris',
2771
             timezone='Europe/Paris',
2772
+            lang='fr',
2747
             do_save=True,
2773
             do_save=True,
2748
             do_notify=False,
2774
             do_notify=False,
2749
         )
2775
         )
2761
             'password': 'mysuperpassword',
2787
             'password': 'mysuperpassword',
2762
             'profile': 'users',
2788
             'profile': 'users',
2763
             'timezone': 'Europe/Paris',
2789
             'timezone': 'Europe/Paris',
2790
+            'lang': 'fr',
2764
             'public_name': 'test user',
2791
             'public_name': 'test user',
2765
             'email_notification': False,
2792
             'email_notification': False,
2766
         }
2793
         }
2792
             name='bob',
2819
             name='bob',
2793
             groups=groups,
2820
             groups=groups,
2794
             timezone='Europe/Paris',
2821
             timezone='Europe/Paris',
2822
+            lang='fr',
2795
             do_save=True,
2823
             do_save=True,
2796
             do_notify=False,
2824
             do_notify=False,
2797
         )
2825
         )
2810
             'profile': 'users',
2838
             'profile': 'users',
2811
             'timezone': 'Europe/Paris',
2839
             'timezone': 'Europe/Paris',
2812
             'public_name': 'test user',
2840
             'public_name': 'test user',
2841
+            'lang': 'fr',
2813
             'email_notification': False,
2842
             'email_notification': False,
2814
         }
2843
         }
2815
         res = self.testapp.post_json(
2844
         res = self.testapp.post_json(
2840
             'profile': 'users',
2869
             'profile': 'users',
2841
             'timezone': 'Europe/Paris',
2870
             'timezone': 'Europe/Paris',
2842
             'public_name': 'test user',
2871
             'public_name': 'test user',
2872
+            'lang': 'fr',
2843
             'email_notification': True,
2873
             'email_notification': True,
2844
         }
2874
         }
2845
         res = self.testapp.post_json(
2875
         res = self.testapp.post_json(
2856
         assert res['email'] == 'test@test.test'
2886
         assert res['email'] == 'test@test.test'
2857
         assert res['public_name'] == 'test user'
2887
         assert res['public_name'] == 'test user'
2858
         assert res['timezone'] == 'Europe/Paris'
2888
         assert res['timezone'] == 'Europe/Paris'
2889
+        assert res['lang'] == 'fr'
2859
 
2890
 
2860
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2891
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2861
         admin = dbsession.query(models.User) \
2892
         admin = dbsession.query(models.User) \
2909
         assert res['email'] == 'test@test.test'
2940
         assert res['email'] == 'test@test.test'
2910
         assert res['public_name'] == 'test'
2941
         assert res['public_name'] == 'test'
2911
         assert res['timezone'] == ''
2942
         assert res['timezone'] == ''
2943
+        assert res['lang'] == None
2912
 
2944
 
2913
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2945
         dbsession = get_tm_session(self.session_factory, transaction.manager)
2914
         admin = dbsession.query(models.User) \
2946
         admin = dbsession.query(models.User) \
2957
             name='bob',
2989
             name='bob',
2958
             groups=groups,
2990
             groups=groups,
2959
             timezone='Europe/Paris',
2991
             timezone='Europe/Paris',
2992
+            lang='fr',
2960
             do_save=True,
2993
             do_save=True,
2961
             do_notify=False,
2994
             do_notify=False,
2962
         )
2995
         )
3011
             name='bob',
3044
             name='bob',
3012
             groups=groups,
3045
             groups=groups,
3013
             timezone='Europe/Paris',
3046
             timezone='Europe/Paris',
3047
+            lang='fr',
3014
             do_save=True,
3048
             do_save=True,
3015
             do_notify=False,
3049
             do_notify=False,
3016
         )
3050
         )
3061
             name='bob',
3095
             name='bob',
3062
             groups=groups,
3096
             groups=groups,
3063
             timezone='Europe/Paris',
3097
             timezone='Europe/Paris',
3098
+            lang='fr',
3064
             do_save=True,
3099
             do_save=True,
3065
             do_notify=False,
3100
             do_notify=False,
3066
         )
3101
         )
3110
             name='bob',
3145
             name='bob',
3111
             groups=groups,
3146
             groups=groups,
3112
             timezone='Europe/Paris',
3147
             timezone='Europe/Paris',
3148
+            lang='fr',
3113
             do_save=True,
3149
             do_save=True,
3114
             do_notify=False,
3150
             do_notify=False,
3115
         )
3151
         )
3119
             name='bob2',
3155
             name='bob2',
3120
             groups=groups,
3156
             groups=groups,
3121
             timezone='Europe/Paris',
3157
             timezone='Europe/Paris',
3158
+            lang='fr',
3122
             do_save=True,
3159
             do_save=True,
3123
             do_notify=False,
3160
             do_notify=False,
3124
         )
3161
         )
3174
             name='bob',
3211
             name='bob',
3175
             groups=groups,
3212
             groups=groups,
3176
             timezone='Europe/Paris',
3213
             timezone='Europe/Paris',
3214
+            lang='fr',
3177
             do_save=True,
3215
             do_save=True,
3178
             do_notify=False,
3216
             do_notify=False,
3179
         )
3217
         )
3183
             name='bob2',
3221
             name='bob2',
3184
             groups=groups,
3222
             groups=groups,
3185
             timezone='Europe/Paris',
3223
             timezone='Europe/Paris',
3224
+            lang='fr',
3186
             do_save=True,
3225
             do_save=True,
3187
             do_notify=False,
3226
             do_notify=False,
3188
         )
3227
         )
3238
             name='bob',
3277
             name='bob',
3239
             groups=groups,
3278
             groups=groups,
3240
             timezone='Europe/Paris',
3279
             timezone='Europe/Paris',
3280
+            lang='fr',
3241
             do_save=True,
3281
             do_save=True,
3242
             do_notify=False,
3282
             do_notify=False,
3243
         )
3283
         )
3247
             name='bob2',
3287
             name='bob2',
3248
             groups=groups,
3288
             groups=groups,
3249
             timezone='Europe/Paris',
3289
             timezone='Europe/Paris',
3290
+            lang='fr',
3250
             do_save=True,
3291
             do_save=True,
3251
             do_notify=False,
3292
             do_notify=False,
3252
         )
3293
         )
3292
             name='bob',
3333
             name='bob',
3293
             groups=groups,
3334
             groups=groups,
3294
             timezone='Europe/Paris',
3335
             timezone='Europe/Paris',
3336
+            lang='fr',
3295
             do_save=True,
3337
             do_save=True,
3296
             do_notify=False,
3338
             do_notify=False,
3297
         )
3339
         )
3301
             name='bob2',
3343
             name='bob2',
3302
             groups=groups,
3344
             groups=groups,
3303
             timezone='Europe/Paris',
3345
             timezone='Europe/Paris',
3346
+            lang='fr',
3304
             do_save=True,
3347
             do_save=True,
3305
             do_notify=False,
3348
             do_notify=False,
3306
         )
3349
         )
3310
             name='bob3',
3353
             name='bob3',
3311
             groups=groups,
3354
             groups=groups,
3312
             timezone='Europe/Paris',
3355
             timezone='Europe/Paris',
3356
+            lang='fr',
3313
             do_save=True,
3357
             do_save=True,
3314
             do_notify=False,
3358
             do_notify=False,
3315
         )
3359
         )
3395
             name='bob',
3439
             name='bob',
3396
             groups=groups,
3440
             groups=groups,
3397
             timezone='Europe/Paris',
3441
             timezone='Europe/Paris',
3442
+            lang='fr',
3398
             do_save=True,
3443
             do_save=True,
3399
             do_notify=False,
3444
             do_notify=False,
3400
         )
3445
         )
3457
             name='bob',
3502
             name='bob',
3458
             groups=groups,
3503
             groups=groups,
3459
             timezone='Europe/Paris',
3504
             timezone='Europe/Paris',
3505
+            lang='fr',
3460
             do_save=True,
3506
             do_save=True,
3461
             do_notify=False,
3507
             do_notify=False,
3462
         )
3508
         )
3519
             name='bob',
3565
             name='bob',
3520
             groups=groups,
3566
             groups=groups,
3521
             timezone='Europe/Paris',
3567
             timezone='Europe/Paris',
3568
+            lang='fr',
3522
             do_save=True,
3569
             do_save=True,
3523
             do_notify=False,
3570
             do_notify=False,
3524
         )
3571
         )
3581
             name='bob',
3628
             name='bob',
3582
             groups=groups,
3629
             groups=groups,
3583
             timezone='Europe/Paris',
3630
             timezone='Europe/Paris',
3631
+            lang='fr',
3584
             do_save=True,
3632
             do_save=True,
3585
             do_notify=False,
3633
             do_notify=False,
3586
         )
3634
         )
3643
             name='bob',
3691
             name='bob',
3644
             groups=groups,
3692
             groups=groups,
3645
             timezone='Europe/Paris',
3693
             timezone='Europe/Paris',
3694
+            lang='fr',
3646
             do_save=True,
3695
             do_save=True,
3647
             do_notify=False,
3696
             do_notify=False,
3648
         )
3697
         )
3712
             name='bob',
3761
             name='bob',
3713
             groups=groups,
3762
             groups=groups,
3714
             timezone='Europe/Paris',
3763
             timezone='Europe/Paris',
3764
+            lang='fr',
3715
             do_save=True,
3765
             do_save=True,
3716
             do_notify=False,
3766
             do_notify=False,
3717
         )
3767
         )
3721
             name='bob2',
3771
             name='bob2',
3722
             groups=groups,
3772
             groups=groups,
3723
             timezone='Europe/Paris',
3773
             timezone='Europe/Paris',
3774
+            lang='fr',
3724
             do_save=True,
3775
             do_save=True,
3725
             do_notify=False,
3776
             do_notify=False,
3726
         )
3777
         )
3777
             name='bob',
3828
             name='bob',
3778
             groups=groups,
3829
             groups=groups,
3779
             timezone='Europe/Paris',
3830
             timezone='Europe/Paris',
3831
+            lang='fr',
3780
             do_save=True,
3832
             do_save=True,
3781
             do_notify=False,
3833
             do_notify=False,
3782
         )
3834
         )
3839
             name='bob',
3891
             name='bob',
3840
             groups=groups,
3892
             groups=groups,
3841
             timezone='Europe/Paris',
3893
             timezone='Europe/Paris',
3894
+            lang='fr',
3842
             do_save=True,
3895
             do_save=True,
3843
             do_notify=False,
3896
             do_notify=False,
3844
         )
3897
         )
3901
             name='bob',
3954
             name='bob',
3902
             groups=groups,
3955
             groups=groups,
3903
             timezone='Europe/Paris',
3956
             timezone='Europe/Paris',
3957
+            lang='fr',
3904
             do_save=True,
3958
             do_save=True,
3905
             do_notify=False,
3959
             do_notify=False,
3906
         )
3960
         )
3965
             name='bob',
4019
             name='bob',
3966
             groups=groups,
4020
             groups=groups,
3967
             timezone='Europe/Paris',
4021
             timezone='Europe/Paris',
4022
+            lang='fr',
3968
             do_save=True,
4023
             do_save=True,
3969
             do_notify=False,
4024
             do_notify=False,
3970
         )
4025
         )
4026
             password='pass',
4081
             password='pass',
4027
             name='bob',
4082
             name='bob',
4028
             groups=groups,
4083
             groups=groups,
4084
+            lang='fr',
4029
             timezone='Europe/Paris',
4085
             timezone='Europe/Paris',
4030
             do_save=True,
4086
             do_save=True,
4031
             do_notify=False,
4087
             do_notify=False,
4036
             name='bob2',
4092
             name='bob2',
4037
             groups=groups,
4093
             groups=groups,
4038
             timezone='Europe/Paris',
4094
             timezone='Europe/Paris',
4095
+            lang='fr',
4039
             do_save=True,
4096
             do_save=True,
4040
             do_notify=False,
4097
             do_notify=False,
4041
         )
4098
         )
4092
             name='bob',
4149
             name='bob',
4093
             groups=groups,
4150
             groups=groups,
4094
             timezone='Europe/Paris',
4151
             timezone='Europe/Paris',
4152
+            lang='fr',
4095
             do_save=True,
4153
             do_save=True,
4096
             do_notify=False,
4154
             do_notify=False,
4097
         )
4155
         )
4115
         assert res['user_id'] == user_id
4173
         assert res['user_id'] == user_id
4116
         assert res['public_name'] == 'bob'
4174
         assert res['public_name'] == 'bob'
4117
         assert res['timezone'] == 'Europe/Paris'
4175
         assert res['timezone'] == 'Europe/Paris'
4176
+        assert res['lang'] == 'fr'
4118
         # Set params
4177
         # Set params
4119
         params = {
4178
         params = {
4120
             'public_name': 'updated',
4179
             'public_name': 'updated',
4121
             'timezone': 'Europe/London',
4180
             'timezone': 'Europe/London',
4181
+            'lang': 'en',
4122
         }
4182
         }
4123
         self.testapp.put_json(
4183
         self.testapp.put_json(
4124
             '/api/v2/users/{}'.format(user_id),
4184
             '/api/v2/users/{}'.format(user_id),
4134
         assert res['user_id'] == user_id
4194
         assert res['user_id'] == user_id
4135
         assert res['public_name'] == 'updated'
4195
         assert res['public_name'] == 'updated'
4136
         assert res['timezone'] == 'Europe/London'
4196
         assert res['timezone'] == 'Europe/London'
4197
+        assert res['lang'] == 'en'
4137
 
4198
 
4138
     def test_api__set_user_info__ok_200__user_itself(self):
4199
     def test_api__set_user_info__ok_200__user_itself(self):
4139
         dbsession = get_tm_session(self.session_factory, transaction.manager)
4200
         dbsession = get_tm_session(self.session_factory, transaction.manager)
4157
             name='bob',
4218
             name='bob',
4158
             groups=groups,
4219
             groups=groups,
4159
             timezone='Europe/Paris',
4220
             timezone='Europe/Paris',
4221
+            lang='fr',
4160
             do_save=True,
4222
             do_save=True,
4161
             do_notify=False,
4223
             do_notify=False,
4162
         )
4224
         )
4180
         assert res['user_id'] == user_id
4242
         assert res['user_id'] == user_id
4181
         assert res['public_name'] == 'bob'
4243
         assert res['public_name'] == 'bob'
4182
         assert res['timezone'] == 'Europe/Paris'
4244
         assert res['timezone'] == 'Europe/Paris'
4245
+        assert res['lang'] == 'fr'
4183
         # Set params
4246
         # Set params
4184
         params = {
4247
         params = {
4185
             'public_name': 'updated',
4248
             'public_name': 'updated',
4186
             'timezone': 'Europe/London',
4249
             'timezone': 'Europe/London',
4250
+            'lang' : 'en',
4187
         }
4251
         }
4188
         self.testapp.put_json(
4252
         self.testapp.put_json(
4189
             '/api/v2/users/{}'.format(user_id),
4253
             '/api/v2/users/{}'.format(user_id),
4199
         assert res['user_id'] == user_id
4263
         assert res['user_id'] == user_id
4200
         assert res['public_name'] == 'updated'
4264
         assert res['public_name'] == 'updated'
4201
         assert res['timezone'] == 'Europe/London'
4265
         assert res['timezone'] == 'Europe/London'
4266
+        assert res['lang'] == 'en'
4202
 
4267
 
4203
     def test_api__set_user_email__err_403__other_normal_user(self):
4268
     def test_api__set_user_email__err_403__other_normal_user(self):
4204
         dbsession = get_tm_session(self.session_factory, transaction.manager)
4269
         dbsession = get_tm_session(self.session_factory, transaction.manager)
4222
             name='bob',
4287
             name='bob',
4223
             groups=groups,
4288
             groups=groups,
4224
             timezone='Europe/Paris',
4289
             timezone='Europe/Paris',
4290
+            lang='fr',
4225
             do_save=True,
4291
             do_save=True,
4226
             do_notify=False,
4292
             do_notify=False,
4227
         )
4293
         )
4231
             name='test',
4297
             name='test',
4232
             groups=groups,
4298
             groups=groups,
4233
             timezone='Europe/Paris',
4299
             timezone='Europe/Paris',
4300
+            lang='fr',
4234
             do_save=True,
4301
             do_save=True,
4235
             do_notify=False,
4302
             do_notify=False,
4236
         )
4303
         )
4250
         params = {
4317
         params = {
4251
             'public_name': 'updated',
4318
             'public_name': 'updated',
4252
             'timezone': 'Europe/London',
4319
             'timezone': 'Europe/London',
4320
+            'lang': 'en'
4253
         }
4321
         }
4254
         self.testapp.put_json(
4322
         self.testapp.put_json(
4255
             '/api/v2/users/{}'.format(user_id),
4323
             '/api/v2/users/{}'.format(user_id),
4287
             name='bob',
4355
             name='bob',
4288
             groups=groups,
4356
             groups=groups,
4289
             timezone='Europe/Paris',
4357
             timezone='Europe/Paris',
4358
+            lang='fr',
4290
             do_save=True,
4359
             do_save=True,
4291
             do_notify=False,
4360
             do_notify=False,
4292
         )
4361
         )
4349
             name='bob',
4418
             name='bob',
4350
             groups=groups,
4419
             groups=groups,
4351
             timezone='Europe/Paris',
4420
             timezone='Europe/Paris',
4421
+            lang='fr',
4352
             do_save=True,
4422
             do_save=True,
4353
             do_notify=False,
4423
             do_notify=False,
4354
         )
4424
         )
4411
             name='bob',
4481
             name='bob',
4412
             groups=groups,
4482
             groups=groups,
4413
             timezone='Europe/Paris',
4483
             timezone='Europe/Paris',
4484
+            lang='fr',
4414
             do_save=True,
4485
             do_save=True,
4415
             do_notify=False,
4486
             do_notify=False,
4416
         )
4487
         )
4420
             name='test',
4491
             name='test',
4421
             groups=groups,
4492
             groups=groups,
4422
             timezone='Europe/Paris',
4493
             timezone='Europe/Paris',
4494
+            lang='fr',
4423
             do_save=True,
4495
             do_save=True,
4424
             do_notify=False,
4496
             do_notify=False,
4425
         )
4497
         )
4476
             name='bob',
4548
             name='bob',
4477
             groups=groups,
4549
             groups=groups,
4478
             timezone='Europe/Paris',
4550
             timezone='Europe/Paris',
4551
+            lang='fr',
4479
             do_save=True,
4552
             do_save=True,
4480
             do_notify=False,
4553
             do_notify=False,
4481
         )
4554
         )
4534
             name='bob',
4607
             name='bob',
4535
             groups=groups,
4608
             groups=groups,
4536
             timezone='Europe/Paris',
4609
             timezone='Europe/Paris',
4610
+            lang='fr',
4537
             do_save=True,
4611
             do_save=True,
4538
             do_notify=False,
4612
             do_notify=False,
4539
         )
4613
         )
4592
             name='bob',
4666
             name='bob',
4593
             groups=groups,
4667
             groups=groups,
4594
             timezone='Europe/Paris',
4668
             timezone='Europe/Paris',
4669
+            lang='fr',
4595
             do_save=True,
4670
             do_save=True,
4596
             do_notify=False,
4671
             do_notify=False,
4597
         )
4672
         )
4601
             name='test2',
4676
             name='test2',
4602
             groups=groups,
4677
             groups=groups,
4603
             timezone='Europe/Paris',
4678
             timezone='Europe/Paris',
4679
+            lang='fr',
4604
             do_save=True,
4680
             do_save=True,
4605
             do_notify=False,
4681
             do_notify=False,
4606
         )
4682
         )
4644
             name='bob',
4720
             name='bob',
4645
             groups=groups,
4721
             groups=groups,
4646
             timezone='Europe/Paris',
4722
             timezone='Europe/Paris',
4723
+            lang='fr',
4647
             do_save=True,
4724
             do_save=True,
4648
             do_notify=False,
4725
             do_notify=False,
4649
         )
4726
         )
4653
             name='test2',
4730
             name='test2',
4654
             groups=groups,
4731
             groups=groups,
4655
             timezone='Europe/Paris',
4732
             timezone='Europe/Paris',
4733
+            lang='fr',
4656
             do_save=True,
4734
             do_save=True,
4657
             do_notify=False,
4735
             do_notify=False,
4658
         )
4736
         )
4696
             name='bob',
4774
             name='bob',
4697
             groups=groups,
4775
             groups=groups,
4698
             timezone='Europe/Paris',
4776
             timezone='Europe/Paris',
4777
+            lang='fr',
4699
             do_save=True,
4778
             do_save=True,
4700
             do_notify=False,
4779
             do_notify=False,
4701
         )
4780
         )

+ 2 - 0
backend/tracim_backend/tests/library/test_user_api.py 查看文件

55
             password='pass',
55
             password='pass',
56
             name='bob',
56
             name='bob',
57
             timezone='+2',
57
             timezone='+2',
58
+            lang='en',
58
             do_save=True,
59
             do_save=True,
59
             do_notify=False,
60
             do_notify=False,
60
         )
61
         )
63
         assert u.validate_password('pass')
64
         assert u.validate_password('pass')
64
         assert u.display_name == 'bob'
65
         assert u.display_name == 'bob'
65
         assert u.timezone == '+2'
66
         assert u.timezone == '+2'
67
+        assert u.lang == 'en'
66
 
68
 
67
     def test_unit__user_with_email_exists__ok__nominal_case(self):
69
     def test_unit__user_with_email_exists__ok__nominal_case(self):
68
         api = UserApi(
70
         api = UserApi(

+ 27 - 0
backend/tracim_backend/views/core_api/schemas.py 查看文件

82
     )
82
     )
83
     # TODO - G.M - 17-04-2018 - Restrict timezone values
83
     # TODO - G.M - 17-04-2018 - Restrict timezone values
84
     timezone = marshmallow.fields.String(
84
     timezone = marshmallow.fields.String(
85
+        description="Timezone as tz database format",
85
         example="Europe/Paris",
86
         example="Europe/Paris",
86
     )
87
     )
87
     # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
88
     # TODO - G.M - 17-04-2018 - check this, relative url allowed ?
97
         validate=OneOf(Profile._NAME),
98
         validate=OneOf(Profile._NAME),
98
         example='managers',
99
         example='managers',
99
     )
100
     )
101
+    lang = marshmallow.fields.String(
102
+        description="User langage in iso639 format",
103
+        example='en',
104
+        required=False,
105
+        validate=Length(min=2, max=3),
106
+        allow_none=True,
107
+        default=None,
108
+    )
100
 
109
 
101
     class Meta:
110
     class Meta:
102
         description = 'User account of Tracim'
111
         description = 'User account of Tracim'
136
 
145
 
137
 class UserInfosSchema(marshmallow.Schema):
146
 class UserInfosSchema(marshmallow.Schema):
138
     timezone = marshmallow.fields.String(
147
     timezone = marshmallow.fields.String(
148
+        description="Timezone as tz database format",
139
         example="Europe/Paris",
149
         example="Europe/Paris",
140
         required=True,
150
         required=True,
141
     )
151
     )
143
         example='Suri Cate',
153
         example='Suri Cate',
144
         required=True,
154
         required=True,
145
     )
155
     )
156
+    lang = marshmallow.fields.String(
157
+        description="User langage in iso639 format",
158
+        example='en',
159
+        required=True,
160
+        validate=Length(min=2, max=3),
161
+        allow_none=True,
162
+        default=None,
163
+    )
146
 
164
 
147
     @post_load
165
     @post_load
148
     def create_user_info_object(self, data):
166
     def create_user_info_object(self, data):
177
         default=Group.TIM_USER_GROUPNAME
195
         default=Group.TIM_USER_GROUPNAME
178
     )
196
     )
179
     timezone = marshmallow.fields.String(
197
     timezone = marshmallow.fields.String(
198
+        description="Timezone as tz database format",
180
         example="Europe/Paris",
199
         example="Europe/Paris",
181
         required=False,
200
         required=False,
182
         default=''
201
         default=''
186
         required=False,
205
         required=False,
187
         default=None,
206
         default=None,
188
     )
207
     )
208
+    lang = marshmallow.fields.String(
209
+        description="User langage in iso639 format",
210
+        example='en',
211
+        required=False,
212
+        validate=Length(min=2, max=3),
213
+        allow_none=True,
214
+        default=None,
215
+    )
189
     email_notification = marshmallow.fields.Bool(
216
     email_notification = marshmallow.fields.Bool(
190
         example=True,
217
         example=True,
191
         required=False,
218
         required=False,

+ 2 - 0
backend/tracim_backend/views/core_api/user_controller.py 查看文件

190
             request.candidate_user,
190
             request.candidate_user,
191
             name=hapic_data.body.public_name,
191
             name=hapic_data.body.public_name,
192
             timezone=hapic_data.body.timezone,
192
             timezone=hapic_data.body.timezone,
193
+            lang=hapic_data.body.lang,
193
             do_save=True
194
             do_save=True
194
         )
195
         )
195
         return uapi.get_user_with_context(user)
196
         return uapi.get_user_with_context(user)
219
             email=hapic_data.body.email,
220
             email=hapic_data.body.email,
220
             password=hapic_data.body.password,
221
             password=hapic_data.body.password,
221
             timezone=hapic_data.body.timezone,
222
             timezone=hapic_data.body.timezone,
223
+            lang=hapic_data.body.lang,
222
             name=hapic_data.body.public_name,
224
             name=hapic_data.body.public_name,
223
             do_notify=hapic_data.body.email_notification,
225
             do_notify=hapic_data.body.email_notification,
224
             groups=groups,
226
             groups=groups,