diff --git a/bots/models.py b/bots/models.py index 10ba13032..31ee78cf5 100644 --- a/bots/models.py +++ b/bots/models.py @@ -49,6 +49,13 @@ def choices_for_workspace( # TODO: Add cls.PUBLIC when team-handles are added return [cls.UNLISTED, cls.INTERNAL] + @classmethod + def get_default_for_workspace(cls, workspace: typing.Optional["Workspace"]): + if not workspace or workspace.is_personal: + return cls.UNLISTED + else: + return cls.INTERNAL + def help_text(self, workspace: typing.Optional["Workspace"] = None): from routers.account import profile_route, saved_route @@ -1678,7 +1685,7 @@ def get_or_create_with_version( workspace: typing.Optional["Workspace"], title: str, notes: str, - visibility: PublishedRunVisibility, + visibility: PublishedRunVisibility | None = None, ): return get_or_create_lazy( PublishedRun, @@ -1705,13 +1712,16 @@ def create_with_version( workspace: typing.Optional["Workspace"], title: str, notes: str, - visibility: PublishedRunVisibility, + visibility: PublishedRunVisibility | None = None, ): workspace_id = ( workspace and workspace.id or PublishedRun._meta.get_field("workspace").get_default() ) + if not visibility: + visibility = PublishedRunVisibility.get_default_for_workspace(workspace) + with transaction.atomic(): pr = self.create( workflow=workflow, @@ -1844,7 +1854,7 @@ def duplicate( workspace: "Workspace", title: str, notes: str, - visibility: PublishedRunVisibility, + visibility: PublishedRunVisibility | None = None, ) -> "PublishedRun": return PublishedRun.objects.create_with_version( workflow=Workflow(self.workflow), @@ -1867,13 +1877,14 @@ def add_version( *, user: AppUser | None, saved_run: SavedRun, - visibility: PublishedRunVisibility, + visibility: PublishedRunVisibility | None = None, title: str = "", notes: str = "", change_notes: str = "", ): assert saved_run.workflow == self.workflow + visibility = visibility or self.visibility with transaction.atomic(): version = PublishedRunVersion( published_run=self, diff --git a/daras_ai_v2/base.py b/daras_ai_v2/base.py index 1e2948370..582e3f315 100644 --- a/daras_ai_v2/base.py +++ b/daras_ai_v2/base.py @@ -820,7 +820,6 @@ def _render_publish_form( workspace=selected_workspace, title=published_run_title.strip(), notes=published_run_description.strip(), - visibility=PublishedRunVisibility.UNLISTED, ) else: if not self.can_user_edit_published_run(self.current_pr): @@ -830,7 +829,6 @@ def _render_publish_form( saved_run=sr, title=published_run_title.strip(), notes=published_run_description.strip(), - visibility=PublishedRunVisibility.UNLISTED, ) if not self._has_published_run_changed(published_run=pr, **updates): gui.error("No changes to publish", icon="⚠️") @@ -900,12 +898,10 @@ def _has_published_run_changed( saved_run: SavedRun, title: str, notes: str, - visibility: PublishedRunVisibility, ): return ( published_run.title != title or published_run.notes != notes - or published_run.visibility != visibility or published_run.saved_run != saved_run ) @@ -980,7 +976,6 @@ def _saved_options_modal(self): workspace=self.current_workspace, title=title, notes=notes, - visibility=PublishedRunVisibility.UNLISTED, ) raise gui.RedirectException( self.app_url(example_id=duplicate_pr.published_run_id) @@ -994,7 +989,6 @@ def _saved_options_modal(self): workspace=self.current_workspace, title=title, notes=notes, - visibility=PublishedRunVisibility.UNLISTED, ) raise gui.RedirectException( self.app_url(example_id=new_pr.published_run_id) @@ -1022,7 +1016,6 @@ def _unsaved_options_modal(self): workspace=self.current_workspace, title=f"{self.request.user.first_name_possesive()} {pr.title}", notes=pr.notes, - visibility=PublishedRunVisibility(PublishedRunVisibility.UNLISTED), ) raise gui.RedirectException( self.app_url(example_id=duplicate_pr.published_run_id) @@ -1465,7 +1458,7 @@ def create_published_run( workspace: typing.Optional["Workspace"], title: str, notes: str, - visibility: PublishedRunVisibility, + visibility: PublishedRunVisibility | None = None, ): return PublishedRun.objects.create_with_version( workflow=cls.workflow, @@ -1944,7 +1937,6 @@ def publish_and_redirect(self) -> typing.NoReturn | None: workspace=self.current_workspace, title=self._get_default_pr_title(), notes=self.current_pr.notes, - visibility=PublishedRunVisibility(PublishedRunVisibility.UNLISTED), ) raise gui.RedirectException(pr.get_app_url())