@@ -930,6 +930,45 @@ def test_statistics_no_inbox_tag(self):
930
930
self .assertEqual (response .data ["documents_inbox" ], None )
931
931
self .assertEqual (response .data ["inbox_tag" ], None )
932
932
933
+ def test_statistics_multiple_users (self ):
934
+ """
935
+ GIVEN:
936
+ - Inbox tags with different owners and documents that are accessible to different users
937
+ WHEN:
938
+ - Statistics are requested
939
+ THEN:
940
+ - Statistics only include inbox counts for tags accessible by the user
941
+ """
942
+ u1 = User .objects .create_user ("user1" )
943
+ u2 = User .objects .create_user ("user2" )
944
+ inbox_tag_u1 = Tag .objects .create (name = "inbox_u1" , is_inbox_tag = True , owner = u1 )
945
+ Tag .objects .create (name = "inbox_u2" , is_inbox_tag = True , owner = u2 )
946
+ doc_u1 = Document .objects .create (
947
+ title = "none1" ,
948
+ checksum = "A" ,
949
+ mime_type = "application/pdf" ,
950
+ owner = u1 ,
951
+ )
952
+ doc2_u1 = Document .objects .create (
953
+ title = "none2" ,
954
+ checksum = "B" ,
955
+ mime_type = "application/pdf" ,
956
+ )
957
+ doc_u1 .tags .add (inbox_tag_u1 )
958
+ doc2_u1 .save ()
959
+ doc2_u1 .tags .add (inbox_tag_u1 )
960
+ doc2_u1 .save ()
961
+
962
+ self .client .force_authenticate (user = u1 )
963
+ response = self .client .get ("/api/statistics/" )
964
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
965
+ self .assertEqual (response .data ["documents_inbox" ], 2 )
966
+
967
+ self .client .force_authenticate (user = u2 )
968
+ response = self .client .get ("/api/statistics/" )
969
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
970
+ self .assertEqual (response .data ["documents_inbox" ], 0 )
971
+
933
972
def test_upload (self ):
934
973
self .consume_file_mock .return_value = celery .result .AsyncResult (
935
974
id = str (uuid .uuid4 ()),
0 commit comments