@@ -593,6 +593,86 @@ def test_models_documents_get_abilities_preset_role(django_assert_num_queries):
593
593
}
594
594
595
595
596
+ @pytest .mark .parametrize (
597
+ "is_authenticated, is_creator,role,link_reach,link_role,can_destroy" ,
598
+ [
599
+ (True , False , "owner" , "restricted" , "editor" , True ),
600
+ (True , True , "owner" , "restricted" , "editor" , True ),
601
+ (True , False , "owner" , "restricted" , "reader" , True ),
602
+ (True , True , "owner" , "restricted" , "reader" , True ),
603
+ (True , False , "owner" , "authenticated" , "editor" , True ),
604
+ (True , True , "owner" , "authenticated" , "editor" , True ),
605
+ (True , False , "owner" , "authenticated" , "reader" , True ),
606
+ (True , True , "owner" , "authenticated" , "reader" , True ),
607
+ (True , False , "owner" , "public" , "editor" , True ),
608
+ (True , True , "owner" , "public" , "editor" , True ),
609
+ (True , False , "owner" , "public" , "reader" , True ),
610
+ (True , True , "owner" , "public" , "reader" , True ),
611
+ (True , False , "administrator" , "restricted" , "editor" , True ),
612
+ (True , True , "administrator" , "restricted" , "editor" , True ),
613
+ (True , False , "administrator" , "restricted" , "reader" , True ),
614
+ (True , True , "administrator" , "restricted" , "reader" , True ),
615
+ (True , False , "administrator" , "authenticated" , "editor" , True ),
616
+ (True , True , "administrator" , "authenticated" , "editor" , True ),
617
+ (True , False , "administrator" , "authenticated" , "reader" , True ),
618
+ (True , True , "administrator" , "authenticated" , "reader" , True ),
619
+ (True , False , "administrator" , "public" , "editor" , True ),
620
+ (True , True , "administrator" , "public" , "editor" , True ),
621
+ (True , False , "administrator" , "public" , "reader" , True ),
622
+ (True , True , "administrator" , "public" , "reader" , True ),
623
+ (True , False , "editor" , "restricted" , "editor" , False ),
624
+ (True , True , "editor" , "restricted" , "editor" , True ),
625
+ (True , False , "editor" , "restricted" , "reader" , False ),
626
+ (True , True , "editor" , "restricted" , "reader" , True ),
627
+ (True , False , "editor" , "authenticated" , "editor" , False ),
628
+ (True , True , "editor" , "authenticated" , "editor" , True ),
629
+ (True , False , "editor" , "authenticated" , "reader" , False ),
630
+ (True , True , "editor" , "authenticated" , "reader" , True ),
631
+ (True , False , "editor" , "public" , "editor" , False ),
632
+ (True , True , "editor" , "public" , "editor" , True ),
633
+ (True , False , "editor" , "public" , "reader" , False ),
634
+ (True , True , "editor" , "public" , "reader" , True ),
635
+ (True , False , "reader" , "restricted" , "editor" , False ),
636
+ (True , False , "reader" , "restricted" , "reader" , False ),
637
+ (True , False , "reader" , "authenticated" , "editor" , False ),
638
+ (True , True , "reader" , "authenticated" , "editor" , True ),
639
+ (True , False , "reader" , "authenticated" , "reader" , False ),
640
+ (True , False , "reader" , "public" , "editor" , False ),
641
+ (True , True , "reader" , "public" , "editor" , True ),
642
+ (True , False , "reader" , "public" , "reader" , False ),
643
+ (False , False , None , "restricted" , "editor" , False ),
644
+ (False , False , None , "restricted" , "reader" , False ),
645
+ (False , False , None , "authenticated" , "editor" , False ),
646
+ (False , False , None , "authenticated" , "reader" , False ),
647
+ (False , False , None , "public" , "editor" , False ),
648
+ (False , False , None , "public" , "reader" , False ),
649
+ ],
650
+ )
651
+ # pylint: disable=too-many-arguments, too-many-positional-arguments
652
+ def test_models_documents_get_abilities_children_destroy ( # noqa: PLR0913
653
+ is_authenticated ,
654
+ is_creator ,
655
+ role ,
656
+ link_reach ,
657
+ link_role ,
658
+ can_destroy ,
659
+ ):
660
+ """For a sub document, if a user can create children, he can destroy it."""
661
+ user = factories .UserFactory () if is_authenticated else AnonymousUser ()
662
+ parent = factories .DocumentFactory (link_reach = link_reach , link_role = link_role )
663
+ document = factories .DocumentFactory (
664
+ link_reach = link_reach ,
665
+ link_role = link_role ,
666
+ parent = parent ,
667
+ creator = user if is_creator else None ,
668
+ )
669
+ if is_authenticated :
670
+ factories .UserDocumentAccessFactory (document = parent , user = user , role = role )
671
+
672
+ abilities = document .get_abilities (user )
673
+ assert abilities ["destroy" ] is can_destroy
674
+
675
+
596
676
@override_settings (AI_ALLOW_REACH_FROM = "public" )
597
677
@pytest .mark .parametrize (
598
678
"is_authenticated,reach" ,
0 commit comments