@@ -589,3 +589,73 @@ def test_partial_permission_grants_implied_view_asset(self):
589
589
# `someuser` should have received the implied `view_asset`
590
590
# permission
591
591
assert self .someuser .has_perm (PERM_VIEW_ASSET , self .asset )
592
+
593
+ def test_no_assignments_saved_on_error (self ):
594
+
595
+ # Call `get_anonymous_user()` to create AnonymousUser if it does not exist
596
+ get_anonymous_user ()
597
+
598
+ # Ensure someuser and anotheruser do not have 'view_submissions' on `self.asset`
599
+ self .assertFalse (self .asset .has_perm (self .someuser , PERM_VIEW_SUBMISSIONS ))
600
+ self .assertFalse (self .asset .has_perm (self .anotheruser , PERM_VIEW_SUBMISSIONS ))
601
+
602
+ # Allow someuser and anotheruser to view submissions
603
+ good_assignments = [
604
+ {
605
+ 'user' : 'someuser' ,
606
+ 'permission' : PERM_VIEW_SUBMISSIONS ,
607
+ },
608
+ {
609
+ 'user' : 'anotheruser' ,
610
+ 'permission' : PERM_VIEW_SUBMISSIONS ,
611
+ }
612
+ ]
613
+
614
+ assignments = self .translate_usernames_and_codenames_to_urls (
615
+ good_assignments
616
+ )
617
+ bulk_endpoint = reverse (
618
+ self ._get_endpoint ('asset-permission-assignment-bulk-assignments' ),
619
+ kwargs = {'parent_lookup_asset' : self .asset .uid }
620
+ )
621
+ response = self .client .post (bulk_endpoint , assignments , format = 'json' )
622
+
623
+ # Everything worked as expected, someuser and anotheruser got 'view_submissions'
624
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
625
+ self .assertTrue (self .asset .has_perm (self .someuser , PERM_VIEW_SUBMISSIONS ))
626
+ self .assertTrue (self .asset .has_perm (self .anotheruser , PERM_VIEW_SUBMISSIONS ))
627
+
628
+ # but do not have respectively 'delete_submissions' and 'change_submissions'
629
+ self .assertFalse (self .asset .has_perm (self .someuser , PERM_DELETE_SUBMISSIONS ))
630
+ self .assertFalse (self .asset .has_perm (self .anotheruser , PERM_CHANGE_SUBMISSIONS ))
631
+
632
+ bad_assignments = [
633
+ {
634
+ 'user' : 'AnonymousUser' ,
635
+ 'permission' : PERM_ADD_SUBMISSIONS , # should return a 400
636
+ },
637
+ {
638
+ 'user' : 'someuser' ,
639
+ 'permission' : PERM_DELETE_SUBMISSIONS ,
640
+ },
641
+ {
642
+ 'user' : 'anotheruser' ,
643
+ 'permission' : PERM_CHANGE_SUBMISSIONS ,
644
+ }
645
+ ]
646
+ assignments = self .translate_usernames_and_codenames_to_urls (
647
+ bad_assignments
648
+ )
649
+
650
+ bulk_endpoint = reverse (
651
+ self ._get_endpoint ('asset-permission-assignment-bulk-assignments' ),
652
+ kwargs = {'parent_lookup_asset' : self .asset .uid }
653
+ )
654
+ response = self .client .post (bulk_endpoint , assignments , format = 'json' )
655
+ # Could not assign 'add_submissions' to anonymous user.
656
+ self .assertEqual (response .status_code , status .HTTP_400_BAD_REQUEST )
657
+
658
+ # Ensure that someuser and anotheruser did not get any other permissions
659
+ # than the one they already had, i.e.: 'view_submissions'.
660
+ self .assertFalse (self .asset .has_perm (self .someuser , PERM_DELETE_SUBMISSIONS ))
661
+ self .assertFalse (self .asset .has_perm (self .anotheruser , PERM_CHANGE_SUBMISSIONS ))
0 commit comments