Skip to content

Commit

Permalink
Ms2 copy/edit shared process with artifacts (#392)
Browse files Browse the repository at this point in the history
* initial configuration prisma

* add: basic CRUD for user & process

* adjusted schema

* itr 1 user fs --to--> user db

* squashed migrations

* delete workspace -> delete all related to workspace

* itr 1: environments.ts fs -> environments.ts db

* itr 1: membership.ts fs -> db

* changed user.guest -> user.isGuest

* update: organization -> isOrganization

* itr1: role , roleMapping fs -> db

* itr1: folder fs -> db

* schema update

* fix: folder not optional

* update: renamed attributed to follow convention

* itr1: process fs -> db

* remove: old migrations

* updated: added await at necessary locs

* model update: workspace -> space

* attribute name adjusted

* add async await at necess. pos

* adjusted auth to use db

* convert returned bigInt into numbers

* minor fixes

* schema adjustments

* add : contact num field

* prettier fix

* fix: build error

* fix: type errors

* migrated: systemAdmin func -> db

* fix: after merge errors

* add: filemanager for GCP bucket and fs

* add: JSDoc

* fix: build error

* fix: build error

* update: schema

* minor changes

* adjusted schema

* fix: added await to async fun

* fix: build error after merge

* turn off feature flag

* turn off flag

* remove unused

* fix: after merge build error

* impl: useFileManager hook

* .

* update: image upload func using useFileMangager hook

* delete: test page

* added save filepath in DB

* turn off feature flag

* make owner optional in Space Model to allow user guests

* added CRON job to schedule sweeper

* fix: build error after merge

* added redo event listener to modeler

* fix: build errors

* minor changes requested in review

* moved db related code to /data/db, using dynamic import with feat flag

* fix: build error

* added dtos and fixed type inference

* remove dynamic import from DTOs.ts

* useFM, for orgaLogo, process-doc page

* fix: build error

* fix: createVersion db erro

* fix: regression, added awaits, fixed roles

* addressed requested changes + schema adjusted + minor bug fixes

* remove migs

* minor improvements!

* copy/edit process inital impl

* added new dev commands

* fix: process.ts

* adjusted artefacts path

* refCounter  0 -> 1

* remove -it option

* fix: tty error

* remove -it

* adjusted commands, removed husky

* Clean up some merge changes

* Refactor workspace logo retrieval and update process artifact handling

* Adjust E2E naming

* Add aria-label to edit button

* E2E adjust share import

---------

Co-authored-by: Kai Rohwer <[email protected]>
  • Loading branch information
anishsapkota and OhKai authored Dec 9, 2024
1 parent c5242ce commit ef50588
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 117 deletions.
42 changes: 22 additions & 20 deletions src/management-system-v2/app/api/private/file-manager/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ export async function GET(request: NextRequest) {
const entityType = searchParams.get('entityType');
const environmentId = searchParams.get('environmentId') || 'unauthenticated';
const fileName = searchParams.get('fileName') || undefined;
if (!entityId || !entityType || !environmentId) {
if (
!entityId ||
!entityType ||
!environmentId ||
(entityType === EntityType.PROCESS && !fileName)
) {
return new NextResponse(null, {
status: 400,
statusText: 'entityId,entityType, environmentId and fileName required as URL search params',
statusText: 'entityId, entityType, environmentId and fileName required as URL search params',
});
}

Expand All @@ -41,26 +46,25 @@ export async function GET(request: NextRequest) {
});
}

if (environmentId === 'unauthenticated') {
// if the user is not an owner check if they have access if a share token is provided in the query data of the url
const shareToken = searchParams.get('shareToken');
if (!canAccess && shareToken) {
const key = process.env.SHARING_ENCRYPTION_SECRET!;
const {
processId: shareProcessId,
embeddedMode,
timestamp,
} = jwt.verify(shareToken, key!) as TokenPayload;

canAccess =
!embeddedMode && shareProcessId === entityId && timestamp === processMeta.shareTimestamp;
}
} else {
// if the user is not unauthenticated check if they have access to the process due to being an owner
if (environmentId !== 'unauthenticated') {
const { ability } = await getCurrentEnvironment(environmentId);

canAccess = ability.can('view', toCaslResource('Process', processMeta));
}

// if the user is not an owner check if they have access if a share token is provided in the query data of the url
const shareToken = searchParams.get('shareToken');
if (!canAccess && shareToken) {
const key = process.env.SHARING_ENCRYPTION_SECRET!;
const {
processId: shareProcessId,
embeddedMode,
timestamp,
} = jwt.verify(shareToken, key!) as TokenPayload;
canAccess =
!embeddedMode && shareProcessId === entityId && timestamp === processMeta.shareTimestamp;
}

if (!canAccess) {
return new NextResponse(null, {
status: 403,
Expand All @@ -81,7 +85,6 @@ export async function GET(request: NextRequest) {
}

const headers = new Headers();
console.log(fileType.mime);
headers.set('Content-Type', fileType.mime);
return new NextResponse(data, { status: 200, statusText: 'OK', headers });
} catch (error: any) {
Expand Down Expand Up @@ -157,7 +160,6 @@ export async function PUT(request: NextRequest) {
);

const fileType = await fileTypeFromBuffer(buffer);
console.log(fileType);
if (!fileType) {
return new NextResponse(null, {
status: 415,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
ImportsInfo,
getElementSVG,
} from './documentation-page-utils';
import { Environment } from '@/lib/data/environment-schema';

/**
* Import the Editor asynchronously since it implicitly uses browser logic which leads to errors when this file is loaded on the server
Expand All @@ -54,13 +55,15 @@ const markdownEditor: Promise<ToastEditorType> =
type BPMNSharedViewerProps = {
processData: Awaited<ReturnType<typeof getProcess>>;
isOwner: boolean;
userWorkspaces: Environment[];
defaultSettings?: SettingsOption;
availableImports: ImportsInfo;
};

const BPMNSharedViewer = ({
processData,
isOwner,
userWorkspaces,
defaultSettings,
availableImports,
}: BPMNSharedViewerProps) => {
Expand Down Expand Up @@ -223,6 +226,7 @@ const BPMNSharedViewer = ({
</Button>
{!isOwner && (
<WorkspaceSelectionModalButton
workspaces={userWorkspaces}
processData={processData}
versionInfo={versionInfo}
/>
Expand Down
9 changes: 5 additions & 4 deletions src/management-system-v2/app/shared-viewer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getDefinitionsAndProcessIdForEveryCallActivity } from '@proceed/bpmn-he

import { SettingsOption } from './settings-modal';
import { env } from '@/lib/env-vars';
import { asyncMap } from '@/lib/helpers/javascriptHelpers';

interface PageProps {
searchParams: {
Expand Down Expand Up @@ -131,11 +132,10 @@ const SharedViewer = async ({ searchParams }: PageProps) => {

const userEnvironments: Environment[] = [await getEnvironmentById(userId)];
const userOrgEnvs = await getUserOrganizationEnvironments(userId);
const orgEnvironmentsPromises = userOrgEnvs.map(async (environmentId) => {
return await getEnvironmentById(environmentId);
});

const orgEnvironments = await Promise.all(orgEnvironmentsPromises);
const orgEnvironments = await asyncMap(userOrgEnvs, (environmentId) =>
getEnvironmentById(environmentId),
);

userEnvironments.push(...orgEnvironments);

Expand Down Expand Up @@ -211,6 +211,7 @@ const SharedViewer = async ({ searchParams }: PageProps) => {
>
<BPMNSharedViewer
isOwner={isOwner}
userWorkspaces={userEnvironments}
processData={processData!}
defaultSettings={defaultSettings}
availableImports={availableImports}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
.WorkspaceSelection {
margin-bottom: 10px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;

.WorkspaceButton {
border: 1px solid black;
width: 150px;
height: 100px;
display: flex;
margin: 5px;
width: 200px;
height: 120px;
display: inline-flex; /* Ensure buttons align horizontally */
flex-direction: column;
justify-content: center;
align-items: center;
Expand Down
Loading

0 comments on commit ef50588

Please sign in to comment.