aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Models/Mapper
diff options
context:
space:
mode:
Diffstat (limited to 'BackEnd/Timeline/Models/Mapper')
-rw-r--r--BackEnd/Timeline/Models/Mapper/TimelineMapper.cs22
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;
}