Example #1
0
        public async Task <ActionResult> CreatePartPOST(CreatePartViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Forbid());
            }

            viewModel.Name = viewModel.Name ?? String.Empty;

            if (String.IsNullOrWhiteSpace(viewModel.Name))
            {
                ModelState.AddModelError("Name", S["The Technical Name can't be empty."]);
            }

            if (_contentDefinitionService.LoadParts(false).Any(p => String.Equals(p.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("Name", S["A part with the same Technical Name already exists."]);
            }

            if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter())
            {
                ModelState.AddModelError("Name", S["The Technical Name must start with a letter."]);
            }

            if (!String.Equals(viewModel.Name, viewModel.Name.ToSafeName(), StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError("Name", S["The Technical Name contains invalid characters."]);
            }

            if (viewModel.Name.IsReservedContentName())
            {
                ModelState.AddModelError("Name", S["The Technical Name is reserved for internal use."]);
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var partViewModel = _contentDefinitionService.AddPart(viewModel);

            if (partViewModel == null)
            {
                await _notifier.InformationAsync(H["The content part could not be created."]);

                return(View(viewModel));
            }

            await _notifier.SuccessAsync(H["The \"{0}\" content part has been created.", partViewModel.Name]);

            return(RedirectToAction(nameof(EditPart), new { id = partViewModel.Name }));
        }
Example #2
0
        public async Task <IActionResult> Purge()
        {
            if (!await _authorizationService.AuthorizeAsync(User, MediaCachePermissions.ManageAssetCache))
            {
                return(Forbid());
            }

            if (_mediaFileStoreCache == null)
            {
                await _notifier.ErrorAsync(H["The asset cache feature is enabled, but a remote media store feature is not enabled, or not configured with appsettings.json."]);

                RedirectToAction(nameof(Index));
            }

            var hasErrors = await _mediaFileStoreCache.PurgeAsync();

            if (hasErrors)
            {
                await _notifier.ErrorAsync(H["Asset cache purged, with errors."]);
            }
            else
            {
                await _notifier.InformationAsync(H["Asset cache purged."]);
            }

            return(RedirectToAction(nameof(Index)));
        }
Example #3
0
        public async Task <IActionResult> Clone(string contentItemId, string returnUrl)
        {
            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await IsAuthorizedAsync(CommonPermissions.CloneContent, contentItem))
            {
                return(Forbid());
            }

            try
            {
                await _contentManager.CloneAsync(contentItem);
            }
            catch (InvalidOperationException)
            {
                await _notifier.WarningAsync(H["Could not clone the content item."]);

                return(Url.IsLocalUrl(returnUrl) ? (IActionResult)this.LocalRedirect(returnUrl, true) : RedirectToAction(nameof(List)));
            }

            await _notifier.InformationAsync(H["Successfully cloned. The clone was saved as a draft."]);

            return(Url.IsLocalUrl(returnUrl) ? (IActionResult)this.LocalRedirect(returnUrl, true) : RedirectToAction(nameof(List)));
        }
Example #4
0
        public async Task <IActionResult> Localize(string contentItemId, string targetCulture)
        {
            // Invariant culture name is empty so a null value is bound.
            targetCulture = targetCulture ?? "";

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.LocalizeContent, contentItem))
            {
                return(Forbid());
            }

            var checkContentItem = await _contentManager.NewAsync(contentItem.ContentType);

            // Set the current user as the owner to check for ownership permissions on creation
            checkContentItem.Owner = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, checkContentItem))
            {
                return(Forbid());
            }

            var part = contentItem.As <LocalizationPart>();

            if (part == null)
            {
                return(NotFound());
            }

            var alreadyLocalizedContent = await _contentLocalizationManager.GetContentItemAsync(part.LocalizationSet, targetCulture);

            if (alreadyLocalizedContent != null)
            {
                await _notifier.WarningAsync(H["A localization already exists for '{0}'.", targetCulture]);

                return(RedirectToAction("Edit", "Admin", new { area = "OrchardCore.Contents", contentItemId = contentItemId }));
            }

            try
            {
                var newContent = await _contentLocalizationManager.LocalizeAsync(contentItem, targetCulture);

                await _notifier.InformationAsync(H["Localized version of the content created successfully."]);

                return(RedirectToAction("Edit", "Admin", new { area = "OrchardCore.Contents", contentItemId = newContent.ContentItemId }));
            }
            catch (InvalidOperationException)
            {
                await _notifier.WarningAsync(H["Could not create localized version of the content item."]);

                return(RedirectToAction("Edit", "Admin", new { area = "OrchardCore.Contents", contentItemId = contentItem.ContentItemId }));
            }
        }
        public async Task <IActionResult> PurgeAll()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var hasErrors = await _sitemapCacheProvider.PurgeAllAsync();

            if (hasErrors)
            {
                await _notifier.ErrorAsync(H["Sitemap cache purged, with errors."]);
            }
            else
            {
                await _notifier.InformationAsync(H["Sitemap cache purged."]);
            }

            return(RedirectToAction(nameof(List)));
        }