Exemplo n.º 1
0
        public async Task <ActionResult <IEnumerable <IFileStoreEntry> > > GetFolders(string path)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageMedia))
            {
                return(Forbid());
            }

            if (string.IsNullOrEmpty(path))
            {
                path = "";
            }

            if (await _mediaFileStore.GetDirectoryInfoAsync(path) == null)
            {
                return(NotFound());
            }

            // create default folders if not exist
            if (await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia) &&
                await _mediaFileStore.GetDirectoryInfoAsync(_mediaFileStore.Combine(_mediaOptions.AssetsUsersFolder, _userAssetFolderNameProvider.GetUserAssetFolderName(User))) == null)
            {
                await _mediaFileStore.TryCreateDirectoryAsync(_mediaFileStore.Combine(_mediaOptions.AssetsUsersFolder, _userAssetFolderNameProvider.GetUserAssetFolderName(User)));
            }

            var allowed = _mediaFileStore.GetDirectoryContentAsync(path)
                          .WhereAwait(async e => e.IsDirectory && await _authorizationService.AuthorizeAsync(User, Permissions.ManageMediaFolder, (object)e.Path));

            return(Ok(await allowed.ToListAsync()));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateFolder(
            string path, string name,
            [FromServices] IAuthorizationService authorizationService)
        {
            if (!await authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia))
            {
                return(Unauthorized());
            }

            if (string.IsNullOrEmpty(path))
            {
                path = "";
            }

            var newPath = _mediaFileStore.Combine(path, name);

            var mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(newPath);

            if (mediaFolder != null && !mediaFolder.IsDirectory)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, "Cannot create folder because a file already exists with the same name"));
            }

            await _mediaFileStore.TryCreateDirectoryAsync(newPath);

            mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(newPath);

            return(Json(mediaFolder));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <IFileStoreEntry> > CreateFolder(
            string path, string name,
            [FromServices] IAuthorizationService authorizationService)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = "";
            }

            name = _mediaNameNormalizerService.NormalizeFolderName(name);

            if (_invalidFolderNameCharacters.Any(invalidChar => name.Contains(invalidChar)))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, S["Cannot create folder because the folder name contains invalid characters"]));
            }

            var newPath = _mediaFileStore.Combine(path, name);

            if (!await authorizationService.AuthorizeAsync(User, Permissions.ManageMedia) ||
                !await authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)newPath))
            {
                return(Forbid());
            }

            var mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(newPath);

            if (mediaFolder != null)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, S["Cannot create folder because a folder already exists with the same name"]));
            }

            var existingFile = await _mediaFileStore.GetFileInfoAsync(newPath);

            if (existingFile != null)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, S["Cannot create folder because a file already exists with the same name"]));
            }

            await _mediaFileStore.TryCreateDirectoryAsync(newPath);

            mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(newPath);

            return(new ObjectResult(mediaFolder));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <IFileStoreEntry> > CreateFolder(
            string path, string name,
            [FromServices] IAuthorizationService authorizationService)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = "";
            }

            var newPath = _mediaFileStore.Combine(path, name);

            if (!await authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia) ||
                !await authorizationService.AuthorizeAsync(User, Permissions.ManageAttachedMediaFieldsFolder, (object)newPath))
            {
                return(Unauthorized());
            }

            var mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(newPath);

            if (mediaFolder != null)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, T["Cannot create folder because a folder already exists with the same name"]));
            }

            var existingFile = await _mediaFileStore.GetFileInfoAsync(newPath);

            if (existingFile != null)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, T["Cannot create folder because a file already exists with the same name"]));
            }

            await _mediaFileStore.TryCreateDirectoryAsync(newPath);

            mediaFolder = await _mediaFileStore.GetDirectoryInfoAsync(newPath);

            return(new ObjectResult(mediaFolder));
        }
        private async Task EnsureGlobalDirectoriesAsync()
        {
            await _fileStore.TryCreateDirectoryAsync(MediaFieldsFolder);

            await _fileStore.TryCreateDirectoryAsync(MediaFieldsTempSubFolder);
        }