Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8565: Delete and Unpublish buttons in backoffice content edit #8566

Open
wants to merge 15 commits into
base: 1.10.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some little code refactoring
  • Loading branch information
AndreaPiovanelli authored and MatteoPiovanelli committed May 16, 2024
commit 7da93e41d85d22e84ae6662187a23221c02a7b66
31 changes: 2 additions & 29 deletions src/Orchard.Web/Core/Contents/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
@@ -355,40 +355,13 @@ public ActionResult EditAndPublishPOST(int id, string returnUrl) {
[HttpPost, ActionName("Edit")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different that the other unpublish/delete actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added delete and unpublish actions referencing specific submits to the controller. There already were unpublish and delete actions (the ones called from the lists), so I called those inside the new actions, specific to the edit form.

[Mvc.FormValueRequired("submit.Unpublish")]
public ActionResult EditUnpublishPOST(int id, string returnUrl) {
var content = _contentManager.Get(id, VersionOptions.Latest);

if (content == null)
return HttpNotFound();

if (!Services.Authorizer.Authorize(Permissions.PublishContent, content, T("Couldn't unpublish content")))
return new HttpUnauthorizedResult();

_contentManager.Unpublish(content);

Services.Notifier.Information(string.IsNullOrWhiteSpace(content.TypeDefinition.DisplayName) ? T("That content has been unpublished.") : T("That {0} has been unpublished.", content.TypeDefinition.DisplayName));

return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
return Unpublish(id, returnUrl);
}

[HttpPost, ActionName("Edit")]
[Mvc.FormValueRequired("submit.Delete")]
public ActionResult EditDeletePOST(int id, string returnUrl) {
var content = _contentManager.Get(id, VersionOptions.Latest);

if (content == null)
return HttpNotFound();

if (!Services.Authorizer.Authorize(Permissions.DeleteContent, content, T("You do not have permission to delete content.")))
return new HttpUnauthorizedResult();

if (content != null) {
_contentManager.Remove(content);
Services.Notifier.Information(string.IsNullOrWhiteSpace(content.TypeDefinition.DisplayName)
? T("That content has been removed.")
: T("That {0} has been removed.", content.TypeDefinition.DisplayName));
}

return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
return Remove(id, returnUrl);
}

private ActionResult EditPOST(int id, string returnUrl, Action<ContentItem> conditionallyPublish) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use remove and sort usings and auto-formatting.

Original file line number Diff line number Diff line change
@@ -141,21 +141,7 @@ public ActionResult EditPOST(int blogId, int postId, string returnUrl) {
[HttpPost, ActionName("Edit")]
[Mvc.FormValueRequired("submit.Delete")]
public ActionResult EditDeletePOST (int blogId, int postId, string returnUrl) {
var blog = _blogService.Get(blogId, VersionOptions.Latest);
if (blog == null)
return HttpNotFound();

var post = _blogPostService.Get(postId, VersionOptions.Latest);
if (post == null)
return HttpNotFound();

if (!Services.Authorizer.Authorize(Permissions.DeleteBlogPost, post, T("Couldn't delete blog post")))
return new HttpUnauthorizedResult();

_blogPostService.Delete(post);
Services.Notifier.Information(T("Blog post was successfully deleted"));

return Redirect(Url.BlogForAdmin(blog.As<BlogPart>()));
return Delete(blogId, postId);
}

[HttpPost, ActionName("Edit")]
@@ -179,21 +165,7 @@ public ActionResult EditAndPublishPOST(int blogId, int postId, string returnUrl)
[HttpPost, ActionName("Edit")]
[Mvc.FormValueRequired("submit.Unpublish")]
public ActionResult EditUnpublishPOST(int blogId, int postId, string returnUrl) {
var blog = _blogService.Get(blogId, VersionOptions.Latest);
if (blog == null)
return HttpNotFound();

var post = _blogPostService.Get(postId, VersionOptions.Latest);
if (post == null)
return HttpNotFound();

if (!Services.Authorizer.Authorize(Permissions.PublishBlogPost, post, T("Couldn't unpublish blog post")))
return new HttpUnauthorizedResult();

_blogPostService.Unpublish(post);
Services.Notifier.Information(T("Blog post successfully unpublished."));

return Redirect(Url.BlogForAdmin(blog.As<BlogPart>()));
return Unpublish(blogId, postId);
}

public ActionResult EditPOST(int blogId, int postId, string returnUrl, Action<ContentItem> conditionallyPublish) {