Browse Source

[#606] fix last_modifier and author should not be the same.

Guénaël Muller 6 years ago
parent
commit
e12133f148

+ 28 - 5
tracim/fixtures/content.py View File

@@ -117,7 +117,7 @@ class Content(Fixture):
117 117
             content_type=ContentType.Page,
118 118
             workspace=recipe_workspace,
119 119
             parent=dessert_folder,
120
-            label='Tiramisu Recipe',
120
+            label='Tiramisu Recipes !!!',
121 121
             do_save=True,
122 122
             do_notify=False,
123 123
         )
@@ -128,8 +128,8 @@ class Content(Fixture):
128 128
         ):
129 129
             content_api.update_content(
130 130
                 item=tiramisu_page,
131
-                new_content='<p>To cook a great Tiramisu, you need many ingredients.</p>',  # nopep8
132
-                new_label='Tiramisu Recipe',
131
+                new_content='<p>To cook a greet Tiramisu, you need many ingredients.</p>',  # nopep8
132
+                new_label='Tiramisu Recipes !!!',
133 133
             )
134 134
             content_api.save(tiramisu_page)
135 135
 
@@ -137,11 +137,11 @@ class Content(Fixture):
137 137
             content_type=ContentType.Thread,
138 138
             workspace=recipe_workspace,
139 139
             parent=dessert_folder,
140
-            label='Best Cakes ?',
140
+            label='Best Cake',
141 141
             do_save=False,
142 142
             do_notify=False,
143 143
         )
144
-        best_cake_thread.description = 'What is the best cake ?'
144
+        best_cake_thread.description = 'Which is the best cake ?'
145 145
         self._session.add(best_cake_thread)
146 146
         apple_pie_recipe = content_api.create(
147 147
             content_type=ContentType.File,
@@ -278,4 +278,27 @@ class Content(Fixture):
278 278
             content='<p>You are right, but Kouign-amann are clearly better.</p>',
279 279
             do_save=True,
280 280
         )
281
+        with new_revision(
282
+                session=self._session,
283
+                tm=transaction.manager,
284
+                content=best_cake_thread,
285
+        ):
286
+            bob_content_api.update_content(
287
+                item=best_cake_thread,
288
+                new_content='What is the best cake ?',
289
+                new_label='Best Cakes ?',
290
+            )
291
+            bob_content_api.save(best_cake_thread)
292
+
293
+        with new_revision(
294
+                session=self._session,
295
+                tm=transaction.manager,
296
+                content=tiramisu_page,
297
+        ):
298
+            bob_content_api.update_content(
299
+                item=tiramisu_page,
300
+                new_content='<p>To cook a great Tiramisu, you need many ingredients.</p>',  # nopep8
301
+                new_label='Tiramisu Recipe',
302
+            )
303
+            bob_content_api.save(tiramisu_page)
281 304
         self._session.flush()

+ 7 - 8
tracim/models/context_models.py View File

@@ -392,7 +392,7 @@ class ContentInContext(object):
392 392
         return UserInContext(
393 393
             dbsession=self.dbsession,
394 394
             config=self.config,
395
-            user=self.content.owner
395
+            user=self.content.first_revision.owner
396 396
         )
397 397
 
398 398
     @property
@@ -413,8 +413,12 @@ class ContentInContext(object):
413 413
 
414 414
     @property
415 415
     def last_modifier(self):
416
-        # TODO - G.M - 2018-06-173 - Repair owner/last modifier
417
-        return self.author
416
+        return UserInContext(
417
+            dbsession=self.dbsession,
418
+            config=self.config,
419
+            user=self.content.last_revision.owner
420
+        )
421
+
418 422
     # Context-related
419 423
     @property
420 424
     def show_in_ui(self):
@@ -514,11 +518,6 @@ class RevisionInContext(object):
514 518
         return self.revision.updated
515 519
 
516 520
     @property
517
-    def last_modifier(self):
518
-        # TODO - G.M - 2018-06-173 - Repair owner/last modifier
519
-        return self.author
520
-    
521
-    @property
522 521
     def comments_ids(self):
523 522
         # TODO - G.M - 2018-06-173 - Return comments related to this revision
524 523
         return []

+ 7 - 1
tracim/models/data.py View File

