Browse Source

Merge branch 'master' of https://github.com/volosoft/abp

pull/318/head
Halil ibrahim Kalkan 8 years ago
parent
commit
c5d441fc82
  1. 3
      modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs
  2. 6
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/BloggingApplicationContractsModule.cs
  3. 32
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/BloggingPermissionDefinitionProvider.cs
  4. 43
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/BloggingPermissions.cs
  5. 6
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  6. 5
      modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs
  7. 37
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml
  8. 10
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs
  9. 33
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml
  10. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs

3
modules/blogging/app/Volo.BloggingTestApp/BloggingTestAppModule.cs

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
@ -138,7 +139,7 @@ namespace Volo.BloggingTestApp
.GetRequiredService<IIdentityDataSeeder>() .GetRequiredService<IIdentityDataSeeder>()
.SeedAsync( .SeedAsync(
"1q2w3E*", "1q2w3E*",
IdentityPermissions.GetAll()//.Union(BlogPermissions.GetAll()) //TODO: Define blog permissions IdentityPermissions.GetAll().Union(BloggingPermissions.GetAll())
); );
}); });
} }

6
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/BloggingApplicationContractsModule.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Blogging namespace Volo.Blogging
@ -8,6 +9,11 @@ namespace Volo.Blogging
{ {
public override void ConfigureServices(IServiceCollection services) public override void ConfigureServices(IServiceCollection services)
{ {
services.Configure<PermissionOptions>(options =>
{
options.DefinitionProviders.Add<BloggingPermissionDefinitionProvider>();
});
services.AddAssemblyOf<BloggingApplicationContractsModule>(); services.AddAssemblyOf<BloggingApplicationContractsModule>();
} }
} }

32
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/BloggingPermissionDefinitionProvider.cs

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;
using Volo.Blogging.Localization;
namespace Volo.Blogging
{
public class BloggingPermissionDefinitionProvider : PermissionDefinitionProvider
{
public override void Define(IPermissionDefinitionContext context)
{
var bloggingGroup = context.AddGroup(BloggingPermissions.GroupName, L("Permission:Blogging"));
var blogs = bloggingGroup.AddPermission(BloggingPermissions.Blogs.Default, L("Permission:BlogManagement"));
blogs.AddChild(BloggingPermissions.Blogs.Update, L("Permission:Edit"));
blogs.AddChild(BloggingPermissions.Blogs.Delete, L("Permission:Delete"));
blogs.AddChild(BloggingPermissions.Blogs.Create, L("Permission:Delete"));
var posts = bloggingGroup.AddPermission(BloggingPermissions.Posts.Default, L("Permission:PostManagement"));
posts.AddChild(BloggingPermissions.Posts.Update, L("Permission:Edit"));
posts.AddChild(BloggingPermissions.Posts.Delete, L("Permission:Delete"));
posts.AddChild(BloggingPermissions.Posts.Create, L("Permission:Delete"));
}
private static LocalizableString L(string name)
{
return LocalizableString.Create<BloggingResource>(name);
}
}
}

43
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/BloggingPermissions.cs

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Blogging
{
public class BloggingPermissions
{
public const string GroupName = "Blogging";
public static class Blogs
{
public const string Default = GroupName + ".Blog";
public const string Delete = Default + ".Delete";
public const string Update = Default + ".Update";
public const string Create = Default + ".Create";
}
public static class Posts
{
public const string Default = GroupName + ".Post";
public const string Delete = Default + ".Delete";
public const string Update = Default + ".Update";
public const string Create = Default + ".Create";
}
public static string[] GetAll()
{
return new[]
{
GroupName,
Blogs.Default,
Blogs.Delete,
Blogs.Update,
Blogs.Create,
Posts.Default,
Posts.Delete,
Posts.Update,
Posts.Create
};
}
}
}

6
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -4,10 +4,12 @@ using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Users; using Volo.Abp.Users;
namespace Volo.Blogging.Posts namespace Volo.Blogging.Posts
{ {
[Authorize(BloggingPermissions.Posts.Default)]
public class PostAppService : ApplicationService, IPostAppService public class PostAppService : ApplicationService, IPostAppService
{ {
private readonly IPostRepository _postRepository; private readonly IPostRepository _postRepository;
@ -39,6 +41,7 @@ namespace Volo.Blogging.Posts
return ObjectMapper.Map<Post, PostWithDetailsDto>(post); return ObjectMapper.Map<Post, PostWithDetailsDto>(post);
} }
[Authorize(BloggingPermissions.Posts.Update)]
public async Task<PostWithDetailsDto> UpdateAsync(Guid id, UpdatePostDto input) public async Task<PostWithDetailsDto> UpdateAsync(Guid id, UpdatePostDto input)
{ {
var post = await _postRepository.GetAsync(id); var post = await _postRepository.GetAsync(id);
@ -51,10 +54,11 @@ namespace Volo.Blogging.Posts
return ObjectMapper.Map<Post, PostWithDetailsDto>(post); return ObjectMapper.Map<Post, PostWithDetailsDto>(post);
} }
[Authorize(BloggingPermissions.Posts.Create)]
public async Task<PostWithDetailsDto> CreateAsync(CreatePostDto input) public async Task<PostWithDetailsDto> CreateAsync(CreatePostDto input)
{ {
var post = new Post( var post = new Post(
GuidGenerator.Create(), id: GuidGenerator.Create(),
blogId: input.BlogId, blogId: input.BlogId,
creatorId: CurrentUser.GetId(), creatorId: CurrentUser.GetId(),
title: input.Title title: input.Title

5
modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs

@ -29,14 +29,13 @@ namespace Volo.Blogging
options.FileSets.AddEmbedded<BloggingWebModule>("Volo.Blogging"); options.FileSets.AddEmbedded<BloggingWebModule>("Volo.Blogging");
}); });
services.Configure<RazorPagesOptions>(options => services.Configure<RazorPagesOptions>(options =>
{ {
//TODO: Make configurable! //TODO: Make configurable!
options.Conventions.AddPageRoute("/Blog/Posts/Index", "blog/{blogShortName}"); options.Conventions.AddPageRoute("/Blog/Posts/Index", "blog/{blogShortName}");
options.Conventions.AddPageRoute("/Blog/Posts/Detail", "blog/{blogShortName}/{postTitle}"); options.Conventions.AddPageRoute("/Blog/Posts/Detail", "blog/{blogShortName}/{postTitle}");
options.Conventions.AddPageRoute("/Blog/Posts/Edit", "blog/{blogShortName}/manage/{postId}"); options.Conventions.AddPageRoute("/Blog/Posts/Edit", "blog/{blogShortName}/posts/edit/{postId}");
options.Conventions.AddPageRoute("/Blog/Posts/New", "blog/{blogShortName}/manage/new"); options.Conventions.AddPageRoute("/Blog/Posts/New", "blog/{blogShortName}/posts/new");
}); });
services.AddAssemblyOf<BloggingWebModule>(); services.AddAssemblyOf<BloggingWebModule>();

37
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml

@ -4,28 +4,23 @@
@{ @{
} }
@using (Html.BeginForm(FormMethod.Post))
{
<div class="form-group">
<label class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input class="form-control" name="Title" value="@Model.Post.Title">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Content</label>
<div class="col-sm-10">
<textarea rows="4" class="form-control" name="Content">@Model.Post.Content</textarea>
</div>
</div>
<input name="BlogId" value="@Model.Post.BlogId" hidden="">
<input name="Id" value="@Model.Post.Id" hidden="">
<div class="form-group"> <form method="post" id="edit-post-form">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button> <abp-input asp-for="@Model.Post.Title" autofocus />
<div class="form-group">
<label>Content</label>
<textarea rows="4" class="form-control" name="Post.Content">@Model.Post.Content</textarea>
</div> </div>
</div>
} <abp-input asp-for="@Model.Post.BlogId" hidden="" />
<input name="Id" value="@Model.Post.Id" hidden="">
<abp-button type="submit" form="edit-post-form">
<span>Submit</span>
</abp-button>
</form>

10
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs

@ -2,7 +2,6 @@ using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.Application.Dtos;
using Volo.Blogging.Blogs; using Volo.Blogging.Blogs;
using Volo.Blogging.Posts; using Volo.Blogging.Posts;
@ -13,16 +12,11 @@ namespace Volo.Blogging.Pages.Blog.Posts
private readonly IPostAppService _postAppService; private readonly IPostAppService _postAppService;
private readonly IBlogAppService _blogAppService; private readonly IBlogAppService _blogAppService;
[BindProperty(SupportsGet = true)]
public string BlogShortName { get; set; }
[BindProperty(SupportsGet = true)] [BindProperty(SupportsGet = true)]
public string PostId { get; set; } public string PostId { get; set; }
public PostWithDetailsDto Post { get; set; } public PostWithDetailsDto Post { get; set; }
public BlogDto Blog { get; set; }
public EditModel(IPostAppService postAppService, IBlogAppService blogAppService) public EditModel(IPostAppService postAppService, IBlogAppService blogAppService)
{ {
_postAppService = postAppService; _postAppService = postAppService;
@ -31,11 +25,7 @@ namespace Volo.Blogging.Pages.Blog.Posts
public async void OnGet() public async void OnGet()
{ {
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = await _postAppService.GetAsync(new Guid(PostId)); Post = await _postAppService.GetAsync(new Guid(PostId));
Blog = blog;
} }
public async Task<ActionResult> OnPost(Guid id, UpdatePostDto post) public async Task<ActionResult> OnPost(Guid id, UpdatePostDto post)

33
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml

@ -4,27 +4,20 @@
@{ @{
} }
@using (Html.BeginForm(FormMethod.Post))
{
<div class="form-group">
<label class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input class="form-control" name="Title" value="@Model.Post.Title">
</div>
</div>
<div class="form-group"> <form method="post" id="new-post-form">
<label class="col-sm-2 control-label">Content</label>
<div class="col-sm-10">
<textarea rows="4" class="form-control" name="Content">@Model.Post.Content</textarea>
</div>
</div>
<input name="BlogId" value="@Model.Post.BlogId" hidden=""> <abp-input asp-for="@Model.Post.Title" autofocus />
<div class="form-group"> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10"> <label>Content</label>
<button type="submit" class="btn btn-default">Save</button> <textarea rows="4" class="form-control" name="Post.Content">@Model.Post.Content</textarea>
</div> </div>
</div>
} <abp-input asp-for="@Model.Post.BlogId" hidden="" />
<abp-button type="submit" form="new-post-form">
<span>Submit</span>
</abp-button>
</form>

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml.cs

@ -1,8 +1,6 @@
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Abp.Application.Dtos;
using Volo.Blogging.Blogs; using Volo.Blogging.Blogs;
using Volo.Blogging.Posts; using Volo.Blogging.Posts;
@ -16,7 +14,7 @@ namespace Volo.Blogging.Pages.Blog.Posts
[BindProperty(SupportsGet = true)] [BindProperty(SupportsGet = true)]
public string BlogShortName { get; set; } public string BlogShortName { get; set; }
public PostWithDetailsDto Post { get; set; } public CreatePostDto Post { get; set; }
public BlogDto Blog { get; set; } public BlogDto Blog { get; set; }
@ -30,7 +28,7 @@ namespace Volo.Blogging.Pages.Blog.Posts
{ {
var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); var blog = await _blogAppService.GetByShortNameAsync(BlogShortName);
Post = new PostWithDetailsDto() Post = new CreatePostDto()
{ {
BlogId = blog.Id BlogId = blog.Id
}; };

Loading…
Cancel
Save