remove unnecessary files

This commit is contained in:
Martin McKeaveney 2022-09-02 16:07:30 +01:00
parent 0db194b412
commit 7e5252e2e2
4 changed files with 10 additions and 72 deletions

View File

@ -167,7 +167,9 @@ exports.createPlatformUserView = async () => {
const view = { const view = {
// if using variables in a map function need to inject them before use // if using variables in a map function need to inject them before use
map: `function(doc) { map: `function(doc) {
if (doc.tenantId) {
emit(doc._id.toLowerCase(), doc._id) emit(doc._id.toLowerCase(), doc._id)
}
}`, }`,
} }
designDoc.views = { designDoc.views = {
@ -178,39 +180,6 @@ exports.createPlatformUserView = async () => {
}) })
} }
exports.queryGlobalView = async (viewName, params, db = null) => {
const CreateFuncByName = {
[ViewName.USER_BY_EMAIL]: exports.createNewUserEmailView,
[ViewName.BY_API_KEY]: exports.createApiKeyView,
[ViewName.USER_BY_BUILDERS]: exports.createUserBuildersView,
[ViewName.USER_BY_APP]: exports.createUserAppView,
}
// can pass DB in if working with something specific
if (!db) {
db = getGlobalDB()
}
try {
let response = (await db.query(`database/${viewName}`, params)).rows
response = response.map(resp =>
params.include_docs ? resp.doc : resp.value
)
if (params.arrayResponse) {
return response
} else {
return response.length <= 1 ? response[0] : response
}
} catch (err) {
if (err != null && err.name === "not_found") {
const createFunc = CreateFuncByName[viewName]
await removeDeprecated(db, viewName)
await createFunc(db)
return exports.queryView(viewName, params, db, CreateFuncByName)
} else {
throw err
}
}
}
exports.queryView = async (viewName, params, db, CreateFuncByName) => { exports.queryView = async (viewName, params, db, CreateFuncByName) => {
try { try {
let response = (await db.query(`database/${viewName}`, params)).rows let response = (await db.query(`database/${viewName}`, params)).rows

View File

@ -1,5 +1,5 @@
import { doWithDB } from "../db" import { doWithDB } from "../db"
import { StaticDatabases, UNICODE_MAX, ViewName } from "../db/constants" import { StaticDatabases, ViewName } from "../db/constants"
import { baseGlobalDBName } from "./utils" import { baseGlobalDBName } from "./utils"
import { import {
getTenantId, getTenantId,
@ -8,7 +8,7 @@ import {
getTenantIDFromAppID, getTenantIDFromAppID,
} from "../context" } from "../context"
import env from "../environment" import env from "../environment"
import { queryGlobalView } from "../db/views" import { queryPlatformView } from "../db/views"
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
@ -119,22 +119,12 @@ export const lookupTenantId = async (userId: string) => {
// lookup, could be email or userId, either will return a doc // lookup, could be email or userId, either will return a doc
export const getTenantUser = async (identifier: string) => { export const getTenantUser = async (identifier: string) => {
// use the view here and allow to find anyone regardless of casing // use the view here and allow to find anyone regardless of casing
const lcIdentifier = identifier.toLowerCase() // Use lowercase to ensure email login is case insensitive
const response = await queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
return await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => { keys: [identifier.toLowerCase()],
let response = await queryGlobalView( include_docs: true,
ViewName.PLATFORM_USERS_LOWERCASE,
{
startkey: lcIdentifier,
endkey: `${lcIdentifier}${UNICODE_MAX}`,
},
db
)
if (!response) {
response = []
}
return response
}) })
return response
} }
export const isUserInAppTenant = (appId: string, user: any) => { export const isUserInAppTenant = (appId: string, user: any) => {

View File

@ -1,13 +0,0 @@
const { createPlatformUserView } = require("@budibase/backend-core/db")
/**
* Date:
* September 2022
*
* Description:
* Create a view in platform DB with lowercase emails for all users.
*/
export const run = async () => {
await createPlatformUserView()
}

View File

@ -9,7 +9,6 @@ import * as appUrls from "./functions/appUrls"
import * as developerQuota from "./functions/developerQuota" import * as developerQuota from "./functions/developerQuota"
import * as publishedAppsQuota from "./functions/publishedAppsQuota" import * as publishedAppsQuota from "./functions/publishedAppsQuota"
import * as backfill from "./functions/backfill" import * as backfill from "./functions/backfill"
import * as platformUsersEmailViewCasing from "./functions/platformUserEmailViewCasing"
/** /**
* Populate the migration function and additional configuration from * Populate the migration function and additional configuration from
@ -85,13 +84,6 @@ export const buildMigrations = () => {
}) })
break break
} }
case MigrationName.PLATFORM_USERS_EMAIL_CASING: {
serverMigrations.push({
...definition,
fn: platformUsersEmailViewCasing.run,
})
break
}
} }
} }