@@ -598,6 +598,7 @@ class ContentRevisionRO(DeclarativeBase):
598 598
 
599 599
     revision_id = Column(Integer, primary_key=True)
600 600
     content_id = Column(Integer, ForeignKey('content.id'), nullable=False)
601
+    # TODO - G.M - 2018-06-177 - [author] Owner should be renamed "author"
601 602
     owner_id = Column(Integer, ForeignKey('users.user_id'), nullable=True)
602 603
 
603 604
     label = Column(Unicode(1024), unique=False, nullable=False)
@@ -631,6 +632,7 @@ class ContentRevisionRO(DeclarativeBase):
631 632
     parent = relationship("Content", foreign_keys=[parent_id], back_populates="children_revisions")
632 633
 
633 634
     node = relationship("Content", foreign_keys=[content_id], back_populates="revisions")
635
+    # TODO - G.M - 2018-06-177 - [author] Owner should be renamed "author"
634 636
     owner = relationship('User', remote_side=[User.user_id])
635 637
 
636 638
     """ List of column copied when make a new revision from another """
@@ -788,7 +790,7 @@ class ContentRevisionRO(DeclarativeBase):
788 790
             file_extension,
789 791
         )
790 792
 
791
-
793
+# TODO - G.M - 2018-06-177 - [author] Owner should be renamed "author"
792 794
 Index('idx__content_revisions__owner_id', ContentRevisionRO.owner_id)
793 795
 Index('idx__content_revisions__parent_id', ContentRevisionRO.parent_id)
794 796
 
@@ -867,6 +869,8 @@ class Content(DeclarativeBase):
867 869
     def revision_id(cls) -> InstrumentedAttribute:
868 870
         return ContentRevisionRO.revision_id
869 871
 
872
+    # TODO - G.M - 2018-06-177 - [author] Owner should be renamed "author"
873
+    # and should be author of first revision.
870 874
     @hybrid_property
871 875
     def owner_id(self) -> int:
872 876
         return self.revision.owner_id
@@ -1113,6 +1117,8 @@ class Content(DeclarativeBase):
1113 1117
     def node(cls) -> InstrumentedAttribute:
1114 1118
         return ContentRevisionRO.node
1115 1119
 
1120
+    # TODO - G.M - 2018-06-177 - [author] Owner should be renamed "author"
1121
+    # and should be author of first revision.
1116 1122
     @hybrid_property
1117 1123
     def owner(self) -> User:
1118 1124
         return self.revision.owner

+ 83 - 14
tracim/tests/functional/test_contents.py View File

@@ -54,7 +54,7 @@ class TestHtmlDocuments(FunctionalTest):
54 54
         assert content['slug'] == 'tiramisu-recipe'
55 55
         assert content['status'] == 'open'
56 56
         assert content['workspace_id'] == 2
57
-        assert content['current_revision_id'] == 7
57
+        assert content['current_revision_id'] == 27
58 58
         # TODO - G.M - 2018-06-173 - check date format
59 59
         assert content['created']
60 60
         assert content['author']
@@ -63,7 +63,10 @@ class TestHtmlDocuments(FunctionalTest):
63 63
         assert content['author']['public_name'] == 'Global manager'
64 64
         # TODO - G.M - 2018-06-173 - check date format
65 65
         assert content['modified']
66
-        assert content['last_modifier'] == content['author']
66
+        assert content['last_modifier'] != content['author']
67
+        assert content['last_modifier']['user_id'] == 3
68
+        assert content['last_modifier']['public_name'] == 'Bob i.'
69
+        assert content['last_modifier']['avatar_url'] is None
67 70
         assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>'  # nopep8
68 71
 
69 72
     def test_api__update_html_document__ok_200__nominal_case(self) -> None:
@@ -97,7 +100,7 @@ class TestHtmlDocuments(FunctionalTest):
97 100
         assert content['slug'] == 'my-new-label'
98 101
         assert content['status'] == 'open'
99 102
         assert content['workspace_id'] == 2
100
-        assert content['current_revision_id'] == 26
103
+        assert content['current_revision_id'] == 28
101 104
         # TODO - G.M - 2018-06-173 - check date format
102 105
         assert content['created']
103 106
         assert content['author']
@@ -124,7 +127,7 @@ class TestHtmlDocuments(FunctionalTest):
124 127
         assert content['slug'] == 'my-new-label'
125 128
         assert content['status'] == 'open'
126 129
         assert content['workspace_id'] == 2
127
-        assert content['current_revision_id'] == 26
130
+        assert content['current_revision_id'] == 28
128 131
         # TODO - G.M - 2018-06-173 - check date format
129 132
         assert content['created']
130 133
         assert content['author']
@@ -154,16 +157,16 @@ class TestHtmlDocuments(FunctionalTest):
154 157
             status=200
155 158
         )
156 159
         revisions = res.json_body
157
-        assert len(revisions) == 2
160
+        assert len(revisions) == 3
158 161
         revision = revisions[0]
159 162
         assert revision['content_type'] == 'page'
160 163
         assert revision['content_id'] == 6
161 164
         assert revision['is_archived'] is False
162 165
         assert revision['is_deleted'] is False
163
-        assert revision['label'] == 'Tiramisu Recipe'
166
+        assert revision['label'] == 'Tiramisu Recipes !!!'
164 167
         assert revision['parent_id'] == 3
165 168
         assert revision['show_in_ui'] is True
166
-        assert revision['slug'] == 'tiramisu-recipe'
169
+        assert revision['slug'] == 'tiramisu-recipes'
167 170
         assert revision['status'] == 'open'
168 171
         assert revision['workspace_id'] == 2
169 172
         assert revision['revision_id'] == 6
@@ -176,6 +179,48 @@ class TestHtmlDocuments(FunctionalTest):
176 179
         assert revision['author']['user_id'] == 1
177 180
         assert revision['author']['avatar_url'] is None
178 181
         assert revision['author']['public_name'] == 'Global manager'
182
+        revision = revisions[1]
183
+        assert revision['content_type'] == 'page'
184
+        assert revision['content_id'] == 6
185
+        assert revision['is_archived'] is False
186
+        assert revision['is_deleted'] is False
187
+        assert revision['label'] == 'Tiramisu Recipes !!!'
188
+        assert revision['parent_id'] == 3
189
+        assert revision['show_in_ui'] is True
190
+        assert revision['slug'] == 'tiramisu-recipes'
191
+        assert revision['status'] == 'open'
192
+        assert revision['workspace_id'] == 2
193
+        assert revision['revision_id'] == 7
194
+        assert revision['sub_content_types']
195
+        # TODO - G.M - 2018-06-173 - Test with real comments
196
+        assert revision['comments_ids'] == []
197
+        # TODO - G.M - 2018-06-173 - check date format
198
+        assert revision['created']
199
+        assert revision['author']
200
+        assert revision['author']['user_id'] == 1
201
+        assert revision['author']['avatar_url'] is None
202
+        assert revision['author']['public_name'] == 'Global manager'
203
+        revision = revisions[2]
204
+        assert revision['content_type'] == 'page'
205
+        assert revision['content_id'] == 6
206
+        assert revision['is_archived'] is False
207
+        assert revision['is_deleted'] is False
208
+        assert revision['label'] == 'Tiramisu Recipe'
209
+        assert revision['parent_id'] == 3
210
+        assert revision['show_in_ui'] is True
211
+        assert revision['slug'] == 'tiramisu-recipe'
212
+        assert revision['status'] == 'open'
213
+        assert revision['workspace_id'] == 2
214
+        assert revision['revision_id'] == 27
215
+        assert revision['sub_content_types']
216
+        # TODO - G.M - 2018-06-173 - Test with real comments
217
+        assert revision['comments_ids'] == []
218
+        # TODO - G.M - 2018-06-173 - check date format
219
+        assert revision['created']
220
+        assert revision['author']
221
+        assert revision['author']['user_id'] == 3
222
+        assert revision['author']['avatar_url'] is None
223
+        assert revision['author']['public_name'] == 'Bob i.'
179 224
 
180 225
     def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
