mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add non-items system Resolvers (#4863)
* Add auth resolvers * Add password request/reset * Add up until file import * Make revisions read only * Add server resolvers * Add utils * Add schema resolvers for schema manipulation
This commit is contained in:
@@ -51,11 +51,7 @@ router.get(
|
||||
accountability: req.accountability,
|
||||
schema: req.schema,
|
||||
});
|
||||
const collectionKey = req.params.collection.includes(',')
|
||||
? req.params.collection.split(',')
|
||||
: req.params.collection;
|
||||
|
||||
const collection = await collectionsService.readByKey(collectionKey as any);
|
||||
const collection = await collectionsService.readByKey(req.params.collection);
|
||||
res.locals.payload = { data: collection || null };
|
||||
|
||||
return next();
|
||||
@@ -70,13 +66,10 @@ router.patch(
|
||||
accountability: req.accountability,
|
||||
schema: req.schema,
|
||||
});
|
||||
const collectionKey = req.params.collection.includes(',')
|
||||
? req.params.collection.split(',')
|
||||
: req.params.collection;
|
||||
await collectionsService.update(req.body, collectionKey as any);
|
||||
await collectionsService.update(req.body, req.params.collection);
|
||||
|
||||
try {
|
||||
const collection = await collectionsService.readByKey(collectionKey as any);
|
||||
const collection = await collectionsService.readByKey(req.params.collection);
|
||||
res.locals.payload = { data: collection || null };
|
||||
} catch (error) {
|
||||
if (error instanceof ForbiddenException) {
|
||||
@@ -99,11 +92,7 @@ router.delete(
|
||||
schema: req.schema,
|
||||
});
|
||||
|
||||
const collectionKey = req.params.collection.includes(',')
|
||||
? req.params.collection.split(',')
|
||||
: req.params.collection;
|
||||
|
||||
await collectionsService.delete(collectionKey as any);
|
||||
await collectionsService.delete(req.params.collection);
|
||||
|
||||
return next();
|
||||
}),
|
||||
|
||||
@@ -54,14 +54,6 @@ router.get(
|
||||
schema: req.schema,
|
||||
});
|
||||
|
||||
if (req.accountability?.admin !== true) {
|
||||
const schema = reduceSchema(req.schema, ['read']);
|
||||
|
||||
if (req.params.field in schema.collections[req.params.collection].fields === false) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
}
|
||||
|
||||
const field = await service.readOne(req.params.collection, req.params.field);
|
||||
|
||||
res.locals.payload = { data: field || null };
|
||||
|
||||
@@ -5,7 +5,6 @@ import { MetaService, FilesService } from '../services';
|
||||
import { File, PrimaryKey } from '../types';
|
||||
import formatTitle from '@directus/format-title';
|
||||
import env from '../env';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import Joi from 'joi';
|
||||
import {
|
||||
InvalidPayloadException,
|
||||
@@ -13,12 +12,10 @@ import {
|
||||
FailedValidationException,
|
||||
ServiceUnavailableException,
|
||||
} from '../exceptions';
|
||||
import url from 'url';
|
||||
import path from 'path';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import { respond } from '../middleware/respond';
|
||||
import { toArray } from '../utils/to-array';
|
||||
import logger from '../logger';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -154,40 +151,7 @@ router.post(
|
||||
schema: req.schema,
|
||||
});
|
||||
|
||||
const fileCreatePermissions = req.schema.permissions.find(
|
||||
(permission) => permission.collection === 'directus_files' && permission.action === 'create'
|
||||
);
|
||||
|
||||
if (req.accountability?.admin !== true && !fileCreatePermissions) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
let fileResponse: AxiosResponse<NodeJS.ReadableStream>;
|
||||
|
||||
try {
|
||||
fileResponse = await axios.get<NodeJS.ReadableStream>(req.body.url, {
|
||||
responseType: 'stream',
|
||||
});
|
||||
} catch (err) {
|
||||
logger.warn(`Couldn't fetch file from url "${req.body.url}"`);
|
||||
logger.warn(err);
|
||||
throw new ServiceUnavailableException(`Couldn't fetch file from url "${req.body.url}"`, {
|
||||
service: 'external-file',
|
||||
});
|
||||
}
|
||||
|
||||
const parsedURL = url.parse(fileResponse.request.res.responseUrl);
|
||||
const filename = path.basename(parsedURL.pathname as string);
|
||||
|
||||
const payload = {
|
||||
filename_download: filename,
|
||||
storage: toArray(env.STORAGE_LOCATIONS)[0],
|
||||
type: fileResponse.headers['content-type'],
|
||||
title: formatTitle(filename),
|
||||
...(req.body.data || {}),
|
||||
};
|
||||
|
||||
const primaryKey = await service.upload(fileResponse.data, payload);
|
||||
const primaryKey = await service.import(req.body.url, req.body.data);
|
||||
|
||||
try {
|
||||
const record = await service.readByKey(primaryKey, req.sanitizedQuery);
|
||||
|
||||
@@ -3,12 +3,14 @@ import { GraphQLService } from '../services';
|
||||
import { respond } from '../middleware/respond';
|
||||
import asyncHandler from '../utils/async-handler';
|
||||
import { parseGraphQL } from '../middleware/graphql';
|
||||
import cookieParser from 'cookie-parser';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.use(
|
||||
'/system',
|
||||
parseGraphQL,
|
||||
cookieParser(),
|
||||
asyncHandler(async (req, res, next) => {
|
||||
const service = new GraphQLService({
|
||||
accountability: req.accountability,
|
||||
@@ -26,6 +28,7 @@ router.use(
|
||||
router.use(
|
||||
'/',
|
||||
parseGraphQL,
|
||||
cookieParser(),
|
||||
asyncHandler(async (req, res, next) => {
|
||||
const service = new GraphQLService({
|
||||
accountability: req.accountability,
|
||||
|
||||
Reference in New Issue
Block a user