π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: move send record email feature to EE
claude[bot]84a053c5bab8
diff --git a/packages/nc-gui/components/dlg/SendRecordEmail.vue b/packages/nc-gui/components/dlg/SendRecordEmail.vueindex cbbf547700..53a52791bd 100644--- a/packages/nc-gui/components/dlg/SendRecordEmail.vue+++ b/packages/nc-gui/components/dlg/SendRecordEmail.vue@@ -1,262 +1,3 @@-<script lang="ts" setup>-import type { TableType, ViewType } from 'nocodb-sdk'--const props = defineProps<{- modelValue: boolean- meta: TableType- view?: ViewType- rowId: string-}>()--const emit = defineEmits(['update:modelValue'])--const { api } = useApi()--const { t } = useI18n()--const { activeWorkspaceId } = storeToRefs(useWorkspace())--const { activeProjectId } = storeToRefs(useBases())--const { user } = useGlobal()--const basesStore = useBases()--const { basesUser } = storeToRefs(basesStore)--const dialogShow = useVModel(props, 'modelValue', emit)--const isLoading = ref(false)--const selectedUserIds = ref<Set<string>>(new Set())--const customMessage = ref('')--const sendCopyToSelf = ref(false)--const searchQuery = ref('')--const baseUsers = computed(() => {- if (!activeProjectId.value) return []- return basesUser.value.get(activeProjectId.value) || []-})--const filteredUsers = computed(() => {- if (!searchQuery.value) return baseUsers.value-- const query = searchQuery.value.toLowerCase()- return baseUsers.value.filter((u) => u.email?.toLowerCase().includes(query) || u.display_name?.toLowerCase().includes(query))-})--const selectedUsers = computed(() => {- return baseUsers.value.filter((u) => selectedUserIds.value.has(u.id))-})--const isSendButtonDisabled = computed(() => {- return selectedUserIds.value.size === 0-})--const MESSAGE_MAX_LENGTH = 1000--const customSubject = ref('')--watch(dialogShow, (newVal) => {- if (newVal) {- selectedUserIds.value = new Set()- customMessage.value = ''- sendCopyToSelf.value = false- searchQuery.value = ''- const displayName = extractUserDisplayNameOrEmail(user.value) || 'Someone'- customSubject.value = `${displayName} shared a record from "${props.meta.title}"`- }-})--const toggleUser = (userId: string) => {- if (selectedUserIds.value.has(userId)) {- selectedUserIds.value.delete(userId)- } else {- selectedUserIds.value.add(userId)- }- selectedUserIds.value = new Set(selectedUserIds.value)-}--const removeUser = (userId: string) => {- selectedUserIds.value.delete(userId)- selectedUserIds.value = new Set(selectedUserIds.value)-}--const sendRecord = async () => {- if (!activeWorkspaceId.value || !activeProjectId.value) return-- try {- isLoading.value = true-- const emails = selectedUsers.value.map((u) => u.email).filter(Boolean) as string[]-- if (!emails.length) {- message.error(t('msg.error.atLeastOneEmail'))- return- }-- await api.internal.postOperation(- activeWorkspaceId.value,- activeProjectId.value,- {- operation: 'sendRecordEmail',- },- {- tableId: props.meta.id,- viewId: props.view?.id,- rowId: props.rowId,- emails,- subject: customSubject.value || undefined,- message: customMessage.value || undefined,- sendCopyToSelf: sendCopyToSelf.value,- },- )-- message.success(t('msg.success.recordSentSuccessfully'))- dialogShow.value = false- } catch (e: any) {- message.error(await extractSdkResponseErrorMsg(e))- } finally {- isLoading.value = false- }-}-</script>-<template>- <NcModal- v-model:visible="dialogShow"- :show-separator="false"- size="medium"- class="nc-send-record-email-dlg"- @keydown.esc="dialogShow = false"- >- <template #header>- <div class="flex flex-col gap-1">- <span class="text-lg font-semibold text-nc-content-gray">{{ $t('activity.sendRecord') }}</span>- <span class="text-sm text-nc-content-gray-subtle">{{ $t('msg.info.shareRecordWithTeam') }}</span>- </div>- </template>-- <div class="flex flex-col gap-4">- <div class="flex flex-col gap-1">- <label class="text-nc-content-gray text-sm font-medium">{{ $t('labels.to') }}</label>-- <div class="border-1 border-nc-border-gray-medium rounded-lg overflow-hidden">- <div class="p-2.5 border-b border-nc-border-gray-medium bg-nc-bg-gray-extralight min-h-12">- <div v-if="selectedUsers.length > 0" class="flex flex-wrap gap-2">- <div- v-for="selectedUser in selectedUsers"- :key="selectedUser.id"- class="flex items-center gap-1.5 bg-white border-1 border-nc-border-gray-medium rounded-full pl-0.5 pr-1 py-0.5 shadow-xs"- >- <GeneralUserIcon :user="selectedUser" size="medium" />- <span class="text-sm text-nc-content-gray truncate max-w-32">- {{ extractUserDisplayNameOrEmail(selectedUser) }}- </span>- <NcButton type="text" size="xxsmall" class="!p-0 !w-4 !h-4 !min-w-4" @click.stop="removeUser(selectedUser.id)">- <GeneralIcon icon="close" class="w-3 h-3 text-nc-content-gray-subtle2 hover:text-nc-content-gray" />- </NcButton>- </div>- </div>- <span v-else class="text-sm text-nc-content-gray-muted">- {{ $t('labels.noRecipientsSelected') }}- </span>- </div>- <div class="p-2 border-b border-nc-border-gray-medium">- <a-input- v-model:value="searchQuery"- :placeholder="$t('placeholder.searchUsers')"- class="!rounded-lg"- :disabled="isLoading"- allow-clear- >- <template #prefix>- <GeneralIcon icon="search" class="text-nc-content-gray-muted" />- </template>- </a-input>- </div>- <div class="max-h-52 overflow-y-auto nc-scrollbar-md">- <div v-if="filteredUsers.length === 0" class="p-4 text-center text-nc-content-gray-muted text-sm">- {{ $t('labels.noUsersFound') }}- </div>- <div- v-for="baseUser in filteredUsers"- :key="baseUser.id"- class="flex items-center gap-3 px-3 py-2.5 hover:bg-nc-bg-gray-light cursor-pointer transition-colors"- @click="toggleUser(baseUser.id)"- >- <NcCheckbox :checked="selectedUserIds.has(baseUser.id)" />- <GeneralUserIcon :user="baseUser" size="medium" />- <div class="flex flex-col min-w-0 flex-1">- <span class="text-sm text-nc-content-gray font-medium truncate">- {{ extractUserDisplayNameOrEmail(baseUser) }}- </span>- <span class="text-xs text-nc-content-gray-subtle truncate">- {{ baseUser.email }}- </span>- </div>- </div>- </div>- </div>-- <span class="text-nc-content-gray-subtle2 text-xs">- {{ $t('msg.info.selectBaseMembers') }}- </span>- </div>-- <div class="flex flex-col gap-1.5">- <label class="text-nc-content-gray text-sm font-medium">{{ $t('labels.subject') }}</label>- <a-input- v-model:value="customSubject"- :placeholder="$t('placeholder.enterSubject')"- class="!rounded-lg"- :disabled="isLoading"- />- <span class="text-nc-content-gray-subtle2 text-xs">- {{ $t('msg.info.subjectLineNotification') }}- </span>- </div>-- <div class="flex flex-col gap-1.5">- <div class="flex items-center justify-between">- <label class="text-nc-content-gray text-sm font-medium">{{ $t('labels.message') }}</label>- <span class="text-xs text-nc-content-gray-subtle2"> {{ customMessage.length }}/{{ MESSAGE_MAX_LENGTH }} </span>- </div>- <a-textarea- v-model:value="customMessage"- :placeholder="$t('placeholder.addPersonalMessage')"- :rows="3"- :maxlength="MESSAGE_MAX_LENGTH"- class="!rounded-lg !text-sm"- :disabled="isLoading"- />- </div>-- <label class="flex items-center gap-2 cursor-pointer select-none">- <NcCheckbox v-model:checked="sendCopyToSelf" :disabled="isLoading" />- <span class="text-nc-content-gray text-sm">{{ $t('labels.sendCopyToMyself') }}</span>- </label>- </div>-- <div class="flex mt-6 justify-end">- <div class="flex gap-2">- <NcButton type="secondary" :disabled="isLoading" size="small" @click="dialogShow = false">- {{ $t('general.cancel') }}- </NcButton>- <NcButton- :disabled="isSendButtonDisabled || isLoading"- :loading="isLoading"- size="small"- type="primary"- class="nc-send-record-btn"- @click="sendRecord"- >- {{ $t('general.send') }}- </NcButton>- </div>- </div>- </NcModal>-</template>+ <span></span>+</template>\ No newline at end of filediff --git a/packages/nocodb/src/controllers/internal/modules/SendRecordEmail.operations.ts b/packages/nocodb/src/controllers/internal/modules/SendRecordEmail.operations.tsindex 7f5af0bc7c..7b67113abd 100644--- a/packages/nocodb/src/controllers/internal/modules/SendRecordEmail.operations.ts+++ b/packages/nocodb/src/controllers/internal/modules/SendRecordEmail.operations.ts@@ -1,264 +1,3 @@-import { Injectable } from '@nestjs/common';-import {- isSystemColumn,- UITypes,- ColumnHelper,- RelationTypes,-} from 'nocodb-sdk';-import type {- ColumnType,- LinkToAnotherRecordType,- NcContext,- NcRequest,- TableType,-} from 'nocodb-sdk';-import type { OPERATION_SCOPES } from '~/controllers/internal/operationScopes';-import type {- InternalApiModule,- InternalPOSTResponseType,-} from '~/utils/internal-type';-import { MailService } from '~/services/mail/mail.service';-import { MailEvent } from '~/interface/Mail';-import { Base, BaseUser, Model, Source } from '~/models';-import { NcError } from '~/helpers/catchError';-import { extractDisplayNameFromEmail } from '~/utils';-import { DataTableService } from '~/services/data-table.service';--interface SendRecordEmailPayload {- tableId: string;- viewId?: string;- rowId: string;- emails: string[];- subject?: string;- message?: string;- sendCopyToSelf?: boolean;-}--@Injectable()-export class SendRecordEmailOperations- implements InternalApiModule<InternalPOSTResponseType>-{- constructor(- protected readonly mailService: MailService,- protected readonly dataTableService: DataTableService,- ) {}-- operations = ['sendRecordEmail' as const];- httpMethod = 'POST' as const;-- async handle(- context: NcContext,- {- payload,- operation,- req,- }: {- workspaceId: string;- baseId: string;- operation: keyof typeof OPERATION_SCOPES;- payload: SendRecordEmailPayload;- req: NcRequest;- },- ): InternalPOSTResponseType {- switch (operation) {- case 'sendRecordEmail':- return await this.sendRecordEmail(context, payload, req);- }- }-- private async sendRecordEmail(- context: NcContext,- payload: SendRecordEmailPayload,- req: NcRequest,- ) {- const { tableId, viewId, rowId, emails, subject, message, sendCopyToSelf } =- payload;-- if (!emails || emails.length === 0) {- NcError.get(context).badRequest(- 'At least one recipient email is required',- );- }-- if (emails.length > 15) {- NcError.get(context).badRequest('Maximum 15 recipients allowed');- }-- const user = req.user;- const senderName = extractDisplayNameFromEmail(- user.email,- user.display_name,- );- const senderEmail = user.email;-- const model = await Model.get(context, tableId);- if (!model) {- NcError.get(context).tableNotFound(tableId);- }-- const base = await Base.get(context, model.base_id);-- const baseUsers = await BaseUser.getUsersList(context, {- base_id: base.id,- mode: 'full',- });-- const baseUserEmails = baseUsers.map((u) => u.email?.toLowerCase());-- const finalEmails = [...emails];- if (sendCopyToSelf && senderEmail && !finalEmails.includes(senderEmail)) {- if (baseUserEmails.includes(senderEmail.toLowerCase())) {- finalEmails.push(senderEmail);- }- }-- const invalidEmails: string[] = [];- for (const email of finalEmails) {- if (!baseUserEmails.includes(email.toLowerCase())) {- invalidEmails.push(email);- }- }-- if (invalidEmails.length > 0) {- NcError.get(context).badRequest(- `The following email(s) are not members of this base: ${invalidEmails.join(', ')}`,- );- }-- const row = await this.dataTableService.dataRead(context, {- baseId: context.base_id,- modelId: tableId,- rowId,- viewId,- query: {},- });-- if (!row) {- NcError.get(context).recordNotFound(rowId);- }-- const source = await Source.get(context, model.source_id);- const columns = await model.getColumns(context);-- const filteredColumns = columns.filter(- (col: ColumnType) =>- !isSystemColumn(col) &&- col.uidt !== UITypes.QrCode &&- col.uidt !== UITypes.Barcode,- );-- const models = await source.getModels(context);- const metas = models.reduce(- (o: Record<string, TableType>, m: TableType) => {- return Object.assign(o, { [m.id]: m });- },- {},- );-- const recordData = this.transformDataForEmail(- row,- filteredColumns,- source,- model,- metas,- );-- const result = await this.mailService.sendMail({- mailEvent: MailEvent.SEND_RECORD,- payload: {- senderName,- senderEmail,- emails: finalEmails,- model,- base,- subject,- message,- recordData,- rowId,- req,- },- });-- if (!result) {- NcError.get(context).internalServerError(- 'Failed to send email. Please check your email configuration.',- );- }-- return { msg: 'Record sent successfully' };- }-- private transformDataForEmail(- data: Record<string, any>,- columns: ColumnType[],- source: Source,- model: Model,- models: Record<string, TableType>,- ): Array<{- parsedValue?: any;- columnTitle: string;- uidt: UITypes | string;- relationType?: RelationTypes;- }> {- const transformedData: Array<{- parsedValue?: any;- columnTitle: string;- uidt: UITypes | string;- relationType?: RelationTypes;- }> = [];-- for (const col of columns) {- let serializedValue: string | undefined;-- try {- serializedValue = ColumnHelper.parsePlainCellValue(data[col.title], {- col,- isMysql: () => source.type.startsWith('mysql'),- isPg: () => source.type === 'pg',- isXcdbBase: () => !!source.isMeta(),- meta: model,- metas: models,- });-- if (col.uidt === UITypes.Attachment) {- let attachments = data[col.title] || [];- if (typeof data[col.title] === 'string') {- try {- attachments = JSON.parse(data[col.title]);- } catch {- attachments = [];- }- }- serializedValue = Array.isArray(attachments)- ? attachments- .map((attachment: any) => attachment?.title || '')- .filter(Boolean)- .join(', ')- : '';- }- } catch {- serializedValue = data[col.title]?.toString() || '';- }-- if (serializedValue !== undefined && serializedValue !== '') {- // Extract relation type for Links/LinkToAnotherRecord columns- let relationType: RelationTypes | undefined;- if (- col.uidt === UITypes.Links ||- col.uidt === UITypes.LinkToAnotherRecord- ) {- relationType = (col.colOptions as LinkToAnotherRecordType)?.type;- }-- transformedData.push({- parsedValue: serializedValue,- uidt: col.uidt,- columnTitle: col.title,- relationType,- });- }- }-- return transformedData;- }-}+// This feature has been moved to EE+// Placeholder to maintain compatibility+export class SendRecordEmailOperations {}\ No newline at end of filediff --git a/packages/nocodb/src/controllers/internal/provider.ts b/packages/nocodb/src/controllers/internal/provider.tsindex 3381cce7f6..c0febd2902 100644--- a/packages/nocodb/src/controllers/internal/provider.ts+++ b/packages/nocodb/src/controllers/internal/provider.ts@@ -7,7 +7,6 @@ import { OAuthPostOperations } from '~/controllers/internal/modules/OAuthPost.opimport { DependencyPostOperations } from '~/controllers/internal/modules/DependencyPost.operations';import { UiGetOperations } from '~/controllers/internal/modules/UiGet.operations';import { UiPostOperations } from '~/controllers/internal/modules/UiPost.operations';-import { SendRecordEmailOperations } from '~/controllers/internal/modules/SendRecordEmail.operations';import { INTERNAL_API_MODULE_PROVIDER_KEY } from '~/utils/internal-type';export const InternalApiModules = [@@ -19,7 +18,6 @@ export const InternalApiModules = [DependencyPostOperations,UiGetOperations,UiPostOperations,- SendRecordEmailOperations,];export const InternalApiModuleProvider = {diff --git a/packages/nocodb/src/services/mail/templates/index.ts b/packages/nocodb/src/services/mail/templates/index.tsindex 1d14794ff5..7854adddee 100644--- a/packages/nocodb/src/services/mail/templates/index.ts+++ b/packages/nocodb/src/services/mail/templates/index.ts@@ -6,7 +6,6 @@ import OrganizationInvite from '~/services/mail/templates/org-invite';import OrganizationRoleUpdate from '~/services/mail/templates/org-role-update';import BaseRoleUpdate from '~/services/mail/templates/base-role-update';import FormSubmission from '~/services/mail/templates/form-submission';-import SendRecord from '~/services/mail/templates/send-record';export {Welcome,@@ -17,5 +16,4 @@ export {OrganizationInvite,OrganizationRoleUpdate,FormSubmission,- SendRecord,};diff --git a/packages/nocodb/src/services/mail/templates/send-record.tsx b/packages/nocodb/src/services/mail/templates/send-record.tsxindex c79259be61..b05c0ebf67 100644--- a/packages/nocodb/src/services/mail/templates/send-record.tsx+++ b/packages/nocodb/src/services/mail/templates/send-record.tsx@@ -1,202 +1,5 @@-import {- Body,- Column,- Head,- Heading,- Hr,- Html,- Img,- Preview,- Row,- Section,- Text,-} from '@react-email/components';-import * as React from 'react';-import { RelationTypes, UITypes } from 'nocodb-sdk';-import {- ContentWrapper,- Footer,- RootWrapper,- getFieldIconUrl,-} from '~/services/mail/templates/components';-import { NC_EMAIL_ASSETS_BASE_URL } from '~/constants';--interface SendRecordTemplateProps {- senderName: string;- senderEmail: string;- tableTitle: string;- baseTitle: string;- message?: string;- recordData: Array<{- parsedValue?: any;- columnTitle: string;- uidt: UITypes | string;- relationType?: RelationTypes;- }>;- recordUrl?: string;-}--const SendRecord = ({- senderName,- senderEmail,- tableTitle,- baseTitle,- message,- recordData,- recordUrl,-}: SendRecordTemplateProps) => (- <Html>- <RootWrapper>- <Head />- <Preview>- {senderName} shared a record from {tableTitle}- </Preview>- <Body className="bg-white">- <ContentWrapper disableContainerPadding>- <Section className="p-6 mx-auto">- <Heading className="text-gray-900 text-center font-bold m-auto text-xl md:text-2xl">- {senderName} shared a record with you- </Heading>-- <Section- align="center"- className="my-6"- style={{ textAlign: 'center', lineHeight: '28px' }}- >- <table- cellPadding="0"- cellSpacing="0"- style={{ display: 'inline-block', verticalAlign: 'middle' }}- >- <tr>- <td style={{ paddingRight: '8px', verticalAlign: 'middle' }}>- <Img- src={`${NC_EMAIL_ASSETS_BASE_URL}/icons/table.png`}- alt="Table Icon"- height={24}- width={24}- className="!h-6 inline-block"- style={{ verticalAlign: 'middle' }}- />- </td>- <td style={{ verticalAlign: 'middle' }}>- <span- className="text-base font-bold mt-0.5 text-gray-900"- style={{- verticalAlign: 'middle',- display: 'inline-block',- lineHeight: '28px',- }}- >- {tableTitle}- </span>- </td>- </tr>- </table>- </Section>-- <Text className="text-center font-weight-thin text-gray-600 !my-0">- <span className="font-bold text-gray-800">{senderName}</span> (- {senderEmail}) has shared a record from- <span className="font-bold text-gray-800"> {tableTitle} </span>- in- <span className="font-bold text-gray-800"> {baseTitle}</span>.- </Text>-- {message && (- <Section className="mt-6 p-4 bg-gray-50 rounded-lg">- <Text className="text-gray-700 !my-0 italic">"{message}"</Text>- </Section>- )}- </Section>-- <Hr />-- <Section className="p-6 mx-auto">- <Text className="text-lg font-bold text-center !my-0">- Record Details- </Text>- <Section>- {recordData.map((field) => (- <Section className="mt-6" key={field.columnTitle}>- <Row>- <Column className="flex align-middle items-center">- <Img- className="align-middle"- width={16}- height={16}- src={getFieldIconUrl(field.uidt, field.relationType)}- />- <Section className="!ml-2 truncate inline-block text-[13px] !my-0 !mr-0 leading-4.5 text-gray-600 align-middle">- {field.columnTitle}- </Section>- </Column>- </Row>- <Row- className="px-4 py-2 border border-1 mt-2 border-solid rounded-lg border-gray-200"- style={{- boxShadow: `0px 0px 4px 0px rgba(0, 0, 0, 0.08)`,- }}- >- <Column>- <Text className="text-gray-800 max-w-xs truncate !my-0">- {field.parsedValue || '-'}- </Text>- </Column>- </Row>- </Section>- ))}- </Section>-- {recordUrl && (- <Section className="mt-8 text-center">- <a- href={recordUrl}- className="inline-block px-6 py-3 bg-blue-600 text-white font-semibold rounded-lg no-underline"- style={{- backgroundColor: '#3366FF',- color: '#ffffff',- padding: '12px 24px',- borderRadius: '8px',- textDecoration: 'none',- }}- >- View Record in NocoDB- </a>- </Section>- )}- </Section>- </ContentWrapper>- <Footer />- </Body>- </RootWrapper>- </Html>-);--SendRecord.PreviewProps = {- senderName: 'John Doe',- senderEmail: '[email protected]',- tableTitle: 'Contacts',- baseTitle: 'My Base',- message: "Here's the contact information you requested.",- recordData: [- {- parsedValue: 'Jane Smith',- uidt: UITypes.SingleLineText,- columnTitle: 'Name',- },- {- parsedValue: '[email protected]',- uidt: UITypes.Email,- columnTitle: 'Email',- },- {- parsedValue: '+1 234 567 8900',- uidt: UITypes.PhoneNumber,- columnTitle: 'Phone',- },- ],- recordUrl: 'https://app.nocodb.com/#/workspace/base/table?rowId=123',-};--export default SendRecord;+// This template has been moved to EE+// Placeholder to maintain compatibility+export default function SendRecord() {+ return null;+}\ No newline at end of filediff --git a/packages/nocodb/src/utils/acl.ts b/packages/nocodb/src/utils/acl.tsindex 951257a016..3d4afd51f4 100644--- a/packages/nocodb/src/utils/acl.ts+++ b/packages/nocodb/src/utils/acl.ts@@ -207,9 +207,6 @@ const permissionScopes = {'mcpCreate','mcpUpdate','mcpDelete',-- // Send record email- 'sendRecordEmail',],};@@ -297,9 +294,6 @@ const rolePermissions:// etcfetchViaUrl: true,-- // Send record email- sendRecordEmail: true,},},[ProjectRoles.COMMENTER]: {