mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-24 21:38:09 +02:00
chore: linting
This commit is contained in:
parent
4b8a2f9726
commit
b89866541e
10 changed files with 42 additions and 59 deletions
|
|
@ -23,6 +23,7 @@ import time
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
revision: str = "164"
|
revision: str = "164"
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import time
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
revision: str = "165"
|
revision: str = "165"
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ boundary.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import uuid
|
import uuid
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
|
|
@ -97,14 +98,16 @@ class TestConnectorIndexCrossSpaceAuthz:
|
||||||
db_session, victim, space_a, SearchSourceConnectorType.GITHUB_CONNECTOR
|
db_session, victim, space_a, SearchSourceConnectorType.GITHUB_CONNECTOR
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(_CHECK_PERMISSION, new=AsyncMock()) as check_permission_mock:
|
with (
|
||||||
with pytest.raises(HTTPException) as exc_info:
|
patch(_CHECK_PERMISSION, new=AsyncMock()) as check_permission_mock,
|
||||||
await index_connector_content(
|
pytest.raises(HTTPException) as exc_info,
|
||||||
connector_id=connector_a.id,
|
):
|
||||||
search_space_id=space_b.id, # the attacker's own space
|
await index_connector_content(
|
||||||
session=db_session,
|
connector_id=connector_a.id,
|
||||||
user=attacker,
|
search_space_id=space_b.id, # the attacker's own space
|
||||||
)
|
session=db_session,
|
||||||
|
user=attacker,
|
||||||
|
)
|
||||||
|
|
||||||
assert exc_info.value.status_code == 404
|
assert exc_info.value.status_code == 404
|
||||||
# Rejected at the search-space reconciliation, never reaching (or relying
|
# Rejected at the search-space reconciliation, never reaching (or relying
|
||||||
|
|
@ -124,18 +127,18 @@ class TestConnectorIndexCrossSpaceAuthz:
|
||||||
db_session, owner, space, SearchSourceConnectorType.CLICKUP_CONNECTOR
|
db_session, owner, space, SearchSourceConnectorType.CLICKUP_CONNECTOR
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(_CHECK_PERMISSION, new=AsyncMock()) as check_permission_mock:
|
# Any downstream indexing behaviour is irrelevant to the authz contract
|
||||||
try:
|
# under test; we only assert what space was authorized.
|
||||||
await index_connector_content(
|
with (
|
||||||
connector_id=connector.id,
|
patch(_CHECK_PERMISSION, new=AsyncMock()) as check_permission_mock,
|
||||||
search_space_id=space.id, # the connector's own space
|
contextlib.suppress(Exception),
|
||||||
session=db_session,
|
):
|
||||||
user=owner,
|
await index_connector_content(
|
||||||
)
|
connector_id=connector.id,
|
||||||
except Exception:
|
search_space_id=space.id, # the connector's own space
|
||||||
# Any downstream indexing behaviour is irrelevant to the authz
|
session=db_session,
|
||||||
# contract under test; we only assert what space was authorized.
|
user=owner,
|
||||||
pass
|
)
|
||||||
|
|
||||||
check_permission_mock.assert_awaited_once()
|
check_permission_mock.assert_awaited_once()
|
||||||
# The space passed to check_permission must be the connector's own space.
|
# The space passed to check_permission must be the connector's own space.
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { loader } from "fumadocs-core/source";
|
import { loader } from "fumadocs-core/source";
|
||||||
import type { MetadataRoute } from "next";
|
import type { MetadataRoute } from "next";
|
||||||
import { blog, changelog } from "@/.source/server";
|
import { blog, changelog } from "@/.source/server";
|
||||||
import { source as docsSource } from "@/lib/source";
|
|
||||||
import { SERVER_BACKEND_URL } from "@/lib/env-config";
|
import { SERVER_BACKEND_URL } from "@/lib/env-config";
|
||||||
|
import { source as docsSource } from "@/lib/source";
|
||||||
|
|
||||||
const blogSource = loader({
|
const blogSource = loader({
|
||||||
baseUrl: "/blog",
|
baseUrl: "/blog",
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
import { Search } from "lucide-react";
|
import { Search } from "lucide-react";
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
|
import { useIsSelfHosted } from "@/components/providers/runtime-config";
|
||||||
import { EnumConnectorName } from "@/contracts/enums/connector";
|
import { EnumConnectorName } from "@/contracts/enums/connector";
|
||||||
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
|
||||||
import { usePlatform } from "@/hooks/use-platform";
|
import { usePlatform } from "@/hooks/use-platform";
|
||||||
import { useIsSelfHosted } from "@/components/providers/runtime-config";
|
|
||||||
import { ConnectorCard } from "../components/connector-card";
|
import { ConnectorCard } from "../components/connector-card";
|
||||||
import {
|
import {
|
||||||
COMPOSIO_CONNECTORS,
|
COMPOSIO_CONNECTORS,
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ import type { FolderDisplay } from "@/components/documents/FolderNode";
|
||||||
import { FolderPickerDialog } from "@/components/documents/FolderPickerDialog";
|
import { FolderPickerDialog } from "@/components/documents/FolderPickerDialog";
|
||||||
import { FolderTreeView } from "@/components/documents/FolderTreeView";
|
import { FolderTreeView } from "@/components/documents/FolderTreeView";
|
||||||
import { VersionHistoryDialog } from "@/components/documents/version-history";
|
import { VersionHistoryDialog } from "@/components/documents/version-history";
|
||||||
|
import { useRuntimeConfig } from "@/components/providers/runtime-config";
|
||||||
import { EXPORT_FILE_EXTENSIONS } from "@/components/shared/ExportMenuItems";
|
import { EXPORT_FILE_EXTENSIONS } from "@/components/shared/ExportMenuItems";
|
||||||
import {
|
import {
|
||||||
DEFAULT_EXCLUDE_PATTERNS,
|
DEFAULT_EXCLUDE_PATTERNS,
|
||||||
|
|
@ -72,7 +73,6 @@ import type { DocumentTypeEnum } from "@/contracts/types/document.types";
|
||||||
import { useDebouncedValue } from "@/hooks/use-debounced-value";
|
import { useDebouncedValue } from "@/hooks/use-debounced-value";
|
||||||
import { useMediaQuery } from "@/hooks/use-media-query";
|
import { useMediaQuery } from "@/hooks/use-media-query";
|
||||||
import { useElectronAPI, usePlatform } from "@/hooks/use-platform";
|
import { useElectronAPI, usePlatform } from "@/hooks/use-platform";
|
||||||
import { useRuntimeConfig } from "@/components/providers/runtime-config";
|
|
||||||
import { anonymousChatApiService } from "@/lib/apis/anonymous-chat-api.service";
|
import { anonymousChatApiService } from "@/lib/apis/anonymous-chat-api.service";
|
||||||
import { documentsApiService } from "@/lib/apis/documents-api.service";
|
import { documentsApiService } from "@/lib/apis/documents-api.service";
|
||||||
import { foldersApiService } from "@/lib/apis/folders-api.service";
|
import { foldersApiService } from "@/lib/apis/folders-api.service";
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ import {
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import {
|
import {
|
||||||
MAX_DURATION_SECONDS,
|
|
||||||
type LanguageOptions,
|
type LanguageOptions,
|
||||||
|
MAX_DURATION_SECONDS,
|
||||||
MAX_SPEAKERS,
|
MAX_SPEAKERS,
|
||||||
MIN_DURATION_SECONDS,
|
MIN_DURATION_SECONDS,
|
||||||
type PodcastSpec,
|
type PodcastSpec,
|
||||||
|
|
@ -68,7 +68,7 @@ interface BriefReviewProps {
|
||||||
export function BriefReview({ podcast, spec }: BriefReviewProps) {
|
export function BriefReview({ podcast, spec }: BriefReviewProps) {
|
||||||
const [draft, setDraft] = useState<PodcastSpec>(spec);
|
const [draft, setDraft] = useState<PodcastSpec>(spec);
|
||||||
const [durationUnit, setDurationUnit] = useState<DurationUnit>(() =>
|
const [durationUnit, setDurationUnit] = useState<DurationUnit>(() =>
|
||||||
defaultDurationUnit(spec.duration.max_seconds),
|
defaultDurationUnit(spec.duration.max_seconds)
|
||||||
);
|
);
|
||||||
const [voices, setVoices] = useState<VoiceOption[] | null>(null);
|
const [voices, setVoices] = useState<VoiceOption[] | null>(null);
|
||||||
const [offering, setOffering] = useState<LanguageOptions | null>(null);
|
const [offering, setOffering] = useState<LanguageOptions | null>(null);
|
||||||
|
|
@ -361,7 +361,7 @@ export function BriefReview({ podcast, spec }: BriefReviewProps) {
|
||||||
value={formatDurationForUnit(draft.duration.min_seconds, durationUnit)}
|
value={formatDurationForUnit(draft.duration.min_seconds, durationUnit)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const seconds = clampDurationSeconds(
|
const seconds = clampDurationSeconds(
|
||||||
fromUnitValue(Number(e.target.value), durationUnit),
|
fromUnitValue(Number(e.target.value), durationUnit)
|
||||||
);
|
);
|
||||||
setDraft((current) => ({
|
setDraft((current) => ({
|
||||||
...current,
|
...current,
|
||||||
|
|
@ -381,15 +381,9 @@ export function BriefReview({ podcast, spec }: BriefReviewProps) {
|
||||||
value={formatDurationForUnit(draft.duration.max_seconds, durationUnit)}
|
value={formatDurationForUnit(draft.duration.max_seconds, durationUnit)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const parsed = Number(e.target.value);
|
const parsed = Number(e.target.value);
|
||||||
const fallback = secondsToUnitValue(
|
const fallback = secondsToUnitValue(draft.duration.min_seconds, durationUnit);
|
||||||
draft.duration.min_seconds,
|
|
||||||
durationUnit,
|
|
||||||
);
|
|
||||||
const seconds = clampDurationSeconds(
|
const seconds = clampDurationSeconds(
|
||||||
fromUnitValue(
|
fromUnitValue(Number.isFinite(parsed) ? parsed : fallback, durationUnit)
|
||||||
Number.isFinite(parsed) ? parsed : fallback,
|
|
||||||
durationUnit,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
setDraft((current) => ({
|
setDraft((current) => ({
|
||||||
...current,
|
...current,
|
||||||
|
|
@ -426,9 +420,7 @@ export function BriefReview({ podcast, spec }: BriefReviewProps) {
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleApprove}
|
onClick={handleApprove}
|
||||||
disabled={
|
disabled={isSubmitting || draft.duration.max_seconds < draft.duration.min_seconds}
|
||||||
isSubmitting || draft.duration.max_seconds < draft.duration.min_seconds
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : null}
|
{isSubmitting ? <Loader2 className="size-4 animate-spin" /> : null}
|
||||||
{isDirty ? "Approve changes & draft transcript" : "Approve & draft transcript"}
|
{isDirty ? "Approve changes & draft transcript" : "Approve & draft transcript"}
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,7 @@ export type SpeakerSpec = z.infer<typeof speakerSpec>;
|
||||||
|
|
||||||
export const durationTarget = z.preprocess(
|
export const durationTarget = z.preprocess(
|
||||||
(raw) => {
|
(raw) => {
|
||||||
if (
|
if (raw && typeof raw === "object" && "min_minutes" in raw && !("min_seconds" in raw)) {
|
||||||
raw &&
|
|
||||||
typeof raw === "object" &&
|
|
||||||
"min_minutes" in raw &&
|
|
||||||
!("min_seconds" in raw)
|
|
||||||
) {
|
|
||||||
const legacy = raw as { min_minutes: number; max_minutes: number };
|
const legacy = raw as { min_minutes: number; max_minutes: number };
|
||||||
return {
|
return {
|
||||||
min_seconds: legacy.min_minutes * 60,
|
min_seconds: legacy.min_minutes * 60,
|
||||||
|
|
@ -78,21 +73,13 @@ export const durationTarget = z.preprocess(
|
||||||
},
|
},
|
||||||
z
|
z
|
||||||
.object({
|
.object({
|
||||||
min_seconds: z
|
min_seconds: z.number().int().min(MIN_DURATION_SECONDS).max(MAX_DURATION_SECONDS),
|
||||||
.number()
|
max_seconds: z.number().int().min(MIN_DURATION_SECONDS).max(MAX_DURATION_SECONDS),
|
||||||
.int()
|
|
||||||
.min(MIN_DURATION_SECONDS)
|
|
||||||
.max(MAX_DURATION_SECONDS),
|
|
||||||
max_seconds: z
|
|
||||||
.number()
|
|
||||||
.int()
|
|
||||||
.min(MIN_DURATION_SECONDS)
|
|
||||||
.max(MAX_DURATION_SECONDS),
|
|
||||||
})
|
})
|
||||||
.refine((duration) => duration.max_seconds >= duration.min_seconds, {
|
.refine((duration) => duration.max_seconds >= duration.min_seconds, {
|
||||||
message: "Max length must be at least min length",
|
message: "Max length must be at least min length",
|
||||||
path: ["max_seconds"],
|
path: ["max_seconds"],
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
export type DurationTarget = z.infer<typeof durationTarget>;
|
export type DurationTarget = z.infer<typeof durationTarget>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,7 @@ type BackendUrlParam = string | number | boolean | null | undefined;
|
||||||
* BACKEND_URL is explicitly configured, the same path resolves against that
|
* BACKEND_URL is explicitly configured, the same path resolves against that
|
||||||
* absolute backend origin.
|
* absolute backend origin.
|
||||||
*/
|
*/
|
||||||
export function buildBackendUrl(
|
export function buildBackendUrl(path: string, params?: Record<string, BackendUrlParam>): string {
|
||||||
path: string,
|
|
||||||
params?: Record<string, BackendUrlParam>
|
|
||||||
): string {
|
|
||||||
const backendPath = path.startsWith("/") ? path : `/${path}`;
|
const backendPath = path.startsWith("/") ? path : `/${path}`;
|
||||||
const queryParams = new URLSearchParams();
|
const queryParams = new URLSearchParams();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,5 +91,7 @@ export function getSupportedExtensionsSet(
|
||||||
acceptedFileTypes?: Record<string, string[]>,
|
acceptedFileTypes?: Record<string, string[]>,
|
||||||
etlService?: string
|
etlService?: string
|
||||||
): Set<string> {
|
): Set<string> {
|
||||||
return new Set(getSupportedExtensions(acceptedFileTypes, etlService).map((ext) => ext.toLowerCase()));
|
return new Set(
|
||||||
|
getSupportedExtensions(acceptedFileTypes, etlService).map((ext) => ext.toLowerCase())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue