feat: 新增角色查看主题权限
This commit is contained in:
@@ -4,8 +4,6 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Article
|
||||
{
|
||||
public class ArticleGetListOutputDto : EntityDto<Guid>
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>
|
||||
//public string Content { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Guid DiscussId { get; set; }
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Article
|
||||
{
|
||||
@@ -10,5 +11,23 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Article
|
||||
public Guid ParentId { get; set; }
|
||||
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
public bool HasPermission { get;internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置权限
|
||||
/// </summary>
|
||||
public void SetPassPermission()
|
||||
{
|
||||
HasPermission = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置无权限
|
||||
/// </summary>
|
||||
public void SetNoPermission()
|
||||
{
|
||||
HasPermission = false;
|
||||
Content=DiscussConst.Privacy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
/// <summary>
|
||||
/// 标签
|
||||
/// </summary>
|
||||
public List<Guid>? DiscussLables { get; set; }
|
||||
public List<Guid>? DiscussLableIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 角色
|
||||
/// </summary>
|
||||
public List<string>? PermissionRoleCodes { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
/// </summary>
|
||||
public bool IsAgree { get; set; } = false;
|
||||
public string Title { get; set; }
|
||||
public string Types { get; set; }
|
||||
public string? Introduction { get; set; }
|
||||
|
||||
public int AgreeNum { get; set; }
|
||||
@@ -43,57 +42,15 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
/// </summary>
|
||||
public string? Cover { get; set; }
|
||||
|
||||
//私有需要判断code权限
|
||||
public string? PrivateCode { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
|
||||
public List<Guid>? PermissionUserIds { get; set; }
|
||||
/// <summary>
|
||||
/// 所需角色
|
||||
/// </summary>
|
||||
public List<string>? PermissionRoleCodes { get; set; } = new List<string>();
|
||||
|
||||
public BbsUserGetListOutputDto User { get; set; }
|
||||
public List<Guid>? DiscussLables { get; set; } = new List<Guid>();
|
||||
public List<Guid>? DiscussLableIds { get; set; } = new List<Guid>();
|
||||
public List<DiscussLableGetOutputDto> Lables { get; set; } = new List<DiscussLableGetOutputDto>();
|
||||
public void SetBan()
|
||||
{
|
||||
Title = DiscussConst.Privacy;
|
||||
Introduction = "";
|
||||
Cover = null;
|
||||
//被禁止
|
||||
IsBan = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DiscussGetListOutputDtoExtension
|
||||
{
|
||||
|
||||
public static void ApplyPermissionTypeFilter(this List<DiscussGetListOutputDto> dtos, Guid userId)
|
||||
{
|
||||
dtos?.ForEach(dto =>
|
||||
{
|
||||
switch (dto.PermissionType)
|
||||
{
|
||||
case DiscussPermissionTypeEnum.Public:
|
||||
break;
|
||||
case DiscussPermissionTypeEnum.Oneself:
|
||||
//当前主题是仅自己可见,同时不是当前登录用户
|
||||
if (dto.User.Id != userId)
|
||||
{
|
||||
dto.SetBan();
|
||||
}
|
||||
break;
|
||||
case DiscussPermissionTypeEnum.User:
|
||||
//当前主题为部分可见,同时不是当前登录用户 也 不在可见用户列表中
|
||||
if (dto.User.Id != userId && !dto.PermissionUserIds.Contains(userId))
|
||||
{
|
||||
dto.SetBan();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.DiscussLable;
|
||||
using Yi.Framework.Bbs.Application.Contracts.Dtos.Plate;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Application.Contracts.Dtos.User;
|
||||
|
||||
@@ -14,7 +15,6 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
/// </summary>
|
||||
public bool IsDisableCreateComment { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string? Types { get; set; }
|
||||
public string? Introduction { get; set; }
|
||||
public int AgreeNum { get; set; }
|
||||
public int SeeNum { get; set; }
|
||||
@@ -37,12 +37,33 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
public DateTime CreationTime { get; set; }
|
||||
public DiscussPermissionTypeEnum PermissionType { get; set; }
|
||||
public bool IsAgree { get; set; } = false;
|
||||
public List<Guid>? PermissionUserIds { get; set; }
|
||||
public List<string> PermissionRoleCodes { get; set; } = new List<string>();
|
||||
|
||||
|
||||
|
||||
public BbsUserGetListOutputDto User { get; set; }
|
||||
|
||||
public PlateGetOutputDto Plate { get; set; }
|
||||
|
||||
public List<Guid>? DiscussLables { get; set; } = new List<Guid>();
|
||||
public List<Guid>? DiscussLableIds { get; set; } = new List<Guid>();
|
||||
public List<DiscussLableGetOutputDto> Lables { get; set; } =new List<DiscussLableGetOutputDto>();
|
||||
|
||||
public bool HasPermission { get;internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置权限
|
||||
/// </summary>
|
||||
public void SetPassPermission()
|
||||
{
|
||||
HasPermission = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置无权限
|
||||
/// </summary>
|
||||
public void SetNoPermission()
|
||||
{
|
||||
HasPermission = false;
|
||||
Content=DiscussConst.Privacy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Discuss
|
||||
/// <summary>
|
||||
/// 标签
|
||||
/// </summary>
|
||||
public List<Guid>? DiscussLables { get; set; }
|
||||
public List<Guid>? DiscussLableIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 需求角色
|
||||
/// </summary>
|
||||
public List<string>? PermissionRoleCodes { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
/// <summary>
|
||||
/// Article服务实现
|
||||
/// </summary>
|
||||
|
||||
public class ArticleService : YiCrudAppService<ArticleAggregateRoot, ArticleGetOutputDto, ArticleGetListOutputDto, Guid, ArticleGetListInputVo, ArticleCreateInputVo, ArticleUpdateInputVo>,
|
||||
public class ArticleService : YiCrudAppService<ArticleAggregateRoot, ArticleGetOutputDto, ArticleGetListOutputDto,
|
||||
Guid, ArticleGetListInputVo, ArticleCreateInputVo, ArticleUpdateInputVo>,
|
||||
IArticleService
|
||||
{
|
||||
public ArticleService(IArticleRepository articleRepository,
|
||||
@@ -39,13 +39,12 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
IDiscussService discussService,
|
||||
ForumManager forumManager) : base(articleRepository)
|
||||
{
|
||||
|
||||
_articleRepository = articleRepository;
|
||||
_discussRepository = discussRepository;
|
||||
_discussService = discussService;
|
||||
_forumManager = forumManager;
|
||||
|
||||
}
|
||||
|
||||
private ForumManager _forumManager;
|
||||
private IArticleRepository _articleRepository;
|
||||
private ISqlSugarRepository<DiscussAggregateRoot> _discussRepository;
|
||||
@@ -55,13 +54,34 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
{
|
||||
RefAsync<int> total = 0;
|
||||
|
||||
var entities = await _articleRepository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name!))
|
||||
//.WhereIF(!string.IsNullOrEmpty(input.Code), x => x.Name.Contains(input.Code!))
|
||||
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
||||
var entities = await _articleRepository._DbQueryable
|
||||
.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name!))
|
||||
.WhereIF(input.StartTime is not null && input.EndTime is not null,
|
||||
x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
return new PagedResultDto<ArticleGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<ArticleGetOutputDto> GetAsync(Guid id)
|
||||
{
|
||||
var entity = await _articleRepository.GetAsync(id);
|
||||
var output = entity.Adapt<ArticleGetOutputDto>();
|
||||
if (!await _forumManager.VerifyDiscussPermissionAsync(entity.DiscussId, CurrentUser.Id, CurrentUser.Roles))
|
||||
{
|
||||
output.SetNoPermission();
|
||||
}
|
||||
else
|
||||
{
|
||||
output.SetPassPermission();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文章全部树级信息
|
||||
@@ -72,16 +92,13 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
[Route("article/all/discuss-id/{discussId}")]
|
||||
public async Task<List<ArticleAllOutputDto>> GetAllAsync([FromRoute] Guid discussId)
|
||||
{
|
||||
await _forumManager.VerifyDiscussPermissionAsync(discussId,CurrentUser.Id);
|
||||
|
||||
|
||||
var entities = await _articleRepository.GetTreeAsync(x => x.DiscussId == discussId);
|
||||
var items = entities.Adapt<List<ArticleAllOutputDto>>();
|
||||
return items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章
|
||||
/// 查询文章概述
|
||||
/// </summary>
|
||||
/// <param name="discussId"></param>
|
||||
/// <returns></returns>
|
||||
@@ -108,7 +125,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
[Authorize]
|
||||
public async override Task<ArticleGetOutputDto> CreateAsync(ArticleCreateInputVo input)
|
||||
{
|
||||
await VerifyDiscussCreateIdAsync(input.DiscussId);
|
||||
await VerifyPermissionAsync(input.DiscussId);
|
||||
return await base.CreateAsync(input);
|
||||
}
|
||||
|
||||
@@ -121,7 +138,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
public override async Task<ArticleGetOutputDto> UpdateAsync(Guid id, ArticleUpdateInputVo input)
|
||||
{
|
||||
var entity = await _articleRepository.GetByIdAsync(id);
|
||||
await VerifyDiscussCreateIdAsync(entity.DiscussId);
|
||||
await VerifyPermissionAsync(entity.DiscussId);
|
||||
return await base.UpdateAsync(id, input);
|
||||
}
|
||||
|
||||
@@ -134,7 +151,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
public override async Task DeleteAsync(Guid id)
|
||||
{
|
||||
var entity = await _articleRepository.GetByIdAsync(id);
|
||||
await VerifyDiscussCreateIdAsync(entity.DiscussId);
|
||||
await VerifyPermissionAsync(entity.DiscussId);
|
||||
await base.DeleteAsync(id);
|
||||
}
|
||||
|
||||
@@ -143,8 +160,10 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
/// 导入文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task PostImportAsync([FromQuery] ArticleImprotDto input, [FromForm][Required] IFormFileCollection file)
|
||||
public async Task PostImportAsync([FromQuery] ArticleImprotDto input,
|
||||
[FromForm] [Required] IFormFileCollection file)
|
||||
{
|
||||
await VerifyPermissionAsync(input.DiscussId);
|
||||
var fileObjs = new List<FileObject>();
|
||||
if (file.Count > 0)
|
||||
{
|
||||
@@ -171,44 +190,17 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
{
|
||||
throw new UserFriendlyException("未选择文件");
|
||||
}
|
||||
|
||||
//使用简单工厂根据传入的类型进行判断
|
||||
await _forumManager.PostImportAsync(input.DiscussId, input.ArticleParentId, fileObjs, input.ImportType);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 校验创建权限,userId为主题创建者
|
||||
/// </summary>
|
||||
/// <param name="disucssId"></param>
|
||||
/// <returns></returns>
|
||||
private async Task VerifyDiscussCreateIdAsync(Guid disucssId)
|
||||
private async Task VerifyPermissionAsync(Guid discussId)
|
||||
{
|
||||
var discuss = await _discussRepository.GetFirstAsync(x => x.Id == disucssId);
|
||||
if (discuss is null)
|
||||
if (!await _forumManager.VerifyDiscussPermissionAsync(discussId, CurrentUser.Id, isVerifyLook: false))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.No_Exist);
|
||||
}
|
||||
|
||||
//这块有点绕,这个版本的写法比较清晰
|
||||
bool result = false;
|
||||
|
||||
if (CurrentUser.GetPermissions().Contains(UserConst.AdminPermissionCode))
|
||||
{
|
||||
//如果是超管,直接跳过
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//如果不是超管,必须满足作者是自己,同时还有发布的权限
|
||||
if (discuss.CreatorId == CurrentUser.Id)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
throw new UserFriendlyException("权限不足,请联系主题作者或管理员申请开通");
|
||||
throw new UserFriendlyException("您无权限进行操作", "403");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,6 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
|
||||
private ISqlSugarRepository<PlateAggregateRoot> _plateEntityRepository { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 单查
|
||||
/// </summary>
|
||||
@@ -117,7 +114,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
|
||||
//组装标签
|
||||
var lableDic=await _discussLableRepository.GetDiscussLableCacheMapAsync();
|
||||
foreach (var lableId in output.DiscussLables)
|
||||
foreach (var lableId in output.DiscussLableIds)
|
||||
{
|
||||
if (lableDic.TryGetValue(lableId,out var item))
|
||||
{
|
||||
@@ -125,7 +122,16 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
}
|
||||
}
|
||||
|
||||
await _forumManager.VerifyDiscussPermissionAsync(output.Id,CurrentUser.Id);
|
||||
//如果没有权限
|
||||
if (!await _forumManager.VerifyDiscussPermissionAsync(output.Id,CurrentUser.Id, CurrentUser.Roles))
|
||||
{
|
||||
output.SetNoPermission();
|
||||
}
|
||||
else
|
||||
{
|
||||
output.SetPassPermission();
|
||||
}
|
||||
|
||||
await _localEventBus.PublishAsync(new SeeDiscussEventArgs
|
||||
{ DiscussId = output.Id, OldSeeNum = output.SeeNum });
|
||||
return output;
|
||||
@@ -180,9 +186,6 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
.GroupBy(x => x.DiscussId)
|
||||
.ToDictionary(x => x.Key, y => y.Select(y => y.CreatorId).ToList());
|
||||
|
||||
//查询完主题之后,要过滤一下私有的主题信息
|
||||
items.ApplyPermissionTypeFilter(CurrentUser.Id ?? Guid.Empty);
|
||||
|
||||
var levelCacheDic= await _bbsUserManager.GetLevelCacheMapAsync();
|
||||
var lableDic=await _discussLableRepository.GetDiscussLableCacheMapAsync();
|
||||
|
||||
@@ -199,7 +202,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var lableId in x.DiscussLables)
|
||||
foreach (var lableId in x.DiscussLableIds)
|
||||
{
|
||||
if (lableDic.TryGetValue(lableId,out var item))
|
||||
{
|
||||
@@ -236,7 +239,6 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
Address = user.Address,
|
||||
Age = user.Age,
|
||||
CreationTime = user.CreationTime,
|
||||
|
||||
Level = info.Level,
|
||||
Introduction = user.Introduction,
|
||||
Icon = user.Icon,
|
||||
@@ -255,7 +257,7 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
output?.ForEach(x =>
|
||||
{
|
||||
x.User.LevelName = levelCacheDic[x.User.Level].Name;
|
||||
foreach (var lableId in x.DiscussLables)
|
||||
foreach (var lableId in x.DiscussLableIds)
|
||||
{
|
||||
if (lableDic.TryGetValue(lableId,out var item))
|
||||
{
|
||||
|
||||
@@ -14,14 +14,9 @@ namespace Yi.Framework.Bbs.Domain.Shared.Enums
|
||||
Public = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 仅自己可见
|
||||
/// 角色要求可见
|
||||
/// </summary>
|
||||
Oneself,
|
||||
|
||||
/// <summary>
|
||||
/// 部分用户可见
|
||||
/// </summary>
|
||||
User
|
||||
Role=1
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ namespace Yi.Framework.Bbs.Domain.Entities.Forum
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当PermissionType为部分用户时候,以下列表中的用户+创建者 代表拥有权限
|
||||
/// 当PermissionType为角色时候,以下列表中的角色+创建者 代表拥有权限
|
||||
/// </summary>
|
||||
[SugarColumn(IsJson = true)] //使用json处理
|
||||
public List<Guid>? PermissionUserIds { get; set; }
|
||||
public List<string>? PermissionRoleCodes { get; set; } = new List<string>();
|
||||
|
||||
[SugarColumn(IsJson = true)]//使用json处理
|
||||
public List<Guid>? DiscussLables{ get; set; }
|
||||
public List<Guid>? DiscussLableIds{ get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止评论创建功能
|
||||
|
||||
@@ -7,6 +7,7 @@ using Yi.Framework.Bbs.Domain.Managers.ArticleImport;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Model;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers
|
||||
@@ -52,30 +53,52 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
/// <param name="discussId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
public async Task VerifyDiscussPermissionAsync(Guid discussId,Guid? userId)
|
||||
public async Task<bool> VerifyDiscussPermissionAsync(Guid discussId,Guid? userId,string[] roles=null,bool isVerifyLook=true)
|
||||
{
|
||||
var discuss = await _discussRepository.GetFirstAsync(x => x.Id == discussId);
|
||||
if (discuss is null)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.No_Exist);
|
||||
}
|
||||
//作者是自己,直接有权限
|
||||
if (discuss.CreatorId ==userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//管理员,直接放行
|
||||
if (roles.Contains(UserConst.AdminRolesCode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (discuss.PermissionType == DiscussPermissionTypeEnum.Oneself)
|
||||
//是否为校验 查看权限, 其他操作权限(增删改)
|
||||
if (isVerifyLook)
|
||||
{
|
||||
if (discuss.CreatorId != userId)
|
||||
//要求角色
|
||||
if (discuss.PermissionType == DiscussPermissionTypeEnum.Role)
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.Privacy);
|
||||
if (roles is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
List<string> roleList = roles.ToList();
|
||||
//所选角色,没有任何交集
|
||||
if (!discuss.PermissionRoleCodes.Intersect(roleList).Any())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (discuss.PermissionType == DiscussPermissionTypeEnum.User)
|
||||
{
|
||||
if (discuss.CreatorId !=userId &&
|
||||
!discuss.PermissionUserIds.Contains(userId?? Guid.Empty))
|
||||
{
|
||||
throw new UserFriendlyException(DiscussConst.Privacy);
|
||||
//通过了上面要求,剩下的都是有权限的,可以直接看
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//通过了上面的要求,剩下的就是没有权限了,直接拦截
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
<!-- 底部 -->
|
||||
<div class="item item-bottom">
|
||||
<div class="tag-list">
|
||||
|
||||
<el-tag v-for="item in discuss.permissionRoleCodes" effect="dark" type="danger" :key="item">{{item}}</el-tag>
|
||||
|
||||
<el-tag v-if="discuss.lables.length===0">暂无标签</el-tag>
|
||||
<el-tag v-for="item in discuss.lables" :key="item.id">{{item.name}}</el-tag>
|
||||
</div>
|
||||
@@ -126,7 +129,8 @@ onMounted(() => {
|
||||
discuss.agreeNum = props.discuss.agreeNum;
|
||||
discuss.isBan = props.discuss.isBan;
|
||||
discuss.cover = props.discuss.cover;
|
||||
discuss.lables=props.discuss.lables
|
||||
discuss.lables=props.discuss.lables;
|
||||
discuss.permissionRoleCodes=props.discuss.permissionRoleCodes;
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
<template>
|
||||
<el-select
|
||||
style="width: 600px;"
|
||||
v-model="value"
|
||||
multiple
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
placeholder="请输入用户账号(可多选)"
|
||||
remote-show-suffix
|
||||
:remote-method="remoteMethod"
|
||||
:loading="loading"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, ref,computed } from 'vue'
|
||||
import {listUser} from '@/apis/userApi'
|
||||
const props = defineProps(['modelValue'])
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
|
||||
//这个为可选择的列表,{value,label},value为用户id,label为账号名称(不可重复)
|
||||
const options = ref([])
|
||||
|
||||
const value = computed({
|
||||
get() {
|
||||
return props.modelValue
|
||||
},
|
||||
set(value) {
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
onMounted( async()=>{
|
||||
|
||||
const response= await listUser({ids:value.value.join()});
|
||||
const res=response.data.items;
|
||||
//下拉列表
|
||||
options.value = res
|
||||
.map((item) => {
|
||||
return { value: `${item.id}`, label: `用户:${item.userName}` }
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
const loadUser=async(query)=>{
|
||||
const response= await listUser({userName:query});
|
||||
const res=response.data.items;
|
||||
//下拉列表
|
||||
options.value = res
|
||||
.map((item) => {
|
||||
return { value: `${item.id}`, label: `用户:${item.userName}` }
|
||||
})
|
||||
}
|
||||
|
||||
const remoteMethod =async (query) => {
|
||||
if (query) {
|
||||
loading.value = true
|
||||
await loadUser(query);
|
||||
loading.value = false
|
||||
} else {
|
||||
options.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const states = [
|
||||
'Alabama',
|
||||
'Alaska',
|
||||
'Arizona',
|
||||
'Arkansas',
|
||||
'California',
|
||||
'Colorado',
|
||||
'Connecticut',
|
||||
'Delaware',
|
||||
'Florida',
|
||||
'Georgia',
|
||||
'Hawaii',
|
||||
'Idaho',
|
||||
'Illinois',
|
||||
'Indiana',
|
||||
'Iowa',
|
||||
'Kansas',
|
||||
'Kentucky',
|
||||
'Louisiana',
|
||||
'Maine',
|
||||
'Maryland',
|
||||
'Massachusetts',
|
||||
'Michigan',
|
||||
'Minnesota',
|
||||
'Mississippi',
|
||||
'Missouri',
|
||||
'Montana',
|
||||
'Nebraska',
|
||||
'Nevada',
|
||||
'New Hampshire',
|
||||
'New Jersey',
|
||||
'New Mexico',
|
||||
'New York',
|
||||
'North Carolina',
|
||||
'North Dakota',
|
||||
'Ohio',
|
||||
'Oklahoma',
|
||||
'Oregon',
|
||||
'Pennsylvania',
|
||||
'Rhode Island',
|
||||
'South Carolina',
|
||||
'South Dakota',
|
||||
'Tennessee',
|
||||
'Texas',
|
||||
'Utah',
|
||||
'Vermont',
|
||||
'Virginia',
|
||||
'Washington',
|
||||
'West Virginia',
|
||||
'Wisconsin',
|
||||
'Wyoming',
|
||||
]
|
||||
</script>
|
||||
@@ -28,19 +28,21 @@
|
||||
>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="权限:" v-if="radio == 'discuss'">
|
||||
<el-radio-group v-model="perRadio">
|
||||
<el-radio-button label="Public">公开</el-radio-button>
|
||||
<el-radio-button label="Oneself">仅自己可见</el-radio-button>
|
||||
<el-radio-button label="User">部分用户可见</el-radio-button>
|
||||
<el-radio-button label="Role">所选角色可见</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="可见用户:"
|
||||
v-if="radio == 'discuss' && perRadio == 'User'"
|
||||
label="可见角色:"
|
||||
v-if="radio == 'discuss' && perRadio == 'Role'"
|
||||
>
|
||||
<UserSelectInfo v-model="editForm.permissionUserIds"/>
|
||||
<el-input-tag
|
||||
v-model="editForm.permissionRoleCodes"
|
||||
placeholder="请输入角色code"
|
||||
aria-label="按下回车,可选择多个"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item
|
||||
@@ -155,7 +157,6 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import MavonEdit from "@/components/MavonEdit.vue";
|
||||
import UserSelectInfo from "@/components/UserSelectInfo.vue";
|
||||
import {ref, reactive, onMounted, computed} from "vue";
|
||||
import {useRoute, useRouter} from "vue-router";
|
||||
import {Plus, Download} from "@element-plus/icons-vue";
|
||||
@@ -221,8 +222,8 @@ const editForm = reactive({
|
||||
introduction: "",
|
||||
content: "",
|
||||
name: "",
|
||||
permissionUserIds: [],
|
||||
discussLables:[]
|
||||
permissionRoleCodes: [],
|
||||
discussLableIds:[]
|
||||
});
|
||||
|
||||
//组装主题内容: 需要更新主题信息
|
||||
@@ -249,18 +250,16 @@ const submit = async (formEl) => {
|
||||
if (!formEl) return;
|
||||
await formEl.validate(async (valid, fields) => {
|
||||
if (valid) {
|
||||
discuss.discussLables=selectLabelList.value.map((item) =>item.id);
|
||||
console.log(discuss,"discuss")
|
||||
//dicuss主题处理
|
||||
if (radio.value == "discuss") {
|
||||
discuss.discussLableIds=selectLabelList.value.map((item) =>item.id);
|
||||
discuss.title = editForm.title;
|
||||
discuss.introduction = editForm.introduction;
|
||||
discuss.content = editForm.content;
|
||||
discuss.plateId = discuss.plateId ?? route.query.plateId;
|
||||
discuss.cover = dialogImageUrl.value;
|
||||
discuss.permissionType = perRadio.value;
|
||||
|
||||
discuss.permissionUserIds = editForm.permissionUserIds;
|
||||
discuss.permissionRoleCodes = editForm.permissionRoleCodes;
|
||||
//主题创建
|
||||
if (route.query.operType == "create") {
|
||||
const response = await discussAdd(discuss);
|
||||
@@ -274,7 +273,7 @@ const submit = async (formEl) => {
|
||||
}
|
||||
//主题更新
|
||||
else if (route.query.operType == "update") {
|
||||
discuss.discussLables=selectLabelList.value.map((item) =>item.id);
|
||||
discuss.discussLableIds=selectLabelList.value.map((item) =>item.id);
|
||||
await discussUpdate(route.query.discussId, discuss);
|
||||
|
||||
ElMessage({
|
||||
@@ -342,7 +341,8 @@ const loadDiscuss = async () => {
|
||||
editForm.content = res.content;
|
||||
editForm.title = res.title;
|
||||
editForm.introduction = res.introduction;
|
||||
editForm.discussLables=res.discussLables;
|
||||
editForm.discussLableIds=res.discussLableIds;
|
||||
editForm.permissionRoleCodes = res.permissionRoleCodes;
|
||||
|
||||
//编辑状态,已选择的就是全部
|
||||
labelListData.value=res.lables;
|
||||
@@ -351,7 +351,7 @@ const loadDiscuss = async () => {
|
||||
discuss.plateId = res.plateId;
|
||||
dialogImageUrl.value = res.cover;
|
||||
perRadio.value = res.permissionType;
|
||||
editForm.permissionUserIds = res.permissionUserIds;
|
||||
|
||||
};
|
||||
//加载文章
|
||||
const loadArticle = async () => {
|
||||
|
||||
Reference in New Issue
Block a user