mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
Fix AB template permissions for preview
This commit is contained in:
1 parent
67d66ed269
commit
38da185cd8
19 files changed
+173
-18
No files matched your search
@@ -4,7 +4,7 @@ from django.db import transaction
|
||||
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
@@ -52,6 +52,12 @@ from baserow.core.integrations.service import IntegrationService
|
||||
class IntegrationsView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
|
||||
return super().get_permissions()
|
||||
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
|
||||
@@ -33,7 +33,7 @@ class TemplateSerializer(serializers.ModelSerializer):
|
||||
|
||||
@extend_schema_field(OpenApiTypes.STR)
|
||||
def get_is_default(self, instance):
|
||||
return instance.slug == settings.DEFAULT_APPLICATION_TEMPLATE
|
||||
return instance.slug == settings.DEFAULT_APPLICATION_TEMPLATES[0]
|
||||
|
||||
|
||||
class TemplateCategoriesSerializer(serializers.ModelSerializer):
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
from django.urls import re_path
|
||||
|
||||
from .views import AsyncInstallTemplateView, InstallTemplateView, TemplatesView
|
||||
from .views import (
|
||||
AsyncInstallTemplateView,
|
||||
InstallTemplateView,
|
||||
TemplatesView,
|
||||
TemplateView,
|
||||
)
|
||||
|
||||
app_name = "baserow.api.templates"
|
||||
|
||||
@@ -16,5 +21,6 @@ urlpatterns = [
|
||||
AsyncInstallTemplateView.as_view(),
|
||||
name="install_async",
|
||||
),
|
||||
re_path(r"(?P<slug>[\w-]+)/$", TemplateView.as_view(), name="item"),
|
||||
re_path(r"$", TemplatesView.as_view(), name="list"),
|
||||
]
|
||||
@@ -19,7 +19,10 @@ from baserow.api.schemas import (
|
||||
CLIENT_UNDO_REDO_ACTION_GROUP_ID_SCHEMA_PARAMETER,
|
||||
get_error_schema,
|
||||
)
|
||||
from baserow.api.templates.serializers import TemplateCategoriesSerializer
|
||||
from baserow.api.templates.serializers import (
|
||||
TemplateCategoriesSerializer,
|
||||
TemplateSerializer,
|
||||
)
|
||||
from baserow.core.action.registries import action_type_registry
|
||||
from baserow.core.actions import InstallTemplateActionType
|
||||
from baserow.core.exceptions import (
|
||||
@@ -33,7 +36,7 @@ from baserow.core.job_types import InstallTemplateJobType
|
||||
from baserow.core.jobs.exceptions import MaxJobCountExceeded
|
||||
from baserow.core.jobs.handler import JobHandler
|
||||
from baserow.core.jobs.registries import job_type_registry
|
||||
from baserow.core.models import TemplateCategory
|
||||
from baserow.core.models import Template, TemplateCategory
|
||||
|
||||
from .errors import ERROR_TEMPLATE_DOES_NOT_EXIST, ERROR_TEMPLATE_FILE_DOES_NOT_EXIST
|
||||
|
||||
@@ -61,6 +64,31 @@ class TemplatesView(APIView):
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class TemplateView(APIView):
|
||||
permission_classes = (AllowAny,)
|
||||
|
||||
@extend_schema(exclude=True)
|
||||
@map_exceptions(
|
||||
{
|
||||
TemplateDoesNotExist: ERROR_TEMPLATE_DOES_NOT_EXIST,
|
||||
}
|
||||
)
|
||||
def get(self, request, slug):
|
||||
"""
|
||||
Responds with a more detailed serialized version of the template related to
|
||||
the provided template slug.
|
||||
"""
|
||||
|
||||
try:
|
||||
template = Template.objects.prefetch_related("categories").get(slug=slug)
|
||||
except Template.DoesNotExist as exc:
|
||||
raise TemplateDoesNotExist(
|
||||
f"The template with slug {slug} does not exist."
|
||||
) from exc
|
||||
|
||||
return Response(TemplateSerializer(template).data)
|
||||
|
||||
|
||||
class InstallTemplateView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
|
||||
@@ -83,6 +83,12 @@ from baserow.core.user_sources.service import UserSourceService
|
||||
class UserSourcesView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
|
||||
return super().get_permissions()
|
||||
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
@@ -202,6 +208,12 @@ class UserSourcesView(APIView):
|
||||
class UserSourceRolesView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
|
||||
return super().get_permissions()
|
||||
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
|
||||
@@ -893,7 +893,7 @@ APPLICATION_TEMPLATES_DIR = os.path.join(BASE_DIR, "../../../templates")
|
||||
# The template that must be selected when the user first opens the templates select
|
||||
# modal.
|
||||
# IF CHANGING KEEP IN SYNC WITH e2e-tests/wait-for-services.sh
|
||||
DEFAULT_APPLICATION_TEMPLATE = "project-tracker"
|
||||
DEFAULT_APPLICATION_TEMPLATES = ["project-tracker", "ab_ivory_theme"]
|
||||
BASEROW_SYNC_TEMPLATES_PATTERN = os.getenv("BASEROW_SYNC_TEMPLATES_PATTERN", None)
|
||||
|
||||
MAX_FIELD_LIMIT = int(os.getenv("BASEROW_MAX_FIELD_LIMIT", 600))
|
||||
|
||||
@@ -16,7 +16,9 @@ def sync_single_default_template_only_for_e2e(sender, **kwargs):
|
||||
|
||||
from baserow.core.handler import CoreHandler
|
||||
|
||||
CoreHandler().sync_templates(pattern=f"^{settings.DEFAULT_APPLICATION_TEMPLATE}$")
|
||||
pattern = f"^({'|'.join(settings.DEFAULT_APPLICATION_TEMPLATES)})$"
|
||||
|
||||
CoreHandler().sync_templates(pattern=pattern)
|
||||
|
||||
|
||||
# Disable normal template syncing in CI as we will sync a single template ourselves
|
||||
|
||||
@@ -78,6 +78,12 @@ from baserow.core.services.registries import service_type_registry
|
||||
class DataSourcesView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
|
||||
return super().get_permissions()
|
||||
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.db import transaction
|
||||
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
@@ -53,6 +53,12 @@ from baserow.contrib.builder.pages.handler import PageHandler
|
||||
class ElementsView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
|
||||
return super().get_permissions()
|
||||
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
|
||||
@@ -74,6 +74,12 @@ from baserow.core.workflow_actions.exceptions import WorkflowActionDoesNotExist
|
||||
class BuilderWorkflowActionsView(APIView):
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
|
||||
return super().get_permissions()
|
||||
|
||||
@extend_schema(
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"type": "bug",
|
||||
"message": "Resolved an issue which prevented logged-out users from previewing certain application templates",
|
||||
"domain": "builder",
|
||||
"issue_number": null,
|
||||
"bullet_points": [],
|
||||
"created_at": "2025-04-01"
|
||||
}
|
||||
@@ -38,7 +38,10 @@ export async function getStaffUser(): Promise<User> {
|
||||
return getTokenAuth("e2e@baserow.io", "testpassword");
|
||||
}
|
||||
|
||||
export async function createUser(skipOnboarding = true): Promise<User> {
|
||||
export async function createUser(
|
||||
skipOnboarding = true,
|
||||
skipGuidedTours = true
|
||||
): Promise<User> {
|
||||
const password = faker.internet.password();
|
||||
const response: any = await getClient().post("user/", {
|
||||
name: faker.name.fullName(),
|
||||
@@ -55,9 +58,12 @@ export async function createUser(skipOnboarding = true): Promise<User> {
|
||||
accessToken: response.data.access_token,
|
||||
refreshToken: response.data.refresh_token,
|
||||
};
|
||||
if (skipOnboarding) {
|
||||
if (skipOnboarding || skipGuidedTours) {
|
||||
await getClient(user).patch("user/account/", {
|
||||
completed_onboarding: true,
|
||||
completed_onboarding: skipOnboarding,
|
||||
completed_guided_tours: skipGuidedTours
|
||||
? ["sidebar", "database", "builder"]
|
||||
: [],
|
||||
});
|
||||
}
|
||||
return user;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Page } from "@playwright/test";
|
||||
import { BaserowPage } from "./baserowPage";
|
||||
|
||||
export class TemplatePage extends BaserowPage {
|
||||
readonly templateSlug: String;
|
||||
|
||||
constructor(page: Page, slug: String) {
|
||||
super(page);
|
||||
this.templateSlug = slug;
|
||||
}
|
||||
|
||||
getFullUrl() {
|
||||
return `${this.baseUrl}/template/${this.templateSlug}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { TemplatePage } from "../../pages/templatePage";
|
||||
import { expect, test } from "../baserowTest";
|
||||
|
||||
test.describe("Builder template application test suite", () => {
|
||||
test("Can show an AB template", async ({ page }) => {
|
||||
const templatePage = new TemplatePage(page, "ab_ivory_theme");
|
||||
|
||||
await templatePage.goto();
|
||||
|
||||
await expect(
|
||||
page.locator(".ab-heading--h3").getByText("Rebranding website")
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ set -Eeo pipefail
|
||||
# to become healthy.
|
||||
|
||||
# Keep in sync with src/baserow/config/settings/base.py:594
|
||||
DEFAULT_APPLICATION_TEMPLATE="project-tracker"
|
||||
DEFAULT_APPLICATION_TEMPLATES=("project-tracker" "ab_ivory_theme")
|
||||
|
||||
baserow_ready() {
|
||||
curlf() {
|
||||
@@ -19,11 +19,13 @@ baserow_ready() {
|
||||
|
||||
templates_ready(){
|
||||
TEMPLATES_JSON=$(curl --silent --max-time 10 "${PUBLIC_BACKEND_URL:-http://backend:8000}/api/templates/")
|
||||
if [[ ${TEMPLATES_JSON} == *"$DEFAULT_APPLICATION_TEMPLATE"* ]] ; then
|
||||
return 0
|
||||
fi
|
||||
echo "Template $DEFAULT_APPLICATION_TEMPLATE is missing..."
|
||||
return 22
|
||||
for template in "${DEFAULT_APPLICATION_TEMPLATES[@]}"; do
|
||||
if [[ ${TEMPLATES_JSON} != *"$template"* ]] ; then
|
||||
echo "Template $template is missing..."
|
||||
return 22
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
if curlf "${PUBLIC_WEB_FRONTEND_URL:-http://web-frontend:3000}/_health/" && curlf "${PUBLIC_BACKEND_URL:-http://backend:8000}/api/_health/" && templates_ready; then
|
||||
|
||||
@@ -10,7 +10,13 @@
|
||||
:subtitle="subtitle"
|
||||
:rounded-icon="false"
|
||||
:avatar-color="isInError ? 'red' : 'neutral'"
|
||||
@click="$emit('edit', dataSource)"
|
||||
@click="
|
||||
$hasPermission(
|
||||
'builder.page.data_source.update',
|
||||
dataSource,
|
||||
workspace.id
|
||||
) && $emit('edit', dataSource)
|
||||
"
|
||||
/>
|
||||
<div
|
||||
v-if="
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<TemplatePreview v-if="template" :template="template" />
|
||||
<div v-else>error</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import TemplatePreview from '@baserow/modules/core/components/template/TemplatePreview'
|
||||
import TemplateService from '@baserow/modules/core/services/template'
|
||||
|
||||
export default {
|
||||
name: 'Template',
|
||||
components: { TemplatePreview },
|
||||
async asyncData({ store, params, error, $client, ...rest }) {
|
||||
const slug = params.slug
|
||||
try {
|
||||
const { data } = await TemplateService($client).fetch(slug)
|
||||
|
||||
return { template: data }
|
||||
} catch (error) {
|
||||
return { template: null }
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -83,6 +83,11 @@ export const routes = [
|
||||
path: '/style-guide',
|
||||
component: path.resolve(__dirname, 'pages/styleGuide.vue'),
|
||||
},
|
||||
{
|
||||
name: 'template',
|
||||
path: '/template/:slug',
|
||||
component: path.resolve(__dirname, 'pages/template.vue'),
|
||||
},
|
||||
{
|
||||
name: 'health-check',
|
||||
path: '/_health',
|
||||
|
||||
@@ -3,6 +3,9 @@ export default (client) => {
|
||||
fetchAll() {
|
||||
return client.get('/templates/')
|
||||
},
|
||||
fetch(slug) {
|
||||
return client.get(`/templates/${slug}/`)
|
||||
},
|
||||
install(workspaceId, templateId) {
|
||||
return client.post(`/templates/install/${workspaceId}/${templateId}/`)
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user