fix new orgs always broken on naming convention

This commit is contained in:
timothycarambat
2023-12-19 14:05:32 -08:00
parent 25d18aa44e
commit 6ec72e42f1
2 changed files with 349 additions and 503 deletions
+6 -12
View File
@@ -16,27 +16,21 @@ const Organization = {
organization: null,
message: "No Organization name provided.",
};
var slug = slugify(orgName, { lower: true });
const validNameRegex = /^[a-zA-Z0-9]+$/;
// Validate orgName against the regular expression
if (!validNameRegex.test(orgName)) {
return {
organization: null,
message: "Organization name contains invalid characters. Only alphanumeric characters are allowed.",
};
}
// If the new name contains bad characters
// replace them with spaces and continue creation.
const newOrgName = orgName.replace(/[:\.,<>@]/, " ");
var slug = slugify(newOrgName, { lower: true });
const existingBySlug = await this.get({ slug });
if (!!existingBySlug) {
const slugSeed = Math.floor(10000000 + Math.random() * 90000000);
slug = slugify(`${orgName}-${slugSeed}`, { lower: true });
slug = slugify(`${newOrgName}-${slugSeed}`, { lower: true });
}
const organization = await prisma.organizations.create({
data: {
name: orgName,
name: newOrgName,
slug,
uuid: this.makeKey(),
},
+343 -491
View File
@@ -1,468 +1,4 @@
{
"_prisma_migrations": {
"slug": "_prisma_migrations",
"table": {
"name": "_prisma_migrations",
"pk": "id",
"verbose": "_prisma_migrations"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "varchar(36)",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "checksum",
"verbose": "checksum",
"control": {
"text": true
},
"type": "varchar(64)",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "finished_at",
"verbose": "finished_at",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": true,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "migration_name",
"verbose": "migration_name",
"control": {
"text": true
},
"type": "varchar(255)",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "logs",
"verbose": "logs",
"control": {
"text": true
},
"type": "text",
"allowNull": true,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "rolled_back_at",
"verbose": "rolled_back_at",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": true,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "started_at",
"verbose": "started_at",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "now()",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "applied_steps_count",
"verbose": "applied_steps_count",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": "0",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"system_settings": {
"slug": "system_settings",
"table": {
"name": "system_settings",
"pk": "id",
"verbose": "system_settings"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "label",
"verbose": "label",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "value",
"verbose": "value",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "lastUpdatedAt",
"verbose": "lastUpdatedAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"users": {
"slug": "users",
"table": {
"name": "users",
"pk": "id",
"verbose": "users"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "email",
"verbose": "email",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "password",
"verbose": "password",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "role",
"verbose": "role",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": "'default'::text",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "lastUpdatedAt",
"verbose": "lastUpdatedAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"organization_users": {
"slug": "organization_users",
"table": {
"name": "organization_users",
"pk": "id",
"verbose": "organization_users"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "user_id",
"verbose": "user_id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "organization_id",
"verbose": "organization_id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "lastUpdatedAt",
"verbose": "lastUpdatedAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"organizations": {
"slug": "organizations",
"table": {
@@ -795,6 +331,154 @@
"readonly": false
}
},
"organization_workspaces": {
"slug": "organization_workspaces",
"table": {
"name": "organization_workspaces",
"pk": "id",
"verbose": "organization_workspaces"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "name",
"verbose": "name",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "slug",
"verbose": "slug",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "uuid",
"verbose": "uuid",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "fname",
"verbose": "fname",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "organization_id",
"verbose": "organization_id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "lastUpdatedAt",
"verbose": "lastUpdatedAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"workspace_documents": {
"slug": "workspace_documents",
"table": {
@@ -927,6 +611,122 @@
"readonly": false
}
},
"users": {
"slug": "users",
"table": {
"name": "users",
"pk": "id",
"verbose": "users"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "email",
"verbose": "email",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "password",
"verbose": "password",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "role",
"verbose": "role",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": "'default'::text",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "lastUpdatedAt",
"verbose": "lastUpdatedAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"document_vectors": {
"slug": "document_vectors",
"table": {
@@ -1239,12 +1039,12 @@
"readonly": false
}
},
"organization_workspaces": {
"slug": "organization_workspaces",
"system_settings": {
"slug": "system_settings",
"table": {
"name": "organization_workspaces",
"name": "system_settings",
"pk": "id",
"verbose": "organization_workspaces"
"verbose": "system_settings"
},
"columns": [
{
@@ -1264,8 +1064,8 @@
}
},
{
"name": "name",
"verbose": "name",
"name": "label",
"verbose": "label",
"control": {
"text": true
},
@@ -1280,8 +1080,8 @@
}
},
{
"name": "slug",
"verbose": "slug",
"name": "value",
"verbose": "value",
"control": {
"text": true
},
@@ -1296,12 +1096,80 @@
}
},
{
"name": "uuid",
"verbose": "uuid",
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "text",
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "lastUpdatedAt",
"verbose": "lastUpdatedAt",
"control": {
"text": true
},
"type": "timestamp",
"allowNull": false,
"defaultValue": "CURRENT_TIMESTAMP",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
},
"organization_users": {
"slug": "organization_users",
"table": {
"name": "organization_users",
"pk": "id",
"verbose": "organization_users"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "user_id",
"verbose": "user_id",
"control": {
"text": true
},
"type": "integer",
"allowNull": false,
"defaultValue": null,
"listview": {
@@ -1358,22 +1226,6 @@
"editview": {
"show": true
}
},
{
"name": "fname",
"verbose": "fname",
"control": {
"text": true
},
"type": "text",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {