remove unnecessary files
This commit is contained in:
parent
0db194b412
commit
7e5252e2e2
|
@ -167,7 +167,9 @@ exports.createPlatformUserView = async () => {
|
|||
const view = {
|
||||
// if using variables in a map function need to inject them before use
|
||||
map: `function(doc) {
|
||||
emit(doc._id.toLowerCase(), doc._id)
|
||||
if (doc.tenantId) {
|
||||
emit(doc._id.toLowerCase(), doc._id)
|
||||
}
|
||||
}`,
|
||||
}
|
||||
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) => {
|
||||
try {
|
||||
let response = (await db.query(`database/${viewName}`, params)).rows
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { doWithDB } from "../db"
|
||||
import { StaticDatabases, UNICODE_MAX, ViewName } from "../db/constants"
|
||||
import { StaticDatabases, ViewName } from "../db/constants"
|
||||
import { baseGlobalDBName } from "./utils"
|
||||
import {
|
||||
getTenantId,
|
||||
|
@ -8,7 +8,7 @@ import {
|
|||
getTenantIDFromAppID,
|
||||
} from "../context"
|
||||
import env from "../environment"
|
||||
import { queryGlobalView } from "../db/views"
|
||||
import { queryPlatformView } from "../db/views"
|
||||
|
||||
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
|
||||
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
|
||||
export const getTenantUser = async (identifier: string) => {
|
||||
// use the view here and allow to find anyone regardless of casing
|
||||
const lcIdentifier = identifier.toLowerCase()
|
||||
|
||||
return await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => {
|
||||
let response = await queryGlobalView(
|
||||
ViewName.PLATFORM_USERS_LOWERCASE,
|
||||
{
|
||||
startkey: lcIdentifier,
|
||||
endkey: `${lcIdentifier}${UNICODE_MAX}`,
|
||||
},
|
||||
db
|
||||
)
|
||||
if (!response) {
|
||||
response = []
|
||||
}
|
||||
return response
|
||||
// Use lowercase to ensure email login is case insensitive
|
||||
const response = await queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
|
||||
keys: [identifier.toLowerCase()],
|
||||
include_docs: true,
|
||||
})
|
||||
return response
|
||||
}
|
||||
|
||||
export const isUserInAppTenant = (appId: string, user: any) => {
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -9,7 +9,6 @@ import * as appUrls from "./functions/appUrls"
|
|||
import * as developerQuota from "./functions/developerQuota"
|
||||
import * as publishedAppsQuota from "./functions/publishedAppsQuota"
|
||||
import * as backfill from "./functions/backfill"
|
||||
import * as platformUsersEmailViewCasing from "./functions/platformUserEmailViewCasing"
|
||||
|
||||
/**
|
||||
* Populate the migration function and additional configuration from
|
||||
|
@ -85,13 +84,6 @@ export const buildMigrations = () => {
|
|||
})
|
||||
break
|
||||
}
|
||||
case MigrationName.PLATFORM_USERS_EMAIL_CASING: {
|
||||
serverMigrations.push({
|
||||
...definition,
|
||||
fn: platformUsersEmailViewCasing.run,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue