forked from tsai/budibase
25 changed files with 354 additions and 34 deletions
@ -1,7 +0,0 @@ |
|||
// EMAIL_SMTP_CREATED = "email:smtp:created",
|
|||
// AUTH_SSO_CREATED = "auth:sso:created",
|
|||
// AUTH_SSO_ACTIVATED = "auth:sso:activated",
|
|||
// AUTH_SSO_DEACTIVATED = "auth:sso:deactivated",
|
|||
// ORG_NAME_UPDATED = "org:info:name:updated",
|
|||
// ORG_LOGO_UPDATED = "org:info:logo:updated",
|
|||
// ORG_PLATFORM_URL_UPDATED = "org:platformurl:updated",
|
|||
@ -0,0 +1,63 @@ |
|||
import { events, db } from "@budibase/backend-core" |
|||
import { |
|||
Config, |
|||
isSMTPConfig, |
|||
isGoogleConfig, |
|||
isOIDCConfig, |
|||
isSettingsConfig, |
|||
} from "@budibase/types" |
|||
import env from "./../../../../environment" |
|||
|
|||
const getConfigs = async (globalDb: any): Promise<Config[]> => { |
|||
const response = await globalDb.allDocs( |
|||
db.getConfigParams( |
|||
{}, |
|||
{ |
|||
include_docs: true, |
|||
} |
|||
) |
|||
) |
|||
return response.rows.map((row: any) => row.doc) |
|||
} |
|||
|
|||
export const backfill = async (globalDb: any) => { |
|||
const configs = await getConfigs(globalDb) |
|||
|
|||
for (const config of configs) { |
|||
if (isSMTPConfig(config)) { |
|||
events.email.SMTPCreated(config) |
|||
} |
|||
if (isGoogleConfig(config)) { |
|||
events.auth.SSOCreated("google") |
|||
if (config.config.activated) { |
|||
events.auth.SSOActivated("google") |
|||
} |
|||
} |
|||
if (isOIDCConfig(config)) { |
|||
events.auth.SSOCreated("oidc") |
|||
if (config.config.configs[0].activated) { |
|||
events.auth.SSOActivated("oidc") |
|||
} |
|||
} |
|||
if (isSettingsConfig(config)) { |
|||
const company = config.config.company |
|||
if (company && company !== "Budibase") { |
|||
events.org.nameUpdated() |
|||
} |
|||
|
|||
const logoUrl = config.config.logoUrl |
|||
if (logoUrl) { |
|||
events.org.logoUpdated() |
|||
} |
|||
|
|||
const platformUrl = config.config.platformUrl |
|||
if ( |
|||
platformUrl && |
|||
platformUrl !== "http://localhost:10000" && |
|||
env.SELF_HOSTED |
|||
) { |
|||
events.org.platformURLUpdated() |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,3 +0,0 @@ |
|||
// USER_CREATED = "user:created",
|
|||
// USER_PERMISSION_ADMIN_ASSIGNED = "user:admin:assigned",
|
|||
// USER_PERMISSION_BUILDER_ASSIGNED = "user:builder:assigned",
|
|||
@ -0,0 +1,38 @@ |
|||
import { events, db } from "@budibase/backend-core" |
|||
import { User } from "@budibase/types" |
|||
|
|||
// manually define user doc params - normally server doesn't read users from the db
|
|||
const getUserParams = (props: any) => { |
|||
return db.getDocParams(db.DocumentTypes.USER, null, props) |
|||
} |
|||
|
|||
const getUsers = async (globalDb: any): Promise<User[]> => { |
|||
const response = await globalDb.allDocs( |
|||
getUserParams({ |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
return response.rows.map((row: any) => row.doc) |
|||
} |
|||
|
|||
export const backfill = async (globalDb: any) => { |
|||
const users = await getUsers(globalDb) |
|||
|
|||
for (const user of users) { |
|||
events.user.created(user) |
|||
|
|||
if (user.admin?.global) { |
|||
events.user.permissionAdminAssigned(user) |
|||
} |
|||
|
|||
if (user.builder?.global) { |
|||
events.user.permissionBuilderAssigned(user) |
|||
} |
|||
|
|||
if (user.roles) { |
|||
for (const [appId, role] of Object.entries(user.roles)) { |
|||
events.role.assigned(user, role) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
// Mimic configs test configuration from worker, creation configs directly in database
|
|||
|
|||
import * as structures from "./structures" |
|||
import { db } from "@budibase/backend-core" |
|||
import { Config } from "@budibase/types" |
|||
|
|||
export const saveSettingsConfig = async (globalDb: any) => { |
|||
const config = structures.settings() |
|||
await saveConfig(config, globalDb) |
|||
} |
|||
|
|||
export const saveGoogleConfig = async (globalDb: any) => { |
|||
const config = structures.google() |
|||
await saveConfig(config, globalDb) |
|||
} |
|||
|
|||
export const saveOIDCConfig = async (globalDb: any) => { |
|||
const config = structures.oidc() |
|||
await saveConfig(config, globalDb) |
|||
} |
|||
|
|||
export const saveSmtpConfig = async (globalDb: any) => { |
|||
const config = structures.smtp() |
|||
await saveConfig(config, globalDb) |
|||
} |
|||
|
|||
const saveConfig = async (config: Config, globalDb: any) => { |
|||
config._id = db.generateConfigID({ type: config.type }) |
|||
await globalDb.put(config) |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
import { utils } from "@budibase/backend-core" |
|||
import { |
|||
SMTPConfig, |
|||
OIDCConfig, |
|||
GoogleConfig, |
|||
SettingsConfig, |
|||
ConfigType, |
|||
} from "@budibase/types" |
|||
|
|||
export const oidc = (conf?: OIDCConfig): OIDCConfig => { |
|||
return { |
|||
type: ConfigType.OIDC, |
|||
config: { |
|||
configs: [ |
|||
{ |
|||
configUrl: "http://someconfigurl", |
|||
clientID: "clientId", |
|||
clientSecret: "clientSecret", |
|||
logo: "Microsoft", |
|||
name: "Active Directory", |
|||
uuid: utils.newid(), |
|||
activated: true, |
|||
...conf, |
|||
}, |
|||
], |
|||
}, |
|||
} |
|||
} |
|||
|
|||
export const google = (conf?: GoogleConfig): GoogleConfig => { |
|||
return { |
|||
type: ConfigType.GOOGLE, |
|||
config: { |
|||
clientID: "clientId", |
|||
clientSecret: "clientSecret", |
|||
activated: true, |
|||
...conf, |
|||
}, |
|||
} |
|||
} |
|||
|
|||
export const smtp = (conf?: SMTPConfig): SMTPConfig => { |
|||
return { |
|||
type: ConfigType.SMTP, |
|||
config: { |
|||
port: 12345, |
|||
host: "smtptesthost.com", |
|||
from: "testfrom@test.com", |
|||
subject: "Hello!", |
|||
secure: false, |
|||
...conf, |
|||
}, |
|||
} |
|||
} |
|||
|
|||
export const settings = (conf?: SettingsConfig): SettingsConfig => { |
|||
return { |
|||
type: ConfigType.SETTINGS, |
|||
config: { |
|||
platformUrl: "http://mycustomdomain.com", |
|||
logoUrl: "http://mylogourl,com", |
|||
company: "mycompany", |
|||
...conf, |
|||
}, |
|||
} |
|||
} |
|||
@ -1,3 +1,3 @@ |
|||
import { Document } from "./document" |
|||
import { Document } from "../document" |
|||
|
|||
export interface Datasource extends Document {} |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
import { Document } from "./document" |
|||
import { Document } from "../document" |
|||
|
|||
export interface Layout extends Document {} |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
import { Document } from "./document" |
|||
import { Document } from "../document" |
|||
|
|||
export interface Role extends Document {} |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
import { Document } from "./document" |
|||
import { Document } from "../document" |
|||
|
|||
export interface Row extends Document {} |
|||
|
|||
@ -1,3 +1,3 @@ |
|||
import { Document } from "./document" |
|||
import { Document } from "../document" |
|||
|
|||
export interface Screen extends Document {} |
|||
|
|||
@ -1 +1,67 @@ |
|||
export interface SMTPConfig {} |
|||
import { Document } from "../document" |
|||
|
|||
export interface Config extends Document { |
|||
type: ConfigType |
|||
} |
|||
|
|||
export interface SMTPConfig extends Config { |
|||
config: { |
|||
port: number |
|||
host: string |
|||
from: string |
|||
subject: string |
|||
secure: boolean |
|||
} |
|||
} |
|||
|
|||
export interface SettingsConfig extends Config { |
|||
config: { |
|||
company: string |
|||
logoUrl: string |
|||
platformUrl: string |
|||
} |
|||
} |
|||
|
|||
export interface GoogleConfig extends Config { |
|||
config: { |
|||
clientID: string |
|||
clientSecret: string |
|||
activated: boolean |
|||
} |
|||
} |
|||
|
|||
export interface OIDCConfig extends Config { |
|||
config: { |
|||
configs: { |
|||
configUrl: string |
|||
clientID: string |
|||
clientSecret: string |
|||
logo: string |
|||
name: string |
|||
uuid: string |
|||
activated: boolean |
|||
}[] |
|||
} |
|||
} |
|||
|
|||
export type NestedConfig = |
|||
| SMTPConfig |
|||
| SettingsConfig |
|||
| GoogleConfig |
|||
| OIDCConfig |
|||
|
|||
export const isSettingsConfig = (config: Config): config is SettingsConfig => |
|||
config.type === ConfigType.SETTINGS |
|||
export const isSMTPConfig = (config: Config): config is SMTPConfig => |
|||
config.type === ConfigType.SMTP |
|||
export const isGoogleConfig = (config: Config): config is GoogleConfig => |
|||
config.type === ConfigType.GOOGLE |
|||
export const isOIDCConfig = (config: Config): config is OIDCConfig => |
|||
config.type === ConfigType.OIDC |
|||
|
|||
export enum ConfigType { |
|||
SETTINGS = "settings", |
|||
SMTP = "smtp", |
|||
GOOGLE = "google", |
|||
OIDC = "oidc", |
|||
} |
|||
|
|||
Loading…
Reference in new issue