Browse Source

Merge pull request #5033 from djmaze/fix_uploads_for_public_base

Allow uploads for public base url users with editor role
pull/4956/merge
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
2e0bbcd846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      packages/nocodb/src/lib/meta/api/attachmentApis.ts

7
packages/nocodb/src/lib/meta/api/attachmentApis.ts

@ -17,14 +17,17 @@ import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
const isUploadAllowed = async (req: Request, _res: Response, next: any) => { const isUploadAllowed = async (req: Request, _res: Response, next: any) => {
if (!req['user']?.id) { if (!req['user']?.id) {
if (!req['user']?.isPublicBase) {
NcError.unauthorized('Unauthorized'); NcError.unauthorized('Unauthorized');
} }
}
try { try {
// check user is super admin or creator // check user is super admin or creator
if ( if (
req['user'].roles?.includes(OrgUserRoles.SUPER_ADMIN) || req['user'].roles?.includes(OrgUserRoles.SUPER_ADMIN) ||
req['user'].roles?.includes(OrgUserRoles.CREATOR) || req['user'].roles?.includes(OrgUserRoles.CREATOR) ||
req['user'].roles?.includes(ProjectRoles.EDITOR) ||
// if viewer then check at-least one project have editor or higher role // if viewer then check at-least one project have editor or higher role
// todo: cache // todo: cache
!!(await Noco.ncMeta !!(await Noco.ncMeta
@ -54,7 +57,7 @@ export async function upload(req: Request, res: Response) {
(req as any).files?.map(async (file) => { (req as any).files?.map(async (file) => {
const fileName = `${nanoid(18)}${path.extname(file.originalname)}`; const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
let url = await storageAdapter.fileCreate( const url = await storageAdapter.fileCreate(
slash(path.join(destPath, fileName)), slash(path.join(destPath, fileName)),
file file
); );
@ -98,7 +101,7 @@ export async function uploadViaURL(req: Request, res: Response) {
const fileName = `${nanoid(18)}${_fileName || url.split('/').pop()}`; const fileName = `${nanoid(18)}${_fileName || url.split('/').pop()}`;
let attachmentUrl = await (storageAdapter as any).fileCreateByUrl( const attachmentUrl = await (storageAdapter as any).fileCreateByUrl(
slash(path.join(destPath, fileName)), slash(path.join(destPath, fileName)),
url url
); );

Loading…
Cancel
Save