From f9f490b44036178b67c4299143e9b4f10be520d3 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Wed, 20 Mar 2024 16:51:24 +0100 Subject: [PATCH 01/22] fix(server): allow standard users to batch invite to server (#2150) * fix(server): allow standard users to batch invite to server * added max 10 invite batch limit * minor change --- .../assets/serverinvites/typedefs/serverInvites.graphql | 2 +- packages/server/modules/core/graph/resolvers/projects.ts | 9 +++++++++ .../serverinvites/graph/resolvers/serverInvites.ts | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/server/assets/serverinvites/typedefs/serverInvites.graphql b/packages/server/assets/serverinvites/typedefs/serverInvites.graphql index 8029295f0e..0b807cc2c1 100644 --- a/packages/server/assets/serverinvites/typedefs/serverInvites.graphql +++ b/packages/server/assets/serverinvites/typedefs/serverInvites.graphql @@ -14,7 +14,7 @@ extend type Mutation { @hasScope(scope: "users:invite") serverInviteBatchCreate(input: [ServerInviteCreateInput!]!): Boolean! - @hasServerRole(role: SERVER_ADMIN) + @hasServerRole(role: SERVER_USER) @hasScope(scope: "users:invite") streamInviteBatchCreate(input: [StreamInviteCreateInput!]!): Boolean! diff --git a/packages/server/modules/core/graph/resolvers/projects.ts b/packages/server/modules/core/graph/resolvers/projects.ts index 763a869b5b..db7c54baf1 100644 --- a/packages/server/modules/core/graph/resolvers/projects.ts +++ b/packages/server/modules/core/graph/resolvers/projects.ts @@ -25,6 +25,7 @@ import { } from '@/modules/core/services/streams/management' import { createOnboardingStream } from '@/modules/core/services/streams/onboarding' import { removeStreamCollaborator } from '@/modules/core/services/streams/streamAccessService' +import { InviteCreateValidationError } from '@/modules/serverinvites/errors' import { cancelStreamInvite } from '@/modules/serverinvites/services/inviteProcessingService' import { getPendingStreamCollaborators, @@ -145,6 +146,14 @@ export = { Roles.Stream.Owner, ctx.resourceAccessRules ) + + const inviteCount = args.input.length + if (inviteCount > 10 && ctx.role !== Roles.Server.Admin) { + throw new InviteCreateValidationError( + 'Maximum 10 invites can be sent at once by non admins' + ) + } + const inputBatches = chunk(args.input, 10) for (const batch of inputBatches) { await Promise.all( diff --git a/packages/server/modules/serverinvites/graph/resolvers/serverInvites.ts b/packages/server/modules/serverinvites/graph/resolvers/serverInvites.ts index fc8e3e0b17..be5b1af36c 100644 --- a/packages/server/modules/serverinvites/graph/resolvers/serverInvites.ts +++ b/packages/server/modules/serverinvites/graph/resolvers/serverInvites.ts @@ -86,6 +86,13 @@ export = { async serverInviteBatchCreate(_parent, args, context) { const { input: paramsArray } = args + const inviteCount = paramsArray.length + if (inviteCount > 10 && context.role !== Roles.Server.Admin) { + throw new InviteCreateValidationError( + 'Maximum 10 invites can be sent at once by non admins' + ) + } + // Batch calls so that we don't kill the server const batches = chunk(paramsArray, 50) for (const paramsBatchArray of batches) { From ffb7ed1a7cae91deee37fbd5546965e69d53d3b8 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Thu, 21 Mar 2024 11:49:31 +0200 Subject: [PATCH 02/22] enabling dev to skip migrations --- .../migrations/20240305120620_automate.ts | 9 ++-- .../20240304143445_rename_tables.ts | 3 ++ packages/server/modules/core/dbSchema.ts | 51 +++++++++++-------- .../modules/shared/helpers/envHelper.ts | 8 +++ 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/packages/server/modules/automate/migrations/20240305120620_automate.ts b/packages/server/modules/automate/migrations/20240305120620_automate.ts index cd3ec19d07..13cc53b702 100644 --- a/packages/server/modules/automate/migrations/20240305120620_automate.ts +++ b/packages/server/modules/automate/migrations/20240305120620_automate.ts @@ -6,6 +6,9 @@ const REVISION_FUNCTIONS_TABLE_NAME = 'automation_revision_functions' const AUTOMATION_RUNS_TABLE_NAME = 'automation_runs' export async function up(knex: Knex): Promise { + // TODO: Remove, this is a temporary shortcut to avoid messing up the db schema which makes it difficult to jump to different branches + if (process.env.SKIP_AUTOMATE_MIGRATION_DEV) return + await knex.schema.createTable(AUTOMATIONS_TABLE_NAME, (table) => { table.text('id').primary({ constraintName: 'automation_id_pk' }) table.text('name').notNullable() @@ -77,8 +80,8 @@ export async function up(knex: Knex): Promise { } export async function down(knex: Knex): Promise { - await knex.schema.dropTable(AUTOMATIONS_TABLE_NAME) - await knex.schema.dropTable(REVISIONS_TABLE_NAME) - await knex.schema.dropTable(REVISION_FUNCTIONS_TABLE_NAME) await knex.schema.dropTable(AUTOMATION_RUNS_TABLE_NAME) + await knex.schema.dropTable(REVISION_FUNCTIONS_TABLE_NAME) + await knex.schema.dropTable(REVISIONS_TABLE_NAME) + await knex.schema.dropTable(AUTOMATIONS_TABLE_NAME) } diff --git a/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts b/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts index 01790cb347..5ac5bce10d 100644 --- a/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts +++ b/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts @@ -13,6 +13,9 @@ const AUTOMATION_FUNCTION_RUNS_RESULT_VERSIONS_TABLE_NAME_NEW = 'beta_automation_function_runs_result_versions' export async function up(knex: Knex): Promise { + // TODO: Remove, this is a temporary shortcut to avoid messing up the db schema which makes it difficult to jump to different branches + if (process.env.SKIP_AUTOMATE_MIGRATION_DEV) return + await knex.schema.renameTable(AUTOMATIONS_TABLE_NAME_OLD, AUTOMATIONS_TABLE_NAME_NEW) await knex.schema.renameTable( AUTOMATION_RUNS_TABLE_NAME_OLD, diff --git a/packages/server/modules/core/dbSchema.ts b/packages/server/modules/core/dbSchema.ts index 49ecf2cc43..4d6b66cfd4 100644 --- a/packages/server/modules/core/dbSchema.ts +++ b/packages/server/modules/core/dbSchema.ts @@ -4,6 +4,7 @@ import knex from '@/db/knex' import { BaseMetaRecord } from '@/modules/core/helpers/meta' import { Knex } from 'knex' import { reduce } from 'lodash' +import { skipAutomateMigrations } from '@/modules/shared/helpers/envHelper' type BaseInnerSchemaConfig = { /** @@ -461,28 +462,36 @@ export const FileUploads = buildTableHelper('file_uploads', [ 'convertedCommitId' ]) -export const Automations = buildTableHelper('beta_automations', [ - 'automationId', - 'automationRevisionId', - 'automationName', - 'projectId', - 'modelId', - 'createdAt', - 'updatedAt', - 'webhookId' -]) +export const Automations = buildTableHelper( + skipAutomateMigrations() ? 'automations' : 'beta_automations', + [ + 'automationId', + 'automationRevisionId', + 'automationName', + 'projectId', + 'modelId', + 'createdAt', + 'updatedAt', + 'webhookId' + ] +) -export const AutomationRuns = buildTableHelper('beta_automation_runs', [ - 'automationId', - 'automationRevisionId', - 'automationRunId', - 'versionId', - 'createdAt', - 'updatedAt' -]) +export const AutomationRuns = buildTableHelper( + skipAutomateMigrations() ? 'automation_runs' : 'beta_automation_runs', + [ + 'automationId', + 'automationRevisionId', + 'automationRunId', + 'versionId', + 'createdAt', + 'updatedAt' + ] +) export const AutomationFunctionRuns = buildTableHelper( - 'beta_automation_function_runs', + skipAutomateMigrations() + ? 'automation_function_runs' + : 'beta_automation_function_runs', [ 'automationRunId', 'functionId', @@ -497,7 +506,9 @@ export const AutomationFunctionRuns = buildTableHelper( ) export const AutomationFunctionRunsResultVersions = buildTableHelper( - 'beta_automation_function_runs_result_versions', + skipAutomateMigrations() + ? 'automation_function_runs_result_version' + : 'beta_automation_function_runs_result_versions', ['automationRunId', 'functionId', 'resultVersionId'] ) diff --git a/packages/server/modules/shared/helpers/envHelper.ts b/packages/server/modules/shared/helpers/envHelper.ts index 24940c84d0..8cfb98efec 100644 --- a/packages/server/modules/shared/helpers/envHelper.ts +++ b/packages/server/modules/shared/helpers/envHelper.ts @@ -274,6 +274,14 @@ export function delayGraphqlResponsesBy() { if (!isDevEnv()) return 0 return getIntFromEnv('DELAY_GQL_RESPONSES_BY', '0') } + +/** + * TODO: Remove, this is a temporary shortcut to avoid messing up the db schema which makes it difficult to jump to different branches + */ +export function skipAutomateMigrations() { + return getBooleanFromEnv('SKIP_AUTOMATE_MIGRATION_DEV') +} + export const { ENABLE_AUTOMATE_MODULE } = parseEnv(process.env, { ENABLE_AUTOMATE_MODULE: z.boolean().default(false) }) From 32a5a36ae35971675393f2b6080c175c89077180 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Thu, 21 Mar 2024 11:18:00 +0100 Subject: [PATCH 03/22] feat(fe2): project tabs synced w/ URL + various hydration mismatch fixes (#2149) * WIP project tabs + resolved various hydration mismatches * hydration mismatch workaround * getting rid if old pages * fixed page tab underlines * minor cleanup * support trailing slash * a few viewer bugfixes --- .../components/common/model/Select.vue | 4 + .../CreateEditApplicationDialog.vue | 4 + .../developer-settings/CreateTokenDialog.vue | 4 + .../components/form/select/ProjectRoles.vue | 4 + .../components/form/select/Projects.vue | 4 + .../components/form/select/ServerRoles.vue | 4 + .../components/form/select/Users.vue | 4 + .../components/header/NavNotifications.vue | 3 +- .../frontend-2/components/header/NavShare.vue | 3 +- .../components/header/NavUserMenu.vue | 3 +- .../project/CommentPermissionsSelect.vue | 4 + .../components/project/VisibilitySelect.vue | 4 + .../project/page/discussions/Header.vue | 3 + .../project/page/discussions/Tab.vue | 10 +- .../project/page/models/Actions.vue | 2 + .../components/project/page/models/Header.vue | 4 + .../components/project/page/models/Tab.vue | 10 +- .../project/page/team/PermissionSelect.vue | 4 + .../webhooks-page/CreateOrEditDialog.vue | 4 + .../components/viewer/explode/Menu.vue | 72 +++--- .../viewer/measurements/UnitSelect.vue | 5 + .../frontend-2/components/viewer/sun/Menu.vue | 170 ++++++------- .../components/viewer/views/Menu.vue | 3 +- .../lib/common/generated/gql/gql.ts | 16 +- .../lib/common/generated/gql/graphql.ts | 8 +- .../frontend-2/lib/common/helpers/route.ts | 12 +- .../lib/projects/graphql/queries.ts | 4 + .../lib/viewer/composables/setup.ts | 9 +- .../pages/projects/[id]/discussions.vue | 59 ----- .../frontend-2/pages/projects/[id]/index.vue | 90 ++++++- .../pages/projects/[id]/index/discussions.vue | 3 + .../pages/projects/[id]/index/index.vue | 5 + .../pages/projects/[id]/models/index.vue | 80 ------ .../src/components/form/select/Badges.vue | 4 + .../src/components/form/select/Base.vue | 16 +- .../src/components/form/select/SourceApps.vue | 8 + .../src/components/layout/Menu.vue | 3 +- .../src/components/layout/PageTabs.stories.ts | 79 +++++- .../src/components/layout/PageTabs.vue | 49 ++-- .../src/components/user/AvatarEditable.vue | 3 + .../ui-components/src/composables/testing.ts | 35 +++ .../src/helpers/layout/components.ts | 2 +- yarn.lock | 227 +++--------------- 43 files changed, 503 insertions(+), 541 deletions(-) delete mode 100644 packages/frontend-2/pages/projects/[id]/discussions.vue create mode 100644 packages/frontend-2/pages/projects/[id]/index/discussions.vue create mode 100644 packages/frontend-2/pages/projects/[id]/index/index.vue delete mode 100644 packages/frontend-2/pages/projects/[id]/models/index.vue create mode 100644 packages/ui-components/src/composables/testing.ts diff --git a/packages/frontend-2/components/common/model/Select.vue b/packages/frontend-2/components/common/model/Select.vue index 32d2ebdd28..3b8795e2a3 100644 --- a/packages/frontend-2/components/common/model/Select.vue +++ b/packages/frontend-2/components/common/model/Select.vue @@ -8,6 +8,8 @@ :multiple="multiple" :disabled="!items.length" :allow-unset="allowUnset" + :label-id="labelId" + :button-id="buttonId" by="id" >