Files
plane/apps/web/core/local-db/utils/query-sanitizer.ts.ts
chuan 8ebde8aa05
Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Initial commit: Plane
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
2025-11-07 00:00:52 +08:00

39 lines
1.4 KiB
TypeScript

// plane constants
import { EUserPermissions } from "@plane/constants";
import type { TIssueParams } from "@plane/types";
// root store
import { rootStore } from "@/lib/store-context";
export const sanitizeWorkItemQueries = (
workspaceSlug: string,
projectId: string,
queries: Partial<Record<TIssueParams, string | boolean>> | undefined
): Partial<Record<TIssueParams, string | boolean>> | undefined => {
// Get current project details and user id and role for the project
const currentProject = rootStore.projectRoot.project.getProjectById(projectId);
const currentUserId = rootStore.user.data?.id;
const currentUserRole = rootStore.user.permission.getProjectRoleByWorkspaceSlugAndProjectId(workspaceSlug, projectId);
// Only apply this restriction for guests when guest_view_all_features is disabled
if (
currentUserId &&
currentUserRole === EUserPermissions.GUEST &&
currentProject?.guest_view_all_features === false
) {
// Sanitize the created_by filter if it doesn't exist or if it exists and includes the current user id
const existingCreatedByFilter = queries?.created_by;
const shouldApplyFilter =
!existingCreatedByFilter ||
(typeof existingCreatedByFilter === "string" && existingCreatedByFilter.includes(currentUserId));
if (shouldApplyFilter) {
queries = {
...queries,
created_by: currentUserId,
};
}
}
return queries;
};