181 226
         """
@@ -270,7 +315,7 @@ class TestThreads(FunctionalTest):
270 315
         assert content['slug'] == 'best-cakes'
271 316
         assert content['status'] == 'open'
272 317
         assert content['workspace_id'] == 2
273
-        assert content['current_revision_id'] == 8
318
+        assert content['current_revision_id'] == 26
274 319
         # TODO - G.M - 2018-06-173 - check date format
275 320
         assert content['created']
276 321
         assert content['author']
@@ -279,7 +324,10 @@ class TestThreads(FunctionalTest):
279 324
         assert content['author']['public_name'] == 'Global manager'
280 325
         # TODO - G.M - 2018-06-173 - check date format
281 326
         assert content['modified']
282
-        assert content['last_modifier'] == content['author']
327
+        assert content['last_modifier'] != content['author']
328
+        assert content['last_modifier']['user_id'] == 3
329
+        assert content['last_modifier']['public_name'] == 'Bob i.'
330
+        assert content['last_modifier']['avatar_url'] is None
283 331
         assert content['raw_content'] == 'What is the best cake ?'  # nopep8
284 332
 
285 333
     def test_api__update_thread__ok_200__nominal_case(self) -> None:
@@ -313,7 +361,7 @@ class TestThreads(FunctionalTest):
313 361
         assert content['slug'] == 'my-new-label'
314 362
         assert content['status'] == 'open'
315 363
         assert content['workspace_id'] == 2
316
-        assert content['current_revision_id'] == 26
364
+        assert content['current_revision_id'] == 28
317 365
         # TODO - G.M - 2018-06-173 - check date format
318 366
         assert content['created']
319 367
         assert content['author']
@@ -340,7 +388,7 @@ class TestThreads(FunctionalTest):
340 388
         assert content['slug'] == 'my-new-label'
341 389
         assert content['status'] == 'open'
342 390
         assert content['workspace_id'] == 2
343
-        assert content['current_revision_id'] == 26
391
+        assert content['current_revision_id'] == 28
344 392
         # TODO - G.M - 2018-06-173 - check date format
345 393
         assert content['created']
346 394
         assert content['author']
@@ -370,16 +418,16 @@ class TestThreads(FunctionalTest):
370 418
             status=200
371 419
         )
372 420
         revisions = res.json_body
373
-        assert len(revisions) == 1
421
+        assert len(revisions) == 2
374 422
         revision = revisions[0]
375 423
         assert revision['content_type'] == 'thread'
376 424
         assert revision['content_id'] == 7
377 425
         assert revision['is_archived'] is False
378 426
         assert revision['is_deleted'] is False
379
-        assert revision['label'] == 'Best Cakes ?'
427
+        assert revision['label'] == 'Best Cake'
380 428
         assert revision['parent_id'] == 3
381 429
         assert revision['show_in_ui'] is True
382
-        assert revision['slug'] == 'best-cakes'
430
+        assert revision['slug'] == 'best-cake'
383 431
         assert revision['status'] == 'open'
384 432
         assert revision['workspace_id'] == 2
385 433
         assert revision['revision_id'] == 8
@@ -392,6 +440,27 @@ class TestThreads(FunctionalTest):
392 440
         assert revision['author']['user_id'] == 1
393 441
         assert revision['author']['avatar_url'] is None
394 442
         assert revision['author']['public_name'] == 'Global manager'
443
+        revision = revisions[1]
444
+        assert revision['content_type'] == 'thread'
445
+        assert revision['content_id'] == 7
446
+        assert revision['is_archived'] is False
447
+        assert revision['is_deleted'] is False
448
+        assert revision['label'] == 'Best Cakes ?'
449
+        assert revision['parent_id'] == 3
450
+        assert revision['show_in_ui'] is True
451
+        assert revision['slug'] == 'best-cakes'
452
+        assert revision['status'] == 'open'
453
+        assert revision['workspace_id'] == 2
454
+        assert revision['revision_id'] == 26
455
+        assert revision['sub_content_types']
456
+        # TODO - G.M - 2018-06-173 - Test with real comments
457
+        assert revision['comments_ids'] == []
458
+        # TODO - G.M - 2018-06-173 - check date format
459
+        assert revision['created']
460
+        assert revision['author']
461
+        assert revision['author']['user_id'] == 3
462
+        assert revision['author']['avatar_url'] is None
463
+        assert revision['author']['public_name'] == 'Bob i.'
395 464
 
396 465
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
397 466
         """