Skip to content

Commit

Permalink
Fix last reference to pre-OOP workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 1, 2024
1 parent 3dd3423 commit e3094e9
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 32 deletions.
14 changes: 13 additions & 1 deletion source/SIL.AppBuilder.Portal/common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion source/SIL.AppBuilder.Portal/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bullmq": "^5.12.2"
},
"devDependencies": {
"prisma": "^5.18.0"
"prisma": "^5.18.0",
"xstate": "^5.18.2"
}
}
6 changes: 6 additions & 0 deletions source/SIL.AppBuilder.Portal/common/public/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ export enum ProductTransitionType {
CancelWorkflow,
ProjectAccess
}

export enum WorkflowType {
Default = 1,
Rebuild,
Republish
}
56 changes: 52 additions & 4 deletions source/SIL.AppBuilder.Portal/common/public/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export enum ActionType {
* - If the flow has `RequiredAdminLevel.High` it will include extra state to represent the organizational approval process
* - If the flow has `RequiredAdminLevel.Low` it will not include those states, but there are still some states that require action from an OrgAdmin to complete certain actions
* - If the flow has `RequiredAdminLevel.None` none of the states or actions for the workflow instance will require an OrgAdmin.
*
*
* Any state or transition can have a list of specified `RequiredAdminLevel`s. What this means is that those states and transitions will be included in a workflow instance ONLY when the instance's `RequiredAdminLevel` is in the state's or transition's list.
*
*
* If a state or transition does not specify any `RequiredAdminLevel` it will be included (provided it passes other conditions not dependent on `RequiredAdminLevel`).
*/
*/
export enum RequiredAdminLevel {
/** NoAdmin/OwnerAdmin */
None = 0,
Expand Down Expand Up @@ -101,6 +101,54 @@ export type WorkflowInput = {
productType: ProductType;
};

// TODO: Just put this info directly in the database
export function workflowInputFromDBProductType(workflowDefinitionId: number): WorkflowInput {
switch (workflowDefinitionId) {
case 1: // sil_android_google_play
return {
adminLevel: RequiredAdminLevel.High,
productType: ProductType.Android_GooglePlay
};
case 4: // sil_android_s3
return {
adminLevel: RequiredAdminLevel.High,
productType: ProductType.Android_S3
};
case 6: // la_android_google_play
return {
adminLevel: RequiredAdminLevel.Low,
productType: ProductType.Android_GooglePlay
};
case 7: // na_android_google_play
return {
adminLevel: RequiredAdminLevel.None,
productType: ProductType.Android_GooglePlay
};
case 8: // na_android_s3
return {
adminLevel: RequiredAdminLevel.None,
productType: ProductType.Android_S3
};
case 9: // pwa_cloud
case 11: // html_cloud
return {
adminLevel: RequiredAdminLevel.None,
productType: ProductType.Web
};
case 13: // asset_package
return {
adminLevel: RequiredAdminLevel.None,
productType: ProductType.AssetPackage
};
default: // would be some other workflow type presumably
console.log(`Unrecognized workflow definition: ${workflowDefinitionId}! Returning configuration for sil_android_google_play.`);
return {
adminLevel: RequiredAdminLevel.High,
productType: ProductType.Android_GooglePlay
};
}
}

/** Used for filtering based on AdminLevel and/or ProductType */
export type MetaFilter = {
level?: RequiredAdminLevel[];
Expand Down Expand Up @@ -135,4 +183,4 @@ export type Snapshot = {
value: string;
context: WorkflowContext;
input: WorkflowInput;
};
};
15 changes: 2 additions & 13 deletions source/SIL.AppBuilder.Portal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions source/SIL.AppBuilder.Portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"@auth/sveltekit": "^1.4.2",
"@bull-board/express": "^5.21.3",
"express": "^4.19.2",
"sil.appbuilder.portal.common": "file:common",
"xstate": "^5.18.1"
"sil.appbuilder.portal.common": "file:common"
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { idSchema } from '$lib/valibot';
import { error } from '@sveltejs/kit';
import { DatabaseWrites, prisma } from 'sil.appbuilder.portal.common';
import { RoleId } from 'sil.appbuilder.portal.common/prisma';
import { RoleId, WorkflowType } from 'sil.appbuilder.portal.common/prisma';
import { fail, superValidate } from 'sveltekit-superforms';
import { valibot } from 'sveltekit-superforms/adapters';
import * as v from 'valibot';
import type { Actions, PageServerLoad } from './$types';
import { verifyCanViewAndEdit } from './common';
import { NoAdminS3 } from 'sil.appbuilder.portal.common';
import { createActor } from 'xstate';
import { Workflow } from 'sil.appbuilder.portal.common';
import { workflowInputFromDBProductType } from 'sil.appbuilder.portal.common/workflow';

const deleteReviewerSchema = v.object({
id: idSchema
Expand Down Expand Up @@ -176,7 +176,7 @@ export const actions = {
const form = await superValidate(event.request, valibot(addProductSchema));
if (!form.valid) return fail(400, { form, ok: false });
// Appears that CanUpdate is not used TODO
const res = await DatabaseWrites.products.create({
const productId = await DatabaseWrites.products.create({
ProjectId: parseInt(event.params.id),
ProductDefinitionId: form.data.productDefinitionId,
StoreId: form.data.storeId,
Expand All @@ -186,13 +186,25 @@ export const actions = {
WorkflowPublishId: form.data.workflowPublishId
});

if (typeof res === 'string') {
const tmpActor = createActor(NoAdminS3, {
input: {
productId: res
if (typeof productId === 'string') {
const flow = (await prisma.productDefinitions.findUnique({
where: {
Id: form.data.productDefinitionId
},
select: {
Workflow: {
select: {
// TODO: RequiredAdminLevel and ProductType should be directly in the database instead of calling a helper function
Id: true,
Type: true
}
}
}
});
tmpActor.start();
}))?.Workflow;

if (flow?.Type === WorkflowType.Default) {
Workflow.create(productId, workflowInputFromDBProductType(flow.Id));
}
}

return { form, ok: true };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { PageServerLoad, Actions } from './$types';
import { prisma, Workflow } from 'sil.appbuilder.portal.common';
import { createActor } from 'xstate';
import { redirect } from '@sveltejs/kit';
import { fail, superValidate } from 'sveltekit-superforms';
import { valibot } from 'sveltekit-superforms/adapters';
Expand Down

0 comments on commit e3094e9

Please sign in to comment.