Bladeren bron

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

Guénaël Muller 6 jaren geleden
bovenliggende
commit
e12133f148
4 gewijzigde bestanden met toevoegingen van 125 en 28 verwijderingen
  1. 28 5
      tracim/fixtures/content.py
  2. 7 8
      tracim/models/context_models.py
  3. 7 1
      tracim/models/data.py
  4. 83 14
      tracim/tests/functional/test_contents.py

+ 28 - 5
tracim/fixtures/content.py Bestand weergeven

117
             content_type=ContentType.Page,
117
             content_type=ContentType.Page,
118
             workspace=recipe_workspace,
118
             workspace=recipe_workspace,
119
             parent=dessert_folder,
119
             parent=dessert_folder,
120
-            label='Tiramisu Recipe',
120
+            label='Tiramisu Recipes !!!',
121
             do_save=True,
121
             do_save=True,
122
             do_notify=False,
122
             do_notify=False,
123
         )
123
         )
128
         ):
128
         ):
129
             content_api.update_content(
129
             content_api.update_content(
130
                 item=tiramisu_page,
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
             content_api.save(tiramisu_page)
134
             content_api.save(tiramisu_page)
135
 
135
 
137
             content_type=ContentType.Thread,
137
             content_type=ContentType.Thread,
138
             workspace=recipe_workspace,
138
             workspace=recipe_workspace,
139
             parent=dessert_folder,
139
             parent=dessert_folder,
140
-            label='Best Cakes ?',
140
+            label='Best Cake',
141
             do_save=False,
141
             do_save=False,
142
             do_notify=False,
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
         self._session.add(best_cake_thread)
145
         self._session.add(best_cake_thread)
146
         apple_pie_recipe = content_api.create(
146
         apple_pie_recipe = content_api.create(
147
             content_type=ContentType.File,
147
             content_type=ContentType.File,
278
             content='<p>You are right, but Kouign-amann are clearly better.</p>',
278
             content='<p>You are right, but Kouign-amann are clearly better.</p>',
279
             do_save=True,
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
         self._session.flush()
304
         self._session.flush()

+ 7 - 8
tracim/models/context_models.py Bestand weergeven

392
         return UserInContext(
392
         return UserInContext(
393
             dbsession=self.dbsession,
393
             dbsession=self.dbsession,
394
             config=self.config,
394
             config=self.config,
395
-            user=self.content.owner
395
+            user=self.content.first_revision.owner
396
         )
396
         )
397
 
397
 
398
     @property
398
     @property
413
 
413
 
414
     @property
414
     @property
415
     def last_modifier(self):
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
     # Context-related
422
     # Context-related
419
     @property
423
     @property
420
     def show_in_ui(self):
424
     def show_in_ui(self):
514
         return self.revision.updated
518
         return self.revision.updated
515
 
519
 
516
     @property
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
     def comments_ids(self):
521
     def comments_ids(self):
523
         # TODO - G.M - 2018-06-173 - Return comments related to this revision
522
         # TODO - G.M - 2018-06-173 - Return comments related to this revision
524
         return []
523
         return []

+ 7 - 1
tracim/models/data.py Bestand weergeven

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

+ 83 - 14
tracim/tests/functional/test_contents.py Bestand weergeven

54
         assert content['slug'] == 'tiramisu-recipe'
54
         assert content['slug'] == 'tiramisu-recipe'
55
         assert content['status'] == 'open'
55
         assert content['status'] == 'open'
56
         assert content['workspace_id'] == 2
56
         assert content['workspace_id'] == 2
57
-        assert content['current_revision_id'] == 7
57
+        assert content['current_revision_id'] == 27
58
         # TODO - G.M - 2018-06-173 - check date format
58
         # TODO - G.M - 2018-06-173 - check date format
59
         assert content['created']
59
         assert content['created']
60
         assert content['author']
60
         assert content['author']
63
         assert content['author']['public_name'] == 'Global manager'
63
         assert content['author']['public_name'] == 'Global manager'
64
         # TODO - G.M - 2018-06-173 - check date format
64
         # TODO - G.M - 2018-06-173 - check date format
65
         assert content['modified']
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
         assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>'  # nopep8
70
         assert content['raw_content'] == '<p>To cook a great Tiramisu, you need many ingredients.</p>'  # nopep8
68
 
71
 
69
     def test_api__update_html_document__ok_200__nominal_case(self) -> None:
72
     def test_api__update_html_document__ok_200__nominal_case(self) -> None:
97
         assert content['slug'] == 'my-new-label'
100
         assert content['slug'] == 'my-new-label'
98
         assert content['status'] == 'open'
101
         assert content['status'] == 'open'
99
         assert content['workspace_id'] == 2
102
         assert content['workspace_id'] == 2
100
-        assert content['current_revision_id'] == 26
103
+        assert content['current_revision_id'] == 28
101
         # TODO - G.M - 2018-06-173 - check date format
104
         # TODO - G.M - 2018-06-173 - check date format
102
         assert content['created']
105
         assert content['created']
103
         assert content['author']
106
         assert content['author']
124
         assert content['slug'] == 'my-new-label'
127
         assert content['slug'] == 'my-new-label'
125
         assert content['status'] == 'open'
128
         assert content['status'] == 'open'
126
         assert content['workspace_id'] == 2
129
         assert content['workspace_id'] == 2
127
-        assert content['current_revision_id'] == 26
130
+        assert content['current_revision_id'] == 28
128
         # TODO - G.M - 2018-06-173 - check date format
131
         # TODO - G.M - 2018-06-173 - check date format
129
         assert content['created']
132
         assert content['created']
130
         assert content['author']
133
         assert content['author']
154
             status=200
157
             status=200
155
         )
158
         )
156
         revisions = res.json_body
159
         revisions = res.json_body
157
-        assert len(revisions) == 2
160
+        assert len(revisions) == 3
158
         revision = revisions[0]
161
         revision = revisions[0]
159
         assert revision['content_type'] == 'page'
162
         assert revision['content_type'] == 'page'
160
         assert revision['content_id'] == 6
163
         assert revision['content_id'] == 6
161
         assert revision['is_archived'] is False
164
         assert revision['is_archived'] is False
162
         assert revision['is_deleted'] is False
165
         assert revision['is_deleted'] is False
163
-        assert revision['label'] == 'Tiramisu Recipe'
166
+        assert revision['label'] == 'Tiramisu Recipes !!!'
164
         assert revision['parent_id'] == 3
167
         assert revision['parent_id'] == 3
165
         assert revision['show_in_ui'] is True
168
         assert revision['show_in_ui'] is True
166
-        assert revision['slug'] == 'tiramisu-recipe'
169
+        assert revision['slug'] == 'tiramisu-recipes'
167
         assert revision['status'] == 'open'
170
         assert revision['status'] == 'open'
168
         assert revision['workspace_id'] == 2
171
         assert revision['workspace_id'] == 2
169
         assert revision['revision_id'] == 6
172
         assert revision['revision_id'] == 6
176
         assert revision['author']['user_id'] == 1
179
         assert revision['author']['user_id'] == 1
177
         assert revision['author']['avatar_url'] is None
180
         assert revision['author']['avatar_url'] is None
178
         assert revision['author']['public_name'] == 'Global manager'
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
     def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
225
     def test_api__set_html_document_status__ok_200__nominal_case(self) -> None:
181
         """
226
         """
270
         assert content['slug'] == 'best-cakes'
315
         assert content['slug'] == 'best-cakes'
271
         assert content['status'] == 'open'
316
         assert content['status'] == 'open'
272
         assert content['workspace_id'] == 2
317
         assert content['workspace_id'] == 2
273
-        assert content['current_revision_id'] == 8
318
+        assert content['current_revision_id'] == 26
274
         # TODO - G.M - 2018-06-173 - check date format
319
         # TODO - G.M - 2018-06-173 - check date format
275
         assert content['created']
320
         assert content['created']
276
         assert content['author']
321
         assert content['author']
279
         assert content['author']['public_name'] == 'Global manager'
324
         assert content['author']['public_name'] == 'Global manager'
280
         # TODO - G.M - 2018-06-173 - check date format
325
         # TODO - G.M - 2018-06-173 - check date format
281
         assert content['modified']
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
         assert content['raw_content'] == 'What is the best cake ?'  # nopep8
331
         assert content['raw_content'] == 'What is the best cake ?'  # nopep8
284
 
332
 
285
     def test_api__update_thread__ok_200__nominal_case(self) -> None:
333
     def test_api__update_thread__ok_200__nominal_case(self) -> None:
313
         assert content['slug'] == 'my-new-label'
361
         assert content['slug'] == 'my-new-label'
314
         assert content['status'] == 'open'
362
         assert content['status'] == 'open'
315
         assert content['workspace_id'] == 2
363
         assert content['workspace_id'] == 2
316
-        assert content['current_revision_id'] == 26
364
+        assert content['current_revision_id'] == 28
317
         # TODO - G.M - 2018-06-173 - check date format
365
         # TODO - G.M - 2018-06-173 - check date format
318
         assert content['created']
366
         assert content['created']
319
         assert content['author']
367
         assert content['author']
340
         assert content['slug'] == 'my-new-label'
388
         assert content['slug'] == 'my-new-label'
341
         assert content['status'] == 'open'
389
         assert content['status'] == 'open'
342
         assert content['workspace_id'] == 2
390
         assert content['workspace_id'] == 2
343
-        assert content['current_revision_id'] == 26
391
+        assert content['current_revision_id'] == 28
344
         # TODO - G.M - 2018-06-173 - check date format
392
         # TODO - G.M - 2018-06-173 - check date format
345
         assert content['created']
393
         assert content['created']
346
         assert content['author']
394
         assert content['author']
370
             status=200
418
             status=200
371
         )
419
         )
