From 4538aa0be40316a967d6fbcbc08bc9670b9bbcf0 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 13 Feb 2021 15:46:02 +0800 Subject: feat: Add timeline manageable. --- BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'BackEnd/Timeline/Models/Mapper/TimelineMapper.cs') diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs index 191e2f70..8dfd7b8d 100644 --- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs @@ -29,13 +29,28 @@ namespace Timeline.Models.Mapper _timelinePostService = timelinePostService; } - public async Task MapToHttp(TimelineEntity entity, IUrlHelper urlHelper, long? userId) + public async Task MapToHttp(TimelineEntity entity, IUrlHelper urlHelper, long? userId, bool isAdministrator) { await _database.Entry(entity).Reference(e => e.Owner).LoadAsync(); await _database.Entry(entity).Collection(e => e.Members).Query().Include(m => m.User).LoadAsync(); var timelineName = entity.Name is null ? "@" + entity.Owner.Username : entity.Name; + bool manageable; + + if (userId is null) + { + manageable = false; + } + else if (isAdministrator) + { + manageable = true; + } + else + { + manageable = await _timelineService.HasManagePermission(entity.Id, userId.Value); + } + return new HttpTimeline( uniqueId: entity.UniqueId, title: string.IsNullOrEmpty(entity.Title) ? timelineName : entity.Title, @@ -50,6 +65,7 @@ namespace Timeline.Models.Mapper lastModified: entity.LastModified, isHighlight: await _highlightTimelineService.IsHighlightTimeline(entity.Id), isBookmark: userId is not null && await _bookmarkTimelineService.IsBookmark(userId.Value, entity.Id, false, false), + manageable: manageable, links: new HttpTimelineLinks( self: urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { timeline = timelineName }), posts: urlHelper.ActionLink(nameof(TimelinePostController.List), nameof(TimelinePostController)[0..^nameof(Controller).Length], new { timeline = timelineName }) @@ -57,12 +73,12 @@ namespace Timeline.Models.Mapper ); } - public async Task> MapToHttp(List entities, IUrlHelper urlHelper, long? userId) + public async Task> MapToHttp(List entities, IUrlHelper urlHelper, long? userId, bool isAdministrator) { var result = new List(); foreach (var entity in entities) { - result.Add(await MapToHttp(entity, urlHelper, userId)); + result.Add(await MapToHttp(entity, urlHelper, userId, isAdministrator)); } return result; } -- cgit v1.2.3