Skip to content
This repository has been archived by the owner on Oct 23, 2021. It is now read-only.

CA 851 - instagram on home/crowdaction pages #407

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9fa468b
Instagram module
JBijker Jun 10, 2020
7a88802
Backend for instagram API + image proxy
timstokman Jun 12, 2020
d89e0ae
instagram wall for root queries as well
timstokman Jun 12, 2020
6d28d93
Display instagram wall using new api
timstokman Jun 12, 2020
8a0b344
Seed instagram users better
timstokman Jun 12, 2020
6e19ec4
Fix insta display issues
timstokman Jun 12, 2020
7936703
Allow editting instagram in admin ui
timstokman Jun 12, 2020
0193252
Add instagram user to start project form
timstokman Jun 12, 2020
0c028b1
tweak submit
timstokman Jun 12, 2020
c10f881
Add id for caching, add last-modified for caching
timstokman Jun 12, 2020
26b7b04
Formattnig differently
timstokman Jun 12, 2020
b97181d
Add debug logging why json is failing
timstokman Jun 12, 2020
0af0aa5
Better logging..
timstokman Jun 12, 2020
487aacd
To loginfo so it doesn't get lost
timstokman Jun 12, 2020
8e08a16
Only debug logging
timstokman Jun 12, 2020
05da497
Add cndinstagram to allowed proxy hosts
timstokman Jun 13, 2020
6dceedf
Caching timeout a little higher
timstokman Jun 14, 2020
59e78fa
Exclude test in github actions because instagram is blocked
timstokman Jun 14, 2020
2eea786
Add comment why we're skipping
timstokman Jun 14, 2020
f40a98c
Add more cdns
timstokman Jun 14, 2020
6c4a01a
Tweak comments
timstokman Jun 14, 2020
85be25e
Enable range processing for proxying videos
timstokman Jun 14, 2020
6d9902d
Code review comments
Jun 15, 2020
857f461
Naming
Jun 15, 2020
5ca92e7
Merge master
timstokman Jul 10, 2020
8f52720
Merge branch 'CA-851' of https://github.com/CollActionteam/CollAction…
timstokman Jul 10, 2020
6227924
Fix build issues
timstokman Jul 10, 2020
a767f4e
Merge master
timstokman Jul 12, 2020
746b502
Merge branch 'master' into CA-851
timstokman Aug 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CollAction.Tests/Integration/Endpoint/GraphQlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GraphQlTests()
[Fact]
public async Task TestCrowdactionList()
{
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null, null, null, null, new[] { Category.Community }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, CrowdactionStatus.Running, 0, null);
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null, null, null, null, null, new[] { Category.Community }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, CrowdactionStatus.Running, 0, null);
Crowdaction createdCrowdaction = await crowdactionService.CreateCrowdactionInternal(newCrowdaction, CancellationToken.None).ConfigureAwait(false);
Assert.NotNull(createdCrowdaction);

Expand Down
11 changes: 6 additions & 5 deletions CollAction.Tests/Integration/Service/CrowdactionServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task TestCrowdactionCreate()
public async Task TestCrowdactionUpdate()
{
var user = await context.Users.FirstAsync().ConfigureAwait(false);
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null, null, null, null, new[] { Category.Community }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, CrowdactionStatus.Running, 0, user.Id);
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null, null, null, null, null, new[] { Category.Community }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, CrowdactionStatus.Running, 0, user.Id);
Crowdaction crowdaction = await crowdactionService.CreateCrowdactionInternal(newCrowdaction, CancellationToken.None).ConfigureAwait(false);
Assert.NotNull(crowdaction);

Expand Down Expand Up @@ -117,7 +117,7 @@ public async Task TestCrowdactionUpdate()
[Fact]
public async Task TestCommentCreate()
{
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null, null, null, null, new[] { Category.Community }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, CrowdactionStatus.Running, 0, null);
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null, null, null, null, null, new[] { Category.Community }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, CrowdactionStatus.Running, 0, null);
Crowdaction crowdaction = await crowdactionService.CreateCrowdactionInternal(newCrowdaction, CancellationToken.None).ConfigureAwait(false);
Assert.NotNull(crowdaction);

Expand All @@ -143,7 +143,7 @@ public async Task TestCrowdactionCommitAnonymous()
{
// Setup
var user = await context.Users.FirstAsync().ConfigureAwait(false);
Crowdaction crowdaction = new Crowdaction($"test-{Guid.NewGuid()}", CrowdactionStatus.Running, user.Id, 10, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), "t", "t", "t", null, null);
Crowdaction crowdaction = new Crowdaction($"test-{Guid.NewGuid()}", CrowdactionStatus.Running, user.Id, 10, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), "t", "t", "t", "t", null, null);
context.Crowdactions.Add(crowdaction);
await context.SaveChangesAsync().ConfigureAwait(false);

