mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
* Pass relations through schema, instead of individual reads * Fetch field transforms upfront * Fix length check * List if user has app access or not in accountability * Load permissions up front, merge app access minimal permissions * Show app access required permissions in permissions overview * Show system minimal permissions in permissions detail * Fix app access check in authenticate for jwt use * Fix minimal permissions for presets * Remove /permissions/me in favor of root use w/ permissions * Fix logical nested OR in an AND * Use root permissions endpoint with filter instead of /me * Allow filter query on /permissions * Add system minimal app access permissions into result of /permissions * Remove stray console log * Remove stray console.dir * Set current role as role for minimal permissions * Fix no-permissions state for user detail * Add filter items function that allows altering existing result set
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import getLocalType from './get-local-type';
|
|
import { Column } from '@directus/schema/dist/types/column';
|
|
import { SchemaOverview } from '../types';
|
|
|
|
export default function getDefaultValue(column: SchemaOverview['tables'][string]['columns'][string] | Column) {
|
|
const type = getLocalType(column);
|
|
|
|
let defaultValue = column.default_value || null;
|
|
if (defaultValue === null) return null;
|
|
if (defaultValue === 'null') return null;
|
|
if (defaultValue === 'NULL') return null;
|
|
|
|
// Check if the default is wrapped in an extra pair of quotes, this happens in SQLite
|
|
if (
|
|
typeof defaultValue === 'string' &&
|
|
((defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`)) ||
|
|
(defaultValue.startsWith(`"`) && defaultValue.endsWith(`"`)))
|
|
) {
|
|
defaultValue = defaultValue.slice(1, -1);
|
|
}
|
|
|
|
switch (type) {
|
|
case 'bigInteger':
|
|
case 'integer':
|
|
case 'decimal':
|
|
case 'float':
|
|
return Number(defaultValue);
|
|
case 'boolean':
|
|
return castToBoolean(defaultValue);
|
|
default:
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
function castToBoolean(value: any): boolean {
|
|
if (typeof value === 'boolean') return value;
|
|
|
|
if (value === 0 || value === '0') return false;
|
|
if (value === 1 || value === '1') return true;
|
|
|
|
if (value === 'false' || value === false) return false;
|
|
if (value === 'true' || value === true) return true;
|
|
|
|
return Boolean(value);
|
|
}
|