mirror of
https://github.com/directus/directus.git
synced 2026-01-23 04:08:14 -05:00
Unify & translate initial role/user detail in init & bootstrap command (#10493)
* Unify initial role/user detail in init & bootstrap * translate role descriptions * translate data from system collections
This commit is contained in:
@@ -8,6 +8,7 @@ import { getSchema } from '../../../utils/get-schema';
|
||||
import { RolesService, UsersService, SettingsService } from '../../../services';
|
||||
import getDatabase, { isInstalled, validateDatabaseConnection, hasDatabaseConnection } from '../../../database';
|
||||
import { SchemaOverview } from '../../../types';
|
||||
import { defaultAdminRole, defaultAdminUser } from '../../utils/defaults';
|
||||
|
||||
export default async function bootstrap({ skipAdminInit }: { skipAdminInit?: boolean }): Promise<void> {
|
||||
logger.info('Initializing bootstrap...');
|
||||
@@ -65,7 +66,7 @@ async function waitForDatabase(database: Knex) {
|
||||
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 });
|
||||
const role = await rolesService.createOne(defaultAdminRole);
|
||||
|
||||
logger.info('Adding first admin user...');
|
||||
const usersService = new UsersService({ schema });
|
||||
@@ -84,5 +85,5 @@ async function createDefaultAdmin(schema: SchemaOverview) {
|
||||
logger.info(`No admin password provided. Defaulting to "${adminPassword}"`);
|
||||
}
|
||||
|
||||
await usersService.createOne({ email: adminEmail, password: adminPassword, role });
|
||||
await usersService.createOne({ email: adminEmail, password: adminPassword, role, ...defaultAdminUser });
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import createEnv from '../../utils/create-env';
|
||||
import { drivers, getDriverForClient } from '../../utils/drivers';
|
||||
import { databaseQuestions } from './questions';
|
||||
import { generateHash } from '../../../utils/generate-hash';
|
||||
import { defaultAdminRole, defaultAdminUser } from '../../utils/defaults';
|
||||
|
||||
export default async function init(): Promise<void> {
|
||||
const rootPath = process.cwd();
|
||||
@@ -94,20 +95,15 @@ export default async function init(): Promise<void> {
|
||||
|
||||
await db('directus_roles').insert({
|
||||
id: roleID,
|
||||
name: 'Administrator',
|
||||
icon: 'verified',
|
||||
admin_access: true,
|
||||
description: 'Initial administrative role with unrestricted App/API access',
|
||||
...defaultAdminRole,
|
||||
});
|
||||
|
||||
await db('directus_users').insert({
|
||||
id: userID,
|
||||
status: 'active',
|
||||
email: firstUser.email,
|
||||
password: firstUser.password,
|
||||
first_name: 'Admin',
|
||||
last_name: 'User',
|
||||
role: roleID,
|
||||
...defaultAdminUser,
|
||||
});
|
||||
|
||||
await db.destroy();
|
||||
|
||||
12
api/src/cli/utils/defaults.ts
Normal file
12
api/src/cli/utils/defaults.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const defaultAdminRole = {
|
||||
name: 'Administrator',
|
||||
icon: 'verified',
|
||||
admin_access: true,
|
||||
description: '$t:admin_description',
|
||||
};
|
||||
|
||||
export const defaultAdminUser = {
|
||||
status: 'active',
|
||||
first_name: 'Admin',
|
||||
last_name: 'User',
|
||||
};
|
||||
@@ -292,7 +292,10 @@ export function useItem(collection: Ref<string>, primaryKey: Ref<string | number
|
||||
}
|
||||
|
||||
function setItemValueToResponse(response: AxiosResponse) {
|
||||
if (collection.value === 'directus_collections' && response.data.data.collection?.startsWith('directus_')) {
|
||||
if (
|
||||
(collection.value.startsWith('directus_') && collection.value !== 'directus_collections') ||
|
||||
(collection.value === 'directus_collections' && response.data.data.collection?.startsWith('directus_'))
|
||||
) {
|
||||
response.data.data = translate(response.data.data);
|
||||
}
|
||||
if (isBatch.value === false) {
|
||||
|
||||
@@ -90,6 +90,7 @@ logoutReason:
|
||||
SESSION_EXPIRED: Session expired
|
||||
public_label: Public
|
||||
public_description: Controls what API data is available without authenticating.
|
||||
admin_description: Initial administrative role with unrestricted App/API access.
|
||||
not_allowed: Not Allowed
|
||||
directus_version: Directus Version
|
||||
node_version: Node Version
|
||||
|
||||
@@ -66,6 +66,7 @@ import { Header as TableHeader } from '@/components/v-table/types';
|
||||
import ValueNull from '@/views/private/components/value-null';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { unexpectedError } from '@/utils/unexpected-error';
|
||||
import { translate } from '@/utils/translate-object-values';
|
||||
|
||||
type Role = {
|
||||
id: number;
|
||||
@@ -155,7 +156,7 @@ export default defineComponent({
|
||||
},
|
||||
...response.data.data.map((role: any) => {
|
||||
return {
|
||||
...role,
|
||||
...translate(role),
|
||||
count: role.users[0]?.count.id || 0,
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user