feat:完成仅自己可见功能
This commit is contained in:
@@ -49,6 +49,13 @@
|
||||
<returns></returns>
|
||||
<exception cref="T:Yi.Framework.Core.Exceptions.UserFriendlyException"></exception>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Application.Forum.ArticleService.VerifyDiscussCreateIdAsync(System.Nullable{System.Int64})">
|
||||
<summary>
|
||||
效验创建权限
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Forum.CommentService">
|
||||
<summary>
|
||||
评论
|
||||
@@ -96,6 +103,14 @@
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Application.Forum.DiscussService.VerifyDiscussPermissionAsync(System.Int64)">
|
||||
<summary>
|
||||
效验主题查询权限
|
||||
</summary>
|
||||
<param name="discussId"></param>
|
||||
<returns></returns>
|
||||
<exception cref="T:Yi.Framework.Core.Exceptions.UserFriendlyException"></exception>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Forum.MyTypeService">
|
||||
<summary>
|
||||
Label服务实现
|
||||
|
||||
@@ -8,6 +8,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.BBS.Domain.Forum.Repositories;
|
||||
using Yi.Framework.Ddd.Repositories;
|
||||
using Yi.BBS.Domain.Shared.Forum.ConstClasses;
|
||||
using Yi.BBS.Domain.Shared.Forum.EnumClasses;
|
||||
using Yi.Framework.Core.CurrentUsers;
|
||||
using Yi.RBAC.Domain.Shared.Identity.ConstClasses;
|
||||
|
||||
namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
@@ -26,6 +29,11 @@ namespace Yi.BBS.Application.Forum
|
||||
[Autowired]
|
||||
private IRepository<DiscussEntity> _discussRepository { get; set; }
|
||||
|
||||
[Autowired]
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
|
||||
[Autowired]
|
||||
private IDiscussService _discussService { get; set; }
|
||||
/// <summary>
|
||||
/// 获取文章全部平铺信息
|
||||
/// </summary>
|
||||
@@ -35,10 +43,8 @@ namespace Yi.BBS.Application.Forum
|
||||
[Route("/api/article/all/discuss-id/{discussId}")]
|
||||
public async Task<List<ArticleAllOutputDto>> GetAllAsync([FromRoute] long discussId)
|
||||
{
|
||||
if (!await _discussRepository.IsAnyAsync(x => x.Id == discussId))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
await _discussService.VerifyDiscussPermissionAsync(discussId);
|
||||
|
||||
|
||||
var entities = await _articleRepository.GetTreeAsync(x => x.DiscussId == discussId);
|
||||
//var result = entities.Tile();
|
||||
@@ -72,7 +78,8 @@ namespace Yi.BBS.Application.Forum
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async override Task<ArticleGetOutputDto> CreateAsync(ArticleCreateInputVo input)
|
||||
{
|
||||
if (!await _discussRepository.IsAnyAsync(x => x.Id == input.DiscussId))
|
||||
var discuss = await _discussRepository.GetFirstAsync(x => x.Id == input.DiscussId);
|
||||
if (discuss is null)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
@@ -80,7 +87,27 @@ namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
throw new UserFriendlyException(ArticleConst.文章不存在);
|
||||
}
|
||||
await VerifyDiscussCreateIdAsync(discuss.CreatorId);
|
||||
return await base.CreateAsync(input);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 效验创建权限
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task VerifyDiscussCreateIdAsync(long? userId)
|
||||
{
|
||||
//只有文章是特殊的,不能在其他主题下创建
|
||||
//主题的创建者不是当前用户,同时,没有权限或者超级管理
|
||||
|
||||
//false & true & false ,三个条件任意满意一个,即可成功使用||,最后取反,一个都不满足
|
||||
//
|
||||
if (userId != _currentUser.Id && !UserConst.Admin.Equals( _currentUser.UserName)&& !_currentUser.Permission.Contains("bbs:discuss:add"))
|
||||
{
|
||||
throw new UserFriendlyException("无权限在其他用户主题中创建子文章");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace Yi.BBS.Application.Forum
|
||||
[Autowired]
|
||||
private IRepository<DiscussEntity> _discussRepository { get; set; }
|
||||
|
||||
|
||||
[Autowired]
|
||||
private IDiscussService _discussService { get; set; }
|
||||
/// <summary>
|
||||
/// 获取改主题下的评论,结构为二维列表,该查询无分页
|
||||
/// </summary>
|
||||
@@ -43,6 +44,7 @@ namespace Yi.BBS.Application.Forum
|
||||
/// <returns></returns>
|
||||
public async Task<PagedResultDto<CommentGetListOutputDto>> GetDiscussIdAsync([FromRoute] long discussId, [FromQuery] CommentGetListInputVo input)
|
||||
{
|
||||
await _discussService.VerifyDiscussPermissionAsync(discussId);
|
||||
|
||||
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Content), x => x.Content.Contains(input.Content))
|
||||
.Where(x => x.DiscussId == discussId)
|
||||
|
||||
@@ -29,6 +29,10 @@ namespace Yi.BBS.Application.Forum
|
||||
public class DiscussService : CrudAppService<DiscussEntity, DiscussGetOutputDto, DiscussGetListOutputDto, long, DiscussGetListInputVo, DiscussCreateInputVo, DiscussUpdateInputVo>,
|
||||
IDiscussService, IAutoApiService
|
||||
{
|
||||
public DiscussService(ICurrentUser currentUser)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
}
|
||||
[Autowired]
|
||||
private ForumManager _forumManager { get; set; }
|
||||
|
||||
@@ -38,7 +42,7 @@ namespace Yi.BBS.Application.Forum
|
||||
[Autowired]
|
||||
private IDistributedEventBus _distributedEventBus { get; set; }
|
||||
|
||||
[Autowired]
|
||||
//[Autowired]
|
||||
private ICurrentUser _currentUser { get; set; }
|
||||
/// <summary>
|
||||
/// 单查
|
||||
@@ -47,12 +51,16 @@ namespace Yi.BBS.Application.Forum
|
||||
/// <returns></returns>
|
||||
public async override Task<DiscussGetOutputDto> GetAsync(long id)
|
||||
{
|
||||
|
||||
//查询主题发布 浏览主题 事件,浏览数+1
|
||||
var item = await _DbQueryable.LeftJoin<UserEntity>((discuss, user) => discuss.CreatorId == user.Id)
|
||||
.Select((discuss, user) => new DiscussGetOutputDto
|
||||
{
|
||||
User = new UserGetListOutputDto() { UserName = user.UserName, Nick = user.Nick, Icon = user.Icon }
|
||||
}, true).SingleAsync(discuss => discuss.Id == id);
|
||||
|
||||
await VerifyDiscussPermissionAsync(item.Id);
|
||||
|
||||
if (item is not null)
|
||||
{
|
||||
_distributedEventBus.PublishAsync(new SeeDiscussEventArgs { DiscussId = item.Id, OldSeeNum = item.SeeNum });
|
||||
@@ -84,9 +92,14 @@ namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
Id=discuss.Id,
|
||||
IsAgree = SqlFunc.Subqueryable<AgreeEntity>().Where(x => x.CreatorId == _currentUser.Id && x.DiscussId == discuss.Id).Any(),
|
||||
User = new UserGetListOutputDto() { UserName = user.UserName, Nick = user.Nick, Icon = user.Icon }
|
||||
|
||||
User = new UserGetListOutputDto() { Id=user.Id, UserName = user.UserName, Nick = user.Nick, Icon = user.Icon }
|
||||
|
||||
}, true)
|
||||
.ToPageListAsync(input.PageNum, input.PageSize, total);
|
||||
|
||||
//查询完主题之后,要过滤一下私有的主题信息
|
||||
items.ApplyPermissionTypeFilter(_currentUser.Id);
|
||||
return new PagedResultDto<DiscussGetListOutputDto>(total, items);
|
||||
}
|
||||
|
||||
@@ -101,8 +114,33 @@ namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
throw new UserFriendlyException(PlateConst.板块不存在);
|
||||
}
|
||||
var entity = await _forumManager.CreateDiscussAsync(input.plateId, input.Title, input.Types, input.Content, input.Introduction);
|
||||
var entity = await _forumManager.CreateDiscussAsync(await MapToEntityAsync(input));
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 效验主题查询权限
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async Task VerifyDiscussPermissionAsync(long discussId)
|
||||
{
|
||||
var discuss = await _repository.GetFirstAsync(x => x.Id == discussId);
|
||||
if (discuss is null)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.主题不存在);
|
||||
}
|
||||
if (discuss.PermissionType == DiscussPermissionTypeEnum.Oneself)
|
||||
{
|
||||
if (discuss.CreatorId != _currentUser.Id)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.私密);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user