mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-08 06:40:07 +00:00
Fix bug when creating a new application
This commit is contained in:
parent
f98e72156a
commit
607b410fb1
18 changed files with 44 additions and 49 deletions
backend
src/baserow/contrib/builder
tests/baserow/contrib
builder
api
domains
elements
test_builder_application_type.pytest_permissions_manager.pyintegrations/local_baserow
enterprise/backend/tests/baserow_enterprise_tests/integrations/local_baserow
|
@ -270,9 +270,7 @@ class DataSourceView(APIView):
|
|||
if "page_id" in request.data:
|
||||
page = PageHandler().get_page(
|
||||
int(request.data["page_id"]),
|
||||
base_queryset=Page.objects_with_shared.filter(
|
||||
builder=data_source.page.builder
|
||||
),
|
||||
base_queryset=Page.objects.filter(builder=data_source.page.builder),
|
||||
)
|
||||
|
||||
# Do we have a service?
|
||||
|
|
|
@ -7,7 +7,6 @@ from django.conf import settings
|
|||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.files.storage import Storage
|
||||
from django.db import transaction
|
||||
from django.db.models import Prefetch
|
||||
from django.db.transaction import Atomic
|
||||
from django.urls import include, path
|
||||
|
||||
|
@ -175,7 +174,7 @@ class BuilderApplicationType(ApplicationType):
|
|||
|
||||
pages = PageHandler().get_pages(
|
||||
builder,
|
||||
base_queryset=Page.objects_with_shared.prefetch_related(
|
||||
base_queryset=Page.objects.prefetch_related(
|
||||
"element_set", "datasource_set"
|
||||
),
|
||||
)
|
||||
|
@ -497,9 +496,7 @@ class BuilderApplicationType(ApplicationType):
|
|||
|
||||
def enhance_queryset(self, queryset):
|
||||
queryset = queryset.select_related("favicon_file").prefetch_related(
|
||||
"user_sources",
|
||||
"integrations",
|
||||
Prefetch("page_set", queryset=Page.objects_with_shared.all()),
|
||||
"user_sources", "integrations", "page_set"
|
||||
)
|
||||
queryset = theme_config_block_registry.enhance_list_builder_queryset(queryset)
|
||||
return queryset
|
||||
|
|
|
@ -834,7 +834,7 @@ class MultiPageElementTypeMixin:
|
|||
if "pages" in values:
|
||||
pages = PageHandler().get_pages(
|
||||
instance.page.builder,
|
||||
base_queryset=Page.objects.filter(
|
||||
base_queryset=Page.objects_without_shared.filter(
|
||||
id__in=[p.id for p in values["pages"]]
|
||||
),
|
||||
)
|
||||
|
@ -852,7 +852,7 @@ class MultiPageElementTypeMixin:
|
|||
if "pages" in values:
|
||||
pages = PageHandler().get_pages(
|
||||
instance.page.builder,
|
||||
base_queryset=Page.objects.filter(
|
||||
base_queryset=Page.objects_without_shared.filter(
|
||||
id__in=[p.id for p in values["pages"]]
|
||||
),
|
||||
)
|
||||
|
|
|
@ -55,6 +55,10 @@ class Builder(Application):
|
|||
# but it's a more generic type
|
||||
return self.application_ptr
|
||||
|
||||
@property
|
||||
def visible_pages(self):
|
||||
return self.page_set(manager="objects_without_shared")
|
||||
|
||||
@cached_property
|
||||
def shared_page(self):
|
||||
from baserow.contrib.builder.pages.handler import PageHandler
|
||||
|
|
|
@ -58,7 +58,7 @@ class PageHandler:
|
|||
"""
|
||||
|
||||
if base_queryset is None:
|
||||
base_queryset = Page.objects_with_shared
|
||||
base_queryset = Page.objects
|
||||
|
||||
try:
|
||||
return base_queryset.select_related("builder__workspace").get(id=page_id)
|
||||
|
@ -70,7 +70,7 @@ class PageHandler:
|
|||
Returns the shared page for the given builder.
|
||||
"""
|
||||
|
||||
return Page.objects_with_shared.select_related("builder__workspace").get(
|
||||
return Page.objects.select_related("builder__workspace").get(
|
||||
builder=builder, shared=True
|
||||
)
|
||||
|
||||
|
@ -80,7 +80,7 @@ class PageHandler:
|
|||
"""
|
||||
|
||||
if base_queryset is None:
|
||||
base_queryset = Page.objects_with_shared.all()
|
||||
base_queryset = Page.objects.all()
|
||||
|
||||
return base_queryset.filter(builder=builder).select_related(
|
||||
"builder__workspace"
|
||||
|
@ -178,7 +178,7 @@ class PageHandler:
|
|||
self.is_page_path_unique(
|
||||
page.builder,
|
||||
path,
|
||||
base_queryset=Page.objects_with_shared.exclude(
|
||||
base_queryset=Page.objects.exclude(
|
||||
id=page.id
|
||||
), # We don't want to conflict with the current page
|
||||
raises=True,
|
||||
|
@ -220,7 +220,7 @@ class PageHandler:
|
|||
"""
|
||||
|
||||
if base_qs is None:
|
||||
base_qs = Page.objects.filter(builder=builder)
|
||||
base_qs = Page.objects_without_shared.filter(builder=builder)
|
||||
|
||||
try:
|
||||
full_order = Page.order_objects(base_qs, order)
|
||||
|
@ -418,7 +418,7 @@ class PageHandler:
|
|||
:return: If the path is unique
|
||||
"""
|
||||
|
||||
queryset = Page.objects_with_shared if base_queryset is None else base_queryset
|
||||
queryset = Page.objects if base_queryset is None else base_queryset
|
||||
|
||||
existing_paths = queryset.filter(builder=builder).values_list("path", flat=True)
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ class Page(
|
|||
ALLOW_ALL_EXCEPT = "allow_all_except"
|
||||
DISALLOW_ALL_EXCEPT = "disallow_all_except"
|
||||
|
||||
objects = PageWithoutSharedManager()
|
||||
objects_with_shared = models.Manager()
|
||||
objects = models.Manager()
|
||||
objects_without_shared = PageWithoutSharedManager()
|
||||
|
||||
builder = models.ForeignKey("builder.Builder", on_delete=models.CASCADE)
|
||||
order = models.PositiveIntegerField()
|
||||
|
@ -98,7 +98,7 @@ class Page(
|
|||
|
||||
@classmethod
|
||||
def get_last_order(cls, builder: "Builder"):
|
||||
queryset = Page.objects.filter(builder=builder)
|
||||
queryset = Page.objects_without_shared.filter(builder=builder)
|
||||
return cls.get_highest_order_of_queryset(queryset) + 1
|
||||
|
||||
|
||||
|
|
|
@ -159,7 +159,9 @@ class PageService:
|
|||
context=builder,
|
||||
)
|
||||
|
||||
all_pages = self.handler.get_pages(builder, base_queryset=Page.objects)
|
||||
all_pages = self.handler.get_pages(
|
||||
builder, base_queryset=Page.objects_without_shared
|
||||
)
|
||||
|
||||
user_pages = CoreHandler().filter_queryset(
|
||||
user,
|
||||
|
|
|
@ -128,10 +128,7 @@ def test_get_public_builder_by_domain_name(api_client, data_fixture):
|
|||
|
||||
del response_json["theme"] # We are not testing the theme response here.
|
||||
|
||||
assert (
|
||||
builder_to.page_set(manager="objects_with_shared").filter(shared=True).count()
|
||||
== 1
|
||||
)
|
||||
assert builder_to.page_set.filter(shared=True).count() == 1
|
||||
|
||||
shared_page = builder_to.shared_page
|
||||
|
||||
|
@ -260,10 +257,7 @@ def test_get_public_builder_by_id(api_client, data_fixture):
|
|||
|
||||
del response_json["theme"] # We are not testing the theme response here.
|
||||
|
||||
assert (
|
||||
page.builder.page_set(manager="objects_with_shared").filter(shared=True).count()
|
||||
== 1
|
||||
)
|
||||
assert page.builder.page_set.filter(shared=True).count() == 1
|
||||
|
||||
shared_page = page.builder.shared_page
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ def test_validate_login_page_id_raises_error_if_shared_page(
|
|||
builder = builder_fixture["builder"]
|
||||
|
||||
# Set the builder's page to be the shared page
|
||||
shared_page = builder.page_set(manager="objects_with_shared").get(shared=True)
|
||||
shared_page = builder.page_set.get(shared=True)
|
||||
response = api_client.patch(
|
||||
reverse("api:applications:item", kwargs={"application_id": builder.id}),
|
||||
{"login_page_id": shared_page.id},
|
||||
|
|
|
@ -185,8 +185,8 @@ def test_domain_publishing(data_fixture):
|
|||
|
||||
assert domain1.published_to is not None
|
||||
assert domain1.published_to.workspace is None
|
||||
assert domain1.published_to.page_set.count() == builder.page_set.count()
|
||||
assert domain1.published_to.page_set.first().element_set.count() == 2
|
||||
assert domain1.published_to.visible_pages.count() == builder.visible_pages.count()
|
||||
assert domain1.published_to.visible_pages.first().element_set.count() == 2
|
||||
|
||||
assert Builder.objects.count() == 2
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ def test_import_export_collection_element_type(collection_element_mixin_fixture)
|
|||
imported_field = imported_table.field_set.get()
|
||||
|
||||
# Pluck out the imported builder records.
|
||||
imported_page = imported_builder.page_set.exclude(path="__shared__")[0]
|
||||
imported_page = imported_builder.visible_pages.exclude(path="__shared__")[0]
|
||||
imported_element = imported_page.element_set.get()
|
||||
|
||||
imported_property_options = [
|
||||
|
|
|
@ -1542,7 +1542,7 @@ def test_repeat_element_import_export(data_fixture):
|
|||
imported_field = imported_table.field_set.get()
|
||||
|
||||
# Pluck out the imported builder records.
|
||||
imported_page = imported_builder.page_set.all()[0]
|
||||
imported_page = imported_builder.visible_pages.all()[0]
|
||||
imported_data_source = imported_page.datasource_set.get()
|
||||
imported_root_repeat = imported_page.element_set.get(
|
||||
parent_element_id=None
|
||||
|
|
|
@ -93,7 +93,9 @@ def test_export_import_record_selector_element(data_fixture):
|
|||
import_export_config=config,
|
||||
)
|
||||
imported_builder = imported_apps[-1]
|
||||
imported_element = imported_builder.page_set.first().element_set.first().specific
|
||||
imported_element = (
|
||||
imported_builder.visible_pages.first().element_set.first().specific
|
||||
)
|
||||
|
||||
# Check that the formula for option name suffix was updated with the new mapping
|
||||
import_option_name_suffix = imported_element.option_name_suffix
|
||||
|
|
|
@ -65,11 +65,11 @@ def test_builder_application_type_init_application(data_fixture):
|
|||
user = data_fixture.create_user()
|
||||
builder = data_fixture.create_builder_application(user=user)
|
||||
|
||||
assert Page.objects.count() == 0
|
||||
assert Page.objects_without_shared.count() == 0
|
||||
|
||||
BuilderApplicationType().init_application(user, builder)
|
||||
|
||||
assert Page.objects.count() == 2 # With demo data
|
||||
assert Page.objects_without_shared.count() == 2 # With demo data
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
@ -1059,11 +1059,9 @@ def test_builder_application_import(data_fixture):
|
|||
)
|
||||
|
||||
assert builder.id != serialized_values["id"]
|
||||
assert builder.page_set.count() == 2
|
||||
assert builder.visible_pages.count() == 2
|
||||
# ensure we have the shared page even if it's not in the reference
|
||||
assert (
|
||||
builder.page_set(manager="objects_with_shared").filter(shared=True).count() == 1
|
||||
)
|
||||
assert builder.page_set.filter(shared=True).count() == 1
|
||||
|
||||
assert builder.integrations.count() == 1
|
||||
first_integration = builder.integrations.first().specific
|
||||
|
@ -1071,7 +1069,7 @@ def test_builder_application_import(data_fixture):
|
|||
|
||||
assert builder.user_sources.count() == 1
|
||||
|
||||
[page1, page2] = builder.page_set.all()
|
||||
[page1, page2] = builder.visible_pages.all()
|
||||
|
||||
assert page1.element_set.count() == 6
|
||||
assert page2.element_set.count() == 1
|
||||
|
@ -1280,7 +1278,7 @@ def test_builder_application_imports_page_with_default_visibility(
|
|||
workspace, serialized_values, config, {}
|
||||
)
|
||||
|
||||
page = builder.page_set.first()
|
||||
page = builder.visible_pages.first()
|
||||
|
||||
assert getattr(page, page_property) == value
|
||||
|
||||
|
@ -1469,7 +1467,7 @@ def test_builder_application_imports_correct_default_roles(data_fixture):
|
|||
workspace, serialized_values, config, {}
|
||||
)
|
||||
|
||||
new_element = builder.page_set.first().element_set.all()[0]
|
||||
new_element = builder.visible_pages.first().element_set.all()[0]
|
||||
new_user_source = builder.user_sources.all()[0]
|
||||
|
||||
# Ensure the "old" Default User Role doesn't exist
|
||||
|
@ -1553,7 +1551,7 @@ def test_ensure_new_element_roles_are_sanitized_during_import_for_default_roles(
|
|||
expected_roles = _expected_roles
|
||||
|
||||
# Ensure new element has roles updated
|
||||
new_element = builder.page_set.all()[0].element_set.all()[0]
|
||||
new_element = builder.visible_pages.all()[0].element_set.all()[0]
|
||||
for index, role in enumerate(new_element.roles):
|
||||
# Default Role's User Source should have changed for new elements
|
||||
if role.startswith(prefix):
|
||||
|
@ -1630,7 +1628,7 @@ def test_ensure_new_element_roles_are_sanitized_during_import_for_roles(
|
|||
workspace, serialized, config, {}
|
||||
)
|
||||
|
||||
new_element = builder.page_set.all()[0].element_set.all()[0]
|
||||
new_element = builder.visible_pages.all()[0].element_set.all()[0]
|
||||
assert new_element.roles == expected_roles
|
||||
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ def test_allow_if_template_permission_manager_filter_queryset(data_fixture):
|
|||
tests_w1 = [
|
||||
(
|
||||
ListPagesBuilderOperationType.type,
|
||||
Page.objects_with_shared.filter(builder__workspace=workspace_2),
|
||||
Page.objects.filter(builder__workspace=workspace_2),
|
||||
[shared_page_2.id, page_2.id],
|
||||
),
|
||||
(
|
||||
|
|
|
@ -599,7 +599,7 @@ def test_export_import_local_baserow_upsert_row_service(
|
|||
imported_table = imported_database.table_set.get()
|
||||
imported_field = imported_table.field_set.get()
|
||||
|
||||
imported_page = imported_builder.page_set.get()
|
||||
imported_page = imported_builder.visible_pages.get()
|
||||
imported_data_source = imported_page.datasource_set.get()
|
||||
imported_integration = imported_builder.integrations.get()
|
||||
imported_upsert_row_service = LocalBaserowUpsertRow.objects.get(
|
||||
|
|
|
@ -173,7 +173,7 @@ def test_local_baserow_table_service_filterable_mixin_import_export(data_fixture
|
|||
imported_select_option = imported_single_select_field.select_options.get()
|
||||
|
||||
# Pluck out the imported builder records.
|
||||
imported_page = imported_builder.page_set.get()
|
||||
imported_page = imported_builder.visible_pages.get()
|
||||
imported_datasource = imported_page.datasource_set.get()
|
||||
imported_filters = [
|
||||
{"field_id": sf.field_id, "value": sf.value}
|
||||
|
|
|
@ -1148,7 +1148,7 @@ def test_public_dispatch_data_source_with_ab_user_using_user_source(
|
|||
refresh_token = user_source_user.get_refresh_token()
|
||||
access_token = refresh_token.access_token
|
||||
|
||||
published_page = domain1.published_to.page_set.first()
|
||||
published_page = domain1.published_to.visible_pages.first()
|
||||
published_data_source = published_page.datasource_set.first()
|
||||
|
||||
url = reverse(
|
||||
|
|
Loading…
Add table
Reference in a new issue