Expand All @@ -161,7 +161,7 @@ public async Task TestCrowdactionCommitLoggedIn()
// Setup
var user = await context.Users.FirstAsync().ConfigureAwait(false);
var userClaim = await signInManager.CreateUserPrincipalAsync(user).ConfigureAwait(false);
var crowdaction = new Crowdaction($"test-{Guid.NewGuid()}", CrowdactionStatus.Running, user.Id, 10, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), "t", "t", "t", null, null);
var crowdaction = new Crowdaction($"test-{Guid.NewGuid()}", CrowdactionStatus.Running, user.Id, 10, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), "t", "t", "t", "t", null, null);
context.Crowdactions.Add(crowdaction);
await context.SaveChangesAsync().ConfigureAwait(false);

Expand All @@ -187,6 +187,7 @@ public async Task TestCrowdactionEmail()
start: DateTime.Now.AddDays(-10),
end: DateTime.Now.AddDays(30),
goal: Guid.NewGuid().ToString(),
instagramUser: "test",
creatorComments: Guid.NewGuid().ToString(),
proposal: Guid.NewGuid().ToString(),
target: 40,
Expand Down Expand Up @@ -217,7 +218,7 @@ public async Task TestCrowdactionSearch()
Category searchCategory = (Category)r.Next(7);
for (int i = 0; i < r.Next(10, 30); i++)
{
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow.AddDays(r.Next(-20, 20)), DateTime.UtcNow.AddDays(r.Next(21, 50)), null, null, null, null, new[] { searchCategory }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, (CrowdactionStatus)r.Next(3), 0, null);
var newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow.AddDays(r.Next(-20, 20)), DateTime.UtcNow.AddDays(r.Next(21, 50)), null, null, null, null, null, new[] { searchCategory }, Array.Empty<string>(), CrowdactionDisplayPriority.Bottom, (CrowdactionStatus)r.Next(3), 0, null);
Crowdaction crowdaction = await crowdactionService.CreateCrowdactionInternal(newCrowdaction, CancellationToken.None).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
namespace CollAction.Tests.Integration.Service
{
[Trait("Category", "Integration")]
public sealed class ImageServicesTests : IntegrationTestBase
public sealed class ImageServiceTests : IntegrationTestBase
{
private readonly byte[] testImage = new byte[] { 0x42, 0x4D, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0xFF, 0x00 };
private readonly MemoryStream imageMs;
private readonly IImageService imageService;
private readonly Mock<IFormFile> upload;

public ImageServicesTests() : base(false)
public ImageServiceTests() : base(false)
{
imageMs = new MemoryStream(testImage);
imageService = Scope.ServiceProvider.GetRequiredService<IImageService>();
Expand Down
29 changes: 29 additions & 0 deletions CollAction.Tests/Integration/Service/InstagramServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CollAction.Services.Instagram;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace CollAction.Tests.Integration.Service
{
[Trait("Category", "Integration")]
public sealed class InstagramServiceTests : IntegrationTestBase
{
private readonly IInstagramService instagramService;

public InstagramServiceTests(): base(false)
{
instagramService = Scope.ServiceProvider.GetRequiredService<IInstagramService>();
}

[Fact]
public async Task TestInstagramApi()
{
var result = await instagramService.GetItems("slowfashionseason", CancellationToken.None).ConfigureAwait(false);
Assert.True(result.Any());
}
}
}
2 changes: 1 addition & 1 deletion CollAction.Tests/Integration/Service/UserServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task TestUserManagement()
public async Task TestFinishRegistration()
{
// Setup
var crowdaction = new Crowdaction($"test-{Guid.NewGuid()}", CrowdactionStatus.Running, await context.Users.Select(u => u.Id).FirstAsync().ConfigureAwait(false), 10, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), "t", "t", "t", null, null);
var crowdaction = new Crowdaction($"test-{Guid.NewGuid()}", CrowdactionStatus.Running, await context.Users.Select(u => u.Id).FirstAsync().ConfigureAwait(false), 10, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), "t", "t", "t", "t", null, null);
context.Crowdactions.Add(crowdaction);
await context.SaveChangesAsync().ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion CollAction/Controllers/GraphQlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private async Task<ExecutionResult> Execute(string query, string? operationName,
UserContext = new UserContext(User, context, serviceProvider),
ComplexityConfiguration = new ComplexityConfiguration()
{
MaxDepth = 20
MaxDepth = 21
timstokman marked this conversation as resolved.
Show resolved Hide resolved
},
ValidationRules = validationRules,
CancellationToken = cancellation,
Expand Down
24 changes: 24 additions & 0 deletions CollAction/Controllers/ProxyController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using CollAction.Services.Proxy;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace CollAction.Controllers
{
[Route("proxy")]
[ApiController]
public sealed class ProxyController
{
private readonly IProxyService proxyService;

public ProxyController(IProxyService proxyService)
{
this.proxyService = proxyService;
}

[HttpGet]
public Task<IActionResult> Proxy(Uri url, CancellationToken token)
=> proxyService.Proxy(url, token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public NewCrowdactionInputGraph()
Field(x => x.CreatorComments, true);
Field(x => x.Start);
Field(x => x.End);
Field(x => x.InstagramUser, true);
Field(x => x.BannerImageFileId, true);
Field(x => x.CardImageFileId, true);
Field(x => x.DescriptiveImageFileId, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public UpdatedCrowdactionInputGraph()
Field(x => x.BannerImageFileId, true);
Field(x => x.CardImageFileId, true);
Field(x => x.DescriptiveImageFileId, true);
Field(x => x.InstagramUser, true);
Field(x => x.DescriptionVideoLink, true);
Field(x => x.Tags);
Field(x => x.DisplayPriority);
Expand Down
2 changes: 1 addition & 1 deletion CollAction/GraphQl/Queries/CrowdactionCommentGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CollAction.GraphQl.Queries
{
public class CrowdactionCommentGraph : EfObjectGraphType<ApplicationDbContext, CrowdactionComment>
public sealed class CrowdactionCommentGraph : EfObjectGraphType<ApplicationDbContext, CrowdactionComment>
{
public CrowdactionCommentGraph(IEfGraphQLService<ApplicationDbContext> graphService) : base(graphService)
{
Expand Down
23 changes: 23 additions & 0 deletions CollAction/GraphQl/Queries/CrowdactionGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
using CollAction.Helpers;
using CollAction.Models;
using CollAction.Services.Crowdactions;
using CollAction.Services.Instagram;
using CollAction.Services.Instagram.Models;
using GraphQL.Authorization;
using GraphQL.EntityFramework;
using GraphQL.Types;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CollAction.GraphQl.Queries
{
Expand All @@ -30,6 +35,7 @@ public CrowdactionGraph(IEfGraphQLService<ApplicationDbContext> entityFrameworkG
Field(x => x.IsComingSoon);
Field(x => x.Name);
Field(x => x.NumberCrowdactionEmailsSent);
Field(x => x.InstagramUser, true);
Field<IdGraphType, string?>(nameof(Crowdaction.OwnerId)).Resolve(x => x.Source.OwnerId);
Field(x => x.Proposal);
Field(x => x.RemainingTime);
Expand Down Expand Up @@ -98,6 +104,23 @@ public CrowdactionGraph(IEfGraphQLService<ApplicationDbContext> entityFrameworkG

return c.Source.Percentage;
});
FieldAsync<NonNullGraphType<ListGraphType<NonNullGraphType<InstagramWallItemGraph>>>, IEnumerable<InstagramWallItem>>(
"instagramWall",
resolve: c =>
{
string? instagramUser = c.Source.InstagramUser;
if (instagramUser != null)
{
return c.GetUserContext()
.ServiceProvider
.GetRequiredService<IInstagramService>()
.GetItems(instagramUser, c.CancellationToken);
}
else
{
return Task.FromResult(Enumerable.Empty<InstagramWallItem>());
timstokman marked this conversation as resolved.
Show resolved Hide resolved
}
});
AddNavigationField(nameof(Crowdaction.DescriptiveImage), c => c.Source.DescriptiveImage);
AddNavigationField(nameof(Crowdaction.BannerImage), c => c.Source.BannerImage);
AddNavigationField(nameof(Crowdaction.CardImage), c => c.Source.CardImage);
Expand Down
19 changes: 19 additions & 0 deletions CollAction/GraphQl/Queries/InstagramWallItemGraph.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CollAction.Services.Instagram.Models;
using GraphQL.Types;

namespace CollAction.GraphQl.Queries
{
public sealed class InstagramWallItemGraph : ObjectGraphType<InstagramWallItem>
{
public InstagramWallItemGraph()
{
Field<IdGraphType>("id", resolve: x => x.Source.ShortCode);
Field(x => x.ShortCode);
Field(x => x.Link);
Field(x => x.Date);
Field(x => x.AccessibilityCaption, true);
Field(x => x.Caption, true);
Field(x => x.ThumbnailSrc);
}
}
}
16 changes: 16 additions & 0 deletions CollAction/GraphQl/Queries/QueryGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
using CollAction.Helpers;
using CollAction.Models;
using CollAction.Services.Crowdactions;
using CollAction.Services.Instagram;
using CollAction.Services.Instagram.Models;
using GraphQL.Authorization;
using GraphQL.EntityFramework;
using GraphQL.Types;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace CollAction.GraphQl.Queries
{
Expand Down Expand Up @@ -119,6 +123,18 @@ public QueryGraph(IEfGraphQLService<ApplicationDbContext> entityFrameworkGraphQl
c => c.DbContext.Users,
typeof(ApplicationUserGraph)).AuthorizeWith(AuthorizationConstants.GraphQlAdminPolicy);

FieldAsync<NonNullGraphType<ListGraphType<NonNullGraphType<InstagramWallItemGraph>>>, IEnumerable<InstagramWallItem>>(
"instagramWall",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<StringGraphType>>() { Name = "user" }),
resolve: c =>
{
string instagramUser = c.GetArgument<string>("user");
return c.GetUserContext()
.ServiceProvider
.GetRequiredService<IInstagramService>()
.GetItems(instagramUser, c.CancellationToken);
});

AddSingleField(
name: "user",
resolve: c => c.DbContext.Users,
Expand Down
Loading