diff options
author | crupest <crupest@outlook.com> | 2021-02-13 15:46:02 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-13 15:46:02 +0800 |
commit | 4538aa0be40316a967d6fbcbc08bc9670b9bbcf0 (patch) | |
tree | 9a3b573c2325fa500b565f82f734bd7540f765c9 /BackEnd/Timeline/Models/Mapper | |
parent | 01c3c5800f9b8a7b89d98b28ea748d496497c0b2 (diff) | |
download | timeline-4538aa0be40316a967d6fbcbc08bc9670b9bbcf0.tar.gz timeline-4538aa0be40316a967d6fbcbc08bc9670b9bbcf0.tar.bz2 timeline-4538aa0be40316a967d6fbcbc08bc9670b9bbcf0.zip |
feat: Add timeline manageable.
Diffstat (limited to 'BackEnd/Timeline/Models/Mapper')
-rw-r--r-- | BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 22 |
1 files changed, 19 insertions, 3 deletions
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<HttpTimeline> MapToHttp(TimelineEntity entity, IUrlHelper urlHelper, long? userId)
+ public async Task<HttpTimeline> 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<List<HttpTimeline>> MapToHttp(List<TimelineEntity> entities, IUrlHelper urlHelper, long? userId)
+ public async Task<List<HttpTimeline>> MapToHttp(List<TimelineEntity> entities, IUrlHelper urlHelper, long? userId, bool isAdministrator)
{
var result = new List<HttpTimeline>();
foreach (var entity in entities)
{
- result.Add(await MapToHttp(entity, urlHelper, userId));
+ result.Add(await MapToHttp(entity, urlHelper, userId, isAdministrator));
}
return result;
}
|