From f2c8cb54c397d0bfab65772c09a2c6b42f818ca3 Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:47:53 +0530 Subject: [PATCH] fix: default visibility for new published runs --- daras_ai_v2/base.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/daras_ai_v2/base.py b/daras_ai_v2/base.py index d356a8d6e..9776859a1 100644 --- a/daras_ai_v2/base.py +++ b/daras_ai_v2/base.py @@ -815,7 +815,7 @@ def _render_publish_form( workspace=selected_workspace, title=published_run_title.strip(), notes=published_run_description.strip(), - visibility=PublishedRunVisibility.UNLISTED, + visibility=self._get_default_pr_visibility(selected_workspace), ) else: if not self.can_user_edit_published_run(self.current_pr): @@ -876,6 +876,14 @@ def _get_default_pr_title(self): recipe_title = self.get_root_pr().title or self.title return f"{self.request.user.first_name_possesive()} {recipe_title}" + def _get_default_pr_visibility(self, workspace: Workspace | None = None): + if not workspace: + workspace = self.current_workspace + if workspace and not workspace.is_personal: + return PublishedRunVisibility.INTERNAL + else: + return PublishedRunVisibility.UNLISTED + def _validate_published_run_title(self, title: str): if slugify(title) in settings.DISALLOWED_TITLE_SLUGS: raise TitleValidationError( @@ -975,7 +983,7 @@ def _saved_options_modal(self): workspace=self.current_workspace, title=title, notes=notes, - visibility=PublishedRunVisibility.UNLISTED, + visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException( self.app_url(example_id=duplicate_pr.published_run_id) @@ -989,7 +997,7 @@ def _saved_options_modal(self): workspace=self.current_workspace, title=title, notes=notes, - visibility=PublishedRunVisibility.UNLISTED, + visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException( self.app_url(example_id=new_pr.published_run_id) @@ -1017,7 +1025,7 @@ 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), + visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException( self.app_url(example_id=duplicate_pr.published_run_id) @@ -1938,7 +1946,7 @@ 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), + visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException(pr.get_app_url())