From 44fde02dd75e42b339ad701fbc06e3e09decebe4 Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:32:49 +0530 Subject: [PATCH 1/4] fix visibility: dont change to unlisted on 'Save' --- daras_ai_v2/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daras_ai_v2/base.py b/daras_ai_v2/base.py index 399592b8d..d356a8d6e 100644 --- a/daras_ai_v2/base.py +++ b/daras_ai_v2/base.py @@ -825,7 +825,7 @@ def _render_publish_form( saved_run=sr, title=published_run_title.strip(), notes=published_run_description.strip(), - visibility=PublishedRunVisibility.UNLISTED, + visibility=pr.visibility, ) if not self._has_published_run_changed(published_run=pr, **updates): gui.error("No changes to publish", icon="⚠️") 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 2/4] 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()) From 5e9652facc9a7a155a8b53700a8de5bcbe78a5c6 Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:24:46 +0530 Subject: [PATCH 3/4] set default visibility in add_version & create_with_version --- bots/models.py | 19 +++++++++++++++---- daras_ai_v2/base.py | 9 +-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bots/models.py b/bots/models.py index 88df2c255..6e0911503 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 @@ -1674,7 +1681,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, @@ -1701,13 +1708,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, @@ -1840,7 +1850,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), @@ -1863,13 +1873,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 9776859a1..22fdb070d 100644 --- a/daras_ai_v2/base.py +++ b/daras_ai_v2/base.py @@ -815,7 +815,6 @@ def _render_publish_form( workspace=selected_workspace, title=published_run_title.strip(), notes=published_run_description.strip(), - visibility=self._get_default_pr_visibility(selected_workspace), ) else: if not self.can_user_edit_published_run(self.current_pr): @@ -825,7 +824,6 @@ def _render_publish_form( saved_run=sr, title=published_run_title.strip(), notes=published_run_description.strip(), - visibility=pr.visibility, ) if not self._has_published_run_changed(published_run=pr, **updates): gui.error("No changes to publish", icon="⚠️") @@ -903,12 +901,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 ) @@ -983,7 +979,6 @@ def _saved_options_modal(self): workspace=self.current_workspace, title=title, notes=notes, - visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException( self.app_url(example_id=duplicate_pr.published_run_id) @@ -997,7 +992,6 @@ def _saved_options_modal(self): workspace=self.current_workspace, title=title, notes=notes, - visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException( self.app_url(example_id=new_pr.published_run_id) @@ -1025,7 +1019,6 @@ def _unsaved_options_modal(self): workspace=self.current_workspace, title=f"{self.request.user.first_name_possesive()} {pr.title}", notes=pr.notes, - visibility=self._get_default_pr_visibility(), ) raise gui.RedirectException( self.app_url(example_id=duplicate_pr.published_run_id) @@ -1467,7 +1460,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, From c705ded0963e6ee0b4ac835ab10784a22da9225e Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:27:01 +0530 Subject: [PATCH 4/4] remove get_default_pr_visibility from base.py --- daras_ai_v2/base.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/daras_ai_v2/base.py b/daras_ai_v2/base.py index 22fdb070d..e7bd6415f 100644 --- a/daras_ai_v2/base.py +++ b/daras_ai_v2/base.py @@ -874,14 +874,6 @@ 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( @@ -1939,7 +1931,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=self._get_default_pr_visibility(), ) raise gui.RedirectException(pr.get_app_url())