From 5610c85d2cd0017003e7201f4558428c810ee457 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 19 Sep 2018 17:05:22 +0300 Subject: [PATCH] Blogging module: more fixes --- .../Pages/Admin/Blogs/Create.cshtml.cs | 13 +++++++++++-- .../Pages/Admin/Blogs/Edit.cshtml.cs | 16 +++++++++++++--- .../Pages/Admin/Blogs/Index.cshtml.cs | 18 ++++++++++++++++-- .../Pages/Blog/Posts/Detail.cshtml | 10 +++++----- .../Pages/Blog/Posts/Edit.cshtml | 2 +- .../Pages/Blog/Posts/Edit.cshtml.cs | 16 +++++++++++++--- .../Pages/Blog/Posts/Index.cshtml | 10 +++++----- .../Pages/Blog/Posts/Index.cshtml.cs | 1 - .../Pages/Blog/Posts/New.cshtml.cs | 15 +++++++++++++-- 9 files changed, 77 insertions(+), 24 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Create.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Create.cshtml.cs index bedf09f1e7..d0c1cf48ed 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Create.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Create.cshtml.cs @@ -1,4 +1,6 @@ using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; @@ -10,18 +12,25 @@ namespace Volo.Blogging.Pages.Admin.Blogs public class CreateModel : AbpPageModel { private readonly IBlogAppService _blogAppService; + private readonly IAuthorizationService _authorization; [BindProperty] public BlogCreateModalView Blog { get; set; } = new BlogCreateModalView(); - public CreateModel(IBlogAppService blogAppService) + public CreateModel(IBlogAppService blogAppService, IAuthorizationService authorization) { _blogAppService = blogAppService; + _authorization = authorization; } - public void OnGet() + public async Task OnGetAsync() { + if (!await _authorization.IsGrantedAsync(BloggingPermissions.Blogs.Create)) + { + return Redirect("/"); + } + return Page(); } public async void OnPostAsync() diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Edit.cshtml.cs index f6034d62ff..e333840f88 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Edit.cshtml.cs @@ -2,6 +2,7 @@ using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; @@ -13,6 +14,7 @@ namespace Volo.Blogging.Pages.Admin.Blogs public class EditModel : AbpPageModel { private readonly IBlogAppService _blogAppService; + private readonly IAuthorizationService _authorization; [BindProperty(SupportsGet = true)] public Guid BlogId { get; set; } @@ -20,19 +22,27 @@ namespace Volo.Blogging.Pages.Admin.Blogs [BindProperty] public BlogEditViewModel Blog { get; set; } = new BlogEditViewModel(); - public EditModel(IBlogAppService blogAppService) + public EditModel(IBlogAppService blogAppService, IAuthorizationService authorization) { _blogAppService = blogAppService; + _authorization = authorization; } - public async Task OnGet() + public async Task OnGetAsync() { + if (!await _authorization.IsGrantedAsync(BloggingPermissions.Blogs.Update)) + { + return Redirect("/"); + } + var blog = await _blogAppService.GetAsync(BlogId); Blog = ObjectMapper.Map(blog); + + return Page(); } - public async Task OnPost() + public async Task OnPostAsync() { await _blogAppService.Update(Blog.Id, new UpdateBlogDto() { diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Index.cshtml.cs index 3ead109ebd..bb74d90652 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Admin/Blogs/Index.cshtml.cs @@ -1,13 +1,27 @@ using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; namespace Volo.Blogging.Pages.Admin.Blogs { public class IndexModel : AbpPageModel { - public async Task OnGetAsync() + private readonly IAuthorizationService _authorization; + + public IndexModel(IAuthorizationService authorization) { - + _authorization = authorization; + } + + public async Task OnGetAsync() + { + if (!await _authorization.IsGrantedAsync(BloggingPermissions.Blogs.Management)) + { + return Redirect("/"); + } + + return Page(); } } } \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 9940485aa6..43110af9ef 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -38,37 +38,37 @@ @L["Blog"] + | @if (!string.IsNullOrWhiteSpace(Model.Blog.Facebook)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Twitter)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Instagram)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Github)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.StackOverflow)) { - | diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml index 167637ee3e..148372413b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml @@ -68,4 +68,4 @@ - + diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs index 15085cab26..b35d07993d 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs @@ -2,6 +2,7 @@ using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; @@ -13,6 +14,7 @@ namespace Volo.Blogging.Pages.Blog.Posts { private readonly IPostAppService _postAppService; private readonly IBlogAppService _blogAppService; + private readonly IAuthorizationService _authorization; [BindProperty(SupportsGet = true)] public string BlogShortName { get; set; } @@ -23,20 +25,28 @@ namespace Volo.Blogging.Pages.Blog.Posts [BindProperty] public EditPostViewModel Post { get; set; } - public EditModel(IPostAppService postAppService, IBlogAppService blogAppService) + public EditModel(IPostAppService postAppService, IBlogAppService blogAppService, IAuthorizationService authorization) { _postAppService = postAppService; _blogAppService = blogAppService; + _authorization = authorization; } - public async Task OnGet() + public async Task OnGetAsync() { + if (!await _authorization.IsGrantedAsync(BloggingPermissions.Posts.Update)) + { + return Redirect("/"); + } + var postDto = await _postAppService.GetAsync(new Guid(PostId)); Post = ObjectMapper.Map(postDto); Post.Tags = String.Join(", ", postDto.Tags.Select(p=>p.Name).ToArray()); + + return Page(); } - public async Task OnPost() + public async Task OnPostAsync() { var post = new UpdatePostDto { diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml index eee2ff4498..9ad5a16a76 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml @@ -47,38 +47,38 @@ @if (await Authorization.IsGrantedAsync(BloggingPermissions.Posts.Create)) { @L["CreateANewPost"] + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Facebook)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Twitter)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Instagram)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.Github)) { - | + | } @if (!string.IsNullOrWhiteSpace(Model.Blog.StackOverflow)) { - | diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs index 256f13e852..626b54d543 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; using Volo.Blogging.Blogs.Dtos; diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs index 14bcfd444f..468d46decd 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs @@ -1,6 +1,8 @@ using System; using System.ComponentModel.DataAnnotations; +using System.Net; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; @@ -13,6 +15,7 @@ namespace Volo.Blogging.Pages.Blog.Posts { private readonly IPostAppService _postAppService; private readonly IBlogAppService _blogAppService; + private readonly IAuthorizationService _authorization; [BindProperty(SupportsGet = true)] public string BlogShortName { get; set; } @@ -22,19 +25,27 @@ namespace Volo.Blogging.Pages.Blog.Posts public BlogDto Blog { get; set; } - public NewModel(IPostAppService postAppService, IBlogAppService blogAppService) + public NewModel(IPostAppService postAppService, IBlogAppService blogAppService, IAuthorizationService authorization) { _postAppService = postAppService; _blogAppService = blogAppService; + _authorization = authorization; } - public async Task OnGetAsync() + public async Task OnGetAsync() { + if (!await _authorization.IsGrantedAsync(BloggingPermissions.Posts.Create)) + { + return Redirect("/"); + } + Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Post = new CreatePostViewModel { BlogId = Blog.Id }; + + return Page(); } public async Task OnPost()