From 57b95cf3c53c0248355ffa46214224cdba4bf79b Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 13 Feb 2021 15:46:02 +0800 Subject: feat: Add timeline manageable. --- .../Timeline.Tests/IntegratedTests/TimelineTest.cs | 73 +++++++++++++--------- 1 file changed, 45 insertions(+), 28 deletions(-) (limited to 'BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index ec9a6d83..be00b595 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -75,15 +75,6 @@ namespace Timeline.Tests.IntegratedTests await client.TestGetAssertInvalidModelAsync("timelines?visibility=aaa"); } - var testResultRelate = new List(); - var testResultOwn = new List(); - var testResultJoin = new List(); - var testResultOwnPrivate = new List(); - var testResultRelatePublic = new List(); - var testResultRelateRegister = new List(); - var testResultJoinPrivate = new List(); - var testResultPublic = new List(); - { using var client = await CreateClientAsUser(); @@ -91,6 +82,34 @@ namespace Timeline.Tests.IntegratedTests await client.PutTimelineMemberAsync("t1", "user3"); await client.PatchTimelineAsync("@user1", new() { Visibility = TimelineVisibility.Public }); await client.PatchTimelineAsync("t1", new() { Visibility = TimelineVisibility.Register }); + } + + { + using var client = await CreateClientAs(2); + + await client.PutTimelineMemberAsync("@user2", "user3"); + await client.PutTimelineMemberAsync("t2", "user3"); + await client.PatchTimelineAsync("@user2", new() { Visibility = TimelineVisibility.Register }); + await client.PatchTimelineAsync("t2", new() { Visibility = TimelineVisibility.Private }); + } + + { + using var client = await CreateClientAs(3); + await client.PatchTimelineAsync("@user3", new HttpTimelinePatchRequest { Visibility = TimelineVisibility.Private }); + await client.PatchTimelineAsync("t3", new HttpTimelinePatchRequest { Visibility = TimelineVisibility.Register }); + } + + { + var testResultRelate = new List(); + var testResultOwn = new List(); + var testResultJoin = new List(); + var testResultOwnPrivate = new List(); + var testResultRelatePublic = new List(); + var testResultRelateRegister = new List(); + var testResultJoinPrivate = new List(); + var testResultPublic = new List(); + + using var client = await CreateDefaultClient(); { var timeline = await client.GetTimelineAsync("@user1"); @@ -106,15 +125,6 @@ namespace Timeline.Tests.IntegratedTests testResultJoin.Add(timeline); testResultRelateRegister.Add(timeline); } - } - - { - using var client = await CreateClientAs(2); - - await client.PutTimelineMemberAsync("@user2", "user3"); - await client.PutTimelineMemberAsync("t2", "user3"); - await client.PatchTimelineAsync("@user2", new() { Visibility = TimelineVisibility.Register }); - await client.PatchTimelineAsync("t2", new() { Visibility = TimelineVisibility.Private }); { var timeline = await client.GetTimelineAsync("@user2"); @@ -129,12 +139,6 @@ namespace Timeline.Tests.IntegratedTests testResultJoin.Add(timeline); testResultJoinPrivate.Add(timeline); } - } - - { - using var client = await CreateClientAs(3); - await client.PatchTimelineAsync("@user3", new HttpTimelinePatchRequest { Visibility = TimelineVisibility.Private }); - await client.PatchTimelineAsync("t3", new HttpTimelinePatchRequest { Visibility = TimelineVisibility.Register }); { var timeline = await client.GetTimelineAsync("@user3"); @@ -149,10 +153,6 @@ namespace Timeline.Tests.IntegratedTests testResultOwn.Add(timeline); testResultRelateRegister.Add(timeline); } - } - - { - using var client = await CreateDefaultClient(); async Task TestAgainst(string url, List against) { @@ -413,5 +413,22 @@ namespace Timeline.Tests.IntegratedTests timeline.Color.Should().Be("#112233"); } } + + [Theory] + [MemberData(nameof(TimelineNameGeneratorTestData))] + public async Task Get_Manageable(TimelineNameGenerator generator) + { + { + using var client = await CreateClientAsUser(); + var timeline = await client.TestGetAsync($"timelines/{generator(1)}"); + timeline.Manageable.Should().Be(true); + } + + { + using var client = await CreateClientAs(2); + var timeline = await client.TestGetAsync($"timelines/{generator(1)}"); + timeline.Manageable.Should().Be(false); + } + } } } -- cgit v1.2.3 From 2d9ca08366d91c22877cee143f43a062d4efda2d Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 13 Feb 2021 15:57:29 +0800 Subject: feat: Timeline add postable. --- BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs | 4 +++- BackEnd/Timeline/Models/Http/HttpTimeline.cs | 4 +++- BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs') diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index be00b595..e2ce8875 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -416,18 +416,20 @@ namespace Timeline.Tests.IntegratedTests [Theory] [MemberData(nameof(TimelineNameGeneratorTestData))] - public async Task Get_Manageable(TimelineNameGenerator generator) + public async Task Get_Manageable_Postable(TimelineNameGenerator generator) { { using var client = await CreateClientAsUser(); var timeline = await client.TestGetAsync($"timelines/{generator(1)}"); timeline.Manageable.Should().Be(true); + timeline.Postable.Should().Be(true); } { using var client = await CreateClientAs(2); var timeline = await client.TestGetAsync($"timelines/{generator(1)}"); timeline.Manageable.Should().Be(false); + timeline.Postable.Should().Be(false); } } } diff --git a/BackEnd/Timeline/Models/Http/HttpTimeline.cs b/BackEnd/Timeline/Models/Http/HttpTimeline.cs index 8a865f96..e3e46bd5 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimeline.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimeline.cs @@ -10,7 +10,7 @@ namespace Timeline.Models.Http { public HttpTimeline() { } - public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List members, string? color, DateTime createTime, DateTime lastModified, bool isHighlight, bool isBookmark, bool manageable, HttpTimelineLinks links) + public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List members, string? color, DateTime createTime, DateTime lastModified, bool isHighlight, bool isBookmark, bool manageable, bool postable, HttpTimelineLinks links) { UniqueId = uniqueId; Title = title; @@ -26,6 +26,7 @@ namespace Timeline.Models.Http IsHighlight = isHighlight; IsBookmark = isBookmark; Manageable = manageable; + Postable = postable; _links = links; } @@ -80,6 +81,7 @@ namespace Timeline.Models.Http public bool IsBookmark { get; set; } public bool Manageable { get; set; } + public bool Postable { get; set; } #pragma warning disable CA1707 // Identifiers should not contain underscores /// diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs index 8dfd7b8d..e4304311 100644 --- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs @@ -51,6 +51,16 @@ namespace Timeline.Models.Mapper manageable = await _timelineService.HasManagePermission(entity.Id, userId.Value); } + bool postable; + if (userId is null) + { + postable = false; + } + else + { + postable = await _timelineService.IsMemberOf(entity.Id, userId.Value); + } + return new HttpTimeline( uniqueId: entity.UniqueId, title: string.IsNullOrEmpty(entity.Title) ? timelineName : entity.Title, @@ -66,6 +76,7 @@ namespace Timeline.Models.Mapper isHighlight: await _highlightTimelineService.IsHighlightTimeline(entity.Id), isBookmark: userId is not null && await _bookmarkTimelineService.IsBookmark(userId.Value, entity.Id, false, false), manageable: manageable, + postable: postable, 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 }) -- cgit v1.2.3