@@ -145,3 +145,54 @@ def test_share_history_login_redirect(self):
145145 self .fill_login_and_submit (user_email )
146146 self .wait_for_logged_in ()
147147 self .wait_for_selector (".make-accessible" )
148+
149+
150+ class TestPrivateHistorySharingRequiresPermissionChanges (SeleniumTestCase ):
151+ """Test that sharing private histories requires permission changes.
152+
153+ Includes regression test for PR #20886: When sharing a history containing private datasets
154+ with another user, the default option should be "Make datasets private to
155+ me and users this history is shared with" rather than "Make datasets public".
156+ """
157+
158+ @selenium_test
159+ def test_sharing_private_history_default_permission (self ):
160+ # Create two test users - one to own the history, one to share with
161+ user1_email = self ._get_random_email ()
162+ user2_email = self ._get_random_email ()
163+
164+ # Register first user and create a private history with data
165+ self .register (user1_email )
166+ self .make_history_private ()
167+ self .perform_upload_of_pasted_content ("hello world" )
168+ self .wait_for_history ()
169+
170+ # Register second user (must exist to share with)
171+ self .logout_if_needed ()
172+ self .register (user2_email )
173+ self .logout_if_needed ()
174+
175+ # Login as first user and initiate sharing
176+ self .submit_login (user1_email )
177+ self .home ()
178+ self .click_history_option_sharing ()
179+
180+ # Share with the second user - this triggers the permission dialog
181+ sharing = self .components .histories .sharing
182+ self .share_with_user (sharing , user_email = user2_email )
183+
184+ # Verify the permission change required dialog appears
185+ self .screenshot ("history_private_sharing_permissions_dialog" )
186+ self .components .histories .sharing .permissions_change_required .wait_for_visible ()
187+
188+ # Verify the default selected option is 'make_accessible_to_shared'
189+ element = self .components .histories .sharing .permissions_change_required_how .wait_for_visible ()
190+ default_value = element .get_attribute ("value" )
191+ assert default_value == "make_accessible_to_shared" , (
192+ f"Expected default permission option to be 'make_accessible_to_shared' "
193+ f"(private to shared users), but got '{ default_value } '"
194+ )
195+
196+ # Confirm the permission change to complete sharing
197+ self .components .histories .sharing .permissions_change_required_ok .wait_for_and_click ()
198+ self .screenshot ("history_private_sharing_permissions_confirmed" )
0 commit comments