Skip to content

Commit

Permalink
Merge pull request #557 from GooeyAI/fix-unlisted-visibility-on-save
Browse files Browse the repository at this point in the history
fix unlisted visibility on save
  • Loading branch information
nikochiko authored Dec 13, 2024
2 parents 3e8996c + c705ded commit 6cc797e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
19 changes: 15 additions & 4 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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="⚠️")
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 6cc797e

Please sign in to comment.