Fix TS errors

This commit is contained in:
rijkvanzanten
2021-04-29 16:18:09 -04:00
parent 3c0e41e881
commit ba98f23d3d
4 changed files with 14 additions and 29 deletions

View File

@@ -54,17 +54,7 @@ export class AuthorizationService {
const uniqueCollectionsRequestedCount = uniq(collectionsRequested.map(({ collection }) => collection)).length;
if (uniqueCollectionsRequestedCount !== permissionsForCollections.length) {
// Find the first collection that doesn't have permissions configured
const { collection, field } = collectionsRequested.find(
({ collection }) =>
permissionsForCollections.find((permission) => permission.collection === collection) === undefined
)!;
if (field) {
throw new ForbiddenException(`You don't have permission to access the "${field}" field.`);
} else {
throw new ForbiddenException(`You don't have permission to access the "${collection}" collection.`);
}
throw new ForbiddenException();
}
validateFields(ast);
@@ -119,7 +109,7 @@ export class AuthorizationService {
const fieldKey = childNode.name;
if (allowedFields.includes(fieldKey) === false) {
throw new ForbiddenException(`You don't have permission to access the "${fieldKey}" field.`);
throw new ForbiddenException();
}
}
}
@@ -151,7 +141,7 @@ export class AuthorizationService {
if (ast.query.filter._and.length === 0) delete ast.query.filter._and;
if (permissions.limit && ast.query.limit && ast.query.limit > permissions.limit) {
throw new ForbiddenException(`You can't read more than ${permissions.limit} items at a time.`);
throw new ForbiddenException();
}
// Default to the permissions limit if limit hasn't been set
@@ -207,9 +197,7 @@ export class AuthorizationService {
const invalidKeys = keysInData.filter((fieldKey) => allowedFields.includes(fieldKey) === false);
if (invalidKeys.length > 0) {
throw new ForbiddenException(
`You're not allowed to ${action} field "${invalidKeys[0]}" in collection "${collection}".`
);
throw new ForbiddenException();
}
}
}

View File

@@ -36,7 +36,7 @@ export class CollectionsService {
*/
async createOne(payload: Partial<Collection> & { collection: string }, opts?: MutationOptions): Promise<string> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
if (!payload.collection) throw new InvalidPayloadException(`"collection" is required`);
@@ -218,7 +218,7 @@ export class CollectionsService {
for (const collectionKey of collectionKeys) {
if (collectionsYouHavePermissionToRead.includes(collectionKey) === false) {
throw new ForbiddenException(`You don't have access to the "${collectionKey}" collection.`);
throw new ForbiddenException();
}
}
}
@@ -256,7 +256,7 @@ export class CollectionsService {
*/
async updateOne(collectionKey: string, data: Partial<Collection>, opts?: MutationOptions): Promise<string> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
const collectionItemsService = new ItemsService('directus_collections', {
@@ -291,7 +291,7 @@ export class CollectionsService {
*/
async updateMany(collectionKeys: string[], data: Partial<Collection>): Promise<string[]> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
await this.knex.transaction(async (trx) => {
@@ -315,7 +315,7 @@ export class CollectionsService {
*/
async deleteOne(collectionKey: string, opts?: MutationOptions): Promise<string> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
const collectionItemsService = new ItemsService('directus_collections', {
@@ -379,7 +379,7 @@ export class CollectionsService {
*/
async deleteMany(collectionKeys: string[], opts?: MutationOptions): Promise<string[]> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
await this.knex.transaction(async (trx) => {

View File

@@ -207,7 +207,7 @@ export class FieldsService {
table?: Knex.CreateTableBuilder // allows collection creation to
): Promise<void> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
// Check if field already exists, either as a column, or as a row in directus_fields
@@ -248,7 +248,7 @@ export class FieldsService {
async updateField(collection: string, field: RawField): Promise<string> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action');
throw new ForbiddenException();
}
if (field.schema) {
@@ -291,7 +291,7 @@ export class FieldsService {
/** @todo save accountability */
async deleteField(collection: string, field: string): Promise<void> {
if (this.accountability && this.accountability.admin !== true) {
throw new ForbiddenException('Only admins can perform this action.');
throw new ForbiddenException();
}
await emitter.emitAsync(`fields.delete.before`, {

View File

@@ -455,10 +455,7 @@ export class PayloadService {
.first());
if (exists === false) {
throw new ForbiddenException(undefined, {
item: record,
collection: relation.many_collection,
});
throw new ForbiddenException();
}
record = {