372
         revisions = res.json_body
420
         revisions = res.json_body
373
-        assert len(revisions) == 1
421
+        assert len(revisions) == 2
374
         revision = revisions[0]
422
         revision = revisions[0]
375
         assert revision['content_type'] == 'thread'
423
         assert revision['content_type'] == 'thread'
376
         assert revision['content_id'] == 7
424
         assert revision['content_id'] == 7
377
         assert revision['is_archived'] is False
425
         assert revision['is_archived'] is False
378
         assert revision['is_deleted'] is False
426
         assert revision['is_deleted'] is False
379
-        assert revision['label'] == 'Best Cakes ?'
427
+        assert revision['label'] == 'Best Cake'
380
         assert revision['parent_id'] == 3
428
         assert revision['parent_id'] == 3
381
         assert revision['show_in_ui'] is True
429
         assert revision['show_in_ui'] is True
382
-        assert revision['slug'] == 'best-cakes'
430
+        assert revision['slug'] == 'best-cake'
383
         assert revision['status'] == 'open'
431
         assert revision['status'] == 'open'
384
         assert revision['workspace_id'] == 2
432
         assert revision['workspace_id'] == 2
385
         assert revision['revision_id'] == 8
433
         assert revision['revision_id'] == 8
392
         assert revision['author']['user_id'] == 1
440
         assert revision['author']['user_id'] == 1
393
         assert revision['author']['avatar_url'] is None
441
         assert revision['author']['avatar_url'] is None
394
         assert revision['author']['public_name'] == 'Global manager'
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
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
465
     def test_api__set_thread_status__ok_200__nominal_case(self) -> None:
397
         """
466
         """