Merge branch 'main' into aggregation

This commit is contained in:
rijkvanzanten
2021-06-30 10:12:16 -04:00
29 changed files with 252 additions and 615 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "directus",
"version": "9.0.0-rc.81",
"version": "9.0.0-rc.83",
"license": "GPL-3.0-only",
"homepage": "https://github.com/directus/directus#readme",
"description": "Directus is a real-time API and App dashboard for managing SQL database content.",
@@ -60,7 +60,7 @@
"prepublishOnly": "npm run build"
},
"engines": {
"node": ">=12.0.0"
"node": ">=12.20.0"
},
"files": [
"dist",
@@ -69,15 +69,15 @@
"example.env"
],
"dependencies": {
"@directus/app": "9.0.0-rc.81",
"@directus/drive": "9.0.0-rc.81",
"@directus/drive-azure": "9.0.0-rc.81",
"@directus/drive-gcs": "9.0.0-rc.81",
"@directus/drive-s3": "9.0.0-rc.81",
"@directus/format-title": "9.0.0-rc.81",
"@directus/schema": "9.0.0-rc.81",
"@directus/shared": "9.0.0-rc.81",
"@directus/specs": "9.0.0-rc.81",
"@directus/app": "9.0.0-rc.83",
"@directus/drive": "9.0.0-rc.83",
"@directus/drive-azure": "9.0.0-rc.83",
"@directus/drive-gcs": "9.0.0-rc.83",
"@directus/drive-s3": "9.0.0-rc.83",
"@directus/format-title": "9.0.0-rc.83",
"@directus/schema": "9.0.0-rc.83",
"@directus/shared": "9.0.0-rc.83",
"@directus/specs": "9.0.0-rc.83",
"@godaddy/terminus": "^4.9.0",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-virtual": "^2.0.3",
@@ -187,7 +187,7 @@
"@types/uuid-validate": "0.0.1",
"copyfiles": "2.4.1",
"cross-env": "7.0.3",
"ts-node-dev": "1.1.6",
"ts-node-dev": "1.1.7",
"typescript": "4.3.4"
}
}

View File

@@ -6,8 +6,9 @@ import logger from '../../../logger';
import { getSchema } from '../../../utils/get-schema';
import { RolesService, UsersService, SettingsService } from '../../../services';
import getDatabase, { isInstalled, hasDatabaseConnection } from '../../../database';
import { SchemaOverview } from '../../../types';
export default async function bootstrap(): Promise<void> {
export default async function bootstrap({ skipAdminInit }: { skipAdminInit?: boolean }): Promise<void> {
logger.info('Initializing bootstrap...');
if ((await isDatabaseAvailable()) === false) {
@@ -27,29 +28,12 @@ export default async function bootstrap(): Promise<void> {
const schema = await getSchema();
logger.info('Setting up first admin role...');
const rolesService = new RolesService({ schema });
const role = await rolesService.createOne({ name: 'Admin', admin_access: true });
logger.info('Adding first admin user...');
const usersService = new UsersService({ schema });
let adminEmail = env.ADMIN_EMAIL;
if (!adminEmail) {
logger.info('No admin email provided. Defaulting to "admin@example.com"');
adminEmail = 'admin@example.com';
if (skipAdminInit == null) {
await createDefaultAdmin(schema);
} else {
logger.info('Skipping creation of default Admin user and role...');
}
let adminPassword = env.ADMIN_PASSWORD;
if (!adminPassword) {
adminPassword = nanoid(12);
logger.info(`No admin password provided. Defaulting to "${adminPassword}"`);
}
await usersService.createOne({ email: adminEmail, password: adminPassword, role });
if (env.PROJECT_NAME && typeof env.PROJECT_NAME === 'string' && env.PROJECT_NAME.length > 0) {
const settingsService = new SettingsService({ schema });
await settingsService.upsertSingleton({ project_name: env.PROJECT_NAME });
@@ -78,3 +62,28 @@ async function isDatabaseAvailable() {
return false;
}
async function createDefaultAdmin(schema: SchemaOverview) {
logger.info('Setting up first admin role...');
const rolesService = new RolesService({ schema });
const role = await rolesService.createOne({ name: 'Admin', admin_access: true });
logger.info('Adding first admin user...');
const usersService = new UsersService({ schema });
let adminEmail = env.ADMIN_EMAIL;
if (!adminEmail) {
logger.info('No admin email provided. Defaulting to "admin@example.com"');
adminEmail = 'admin@example.com';
}
let adminPassword = env.ADMIN_PASSWORD;
if (!adminPassword) {
adminPassword = nanoid(12);
logger.info(`No admin password provided. Defaulting to "${adminPassword}"`);
}
await usersService.createOne({ email: adminEmail, password: adminPassword, role });
}

View File

@@ -63,7 +63,11 @@ rolesCommand
program.command('count <collection>').description('Count the amount of items in a given collection').action(count);
program.command('bootstrap').description('Initialize or update the database').action(bootstrap);
program
.command('bootstrap')
.description('Initialize or update the database')
.option('--skipAdminInit', 'Skips the creation of the default Admin Role and User')
.action(bootstrap);
program.parseAsync(process.argv).catch((err) => {
console.error(err);

View File

@@ -190,7 +190,7 @@ export class FilesService extends ItemsService {
* Delete multiple files
*/
async deleteMany(keys: PrimaryKey[], opts?: MutationOptions): Promise<PrimaryKey[]> {
const files = await super.readMany(keys, { fields: ['id', 'storage'] });
const files = await super.readMany(keys, { fields: ['id', 'storage'], limit: -1 });
if (!files) {
throw new ForbiddenException();