Browse Source

Remove referrer

pull/906/head
Sebastian 4 years ago
parent
commit
46cfaada50
  1. 2
      backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/ChangePlan.cs
  2. 8
      backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs
  3. 6
      backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/IAppPlanBillingManager.cs
  4. 6
      backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/NoopAppPlanBillingManager.cs
  5. 2
      backend/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs
  6. 4
      backend/src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs
  7. 28
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs
  8. 6
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/NoopAppPlanBillingManagerTests.cs

2
backend/src/Squidex.Domain.Apps.Entities/Apps/Commands/ChangePlan.cs

@ -12,7 +12,5 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands
public bool FromCallback { get; set; }
public string PlanId { get; set; }
public string Referer { get; set; }
}
}

8
backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs

@ -258,7 +258,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
case DeleteApp delete:
return UpdateAsync(delete, async (c, ct) =>
{
await Billing().SubscribeAsync(c.Actor.Identifier, Snapshot.NamedId(), null, null, ct);
await Billing().UnsubscribeAsync(c.Actor.Identifier, Snapshot.NamedId(), default);
DeleteApp(c);
}, ct);
@ -290,7 +290,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
if (!c.FromCallback)
{
var redirectUri = await Billing().MustRedirectToPortalAsync(userId, Snapshot.NamedId(), c.PlanId, c.Referer, default);
var redirectUri = await Billing().MustRedirectToPortalAsync(userId, Snapshot.NamedId(), c.PlanId, default);
if (redirectUri != null)
{
@ -310,11 +310,11 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
if (result.Payload is PlanChangedResult { Unsubscribed: true, RedirectUri: null })
{
await Billing().UnsubscribeAsync(userId, Snapshot.NamedId(), changePlan.Referer, default);
await Billing().UnsubscribeAsync(userId, Snapshot.NamedId(), default);
}
else if (result.Payload is PlanChangedResult { RedirectUri: null })
{
await Billing().SubscribeAsync(userId, Snapshot.NamedId(), changePlan.PlanId, changePlan.Referer);
await Billing().SubscribeAsync(userId, Snapshot.NamedId(), changePlan.PlanId, default);
}
return result;

6
backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/IAppPlanBillingManager.cs

@ -13,13 +13,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
{
bool HasPortal { get; }
Task<Uri?> MustRedirectToPortalAsync(string userId, NamedId<DomainId> appId, string? planId, string? referer,
Task<Uri?> MustRedirectToPortalAsync(string userId, NamedId<DomainId> appId, string? planId,
CancellationToken ct = default);
Task SubscribeAsync(string userId, NamedId<DomainId> appId, string? planId, string? referer,
Task SubscribeAsync(string userId, NamedId<DomainId> appId, string planId,
CancellationToken ct = default);
Task UnsubscribeAsync(string userId, NamedId<DomainId> appId, string? referer,
Task UnsubscribeAsync(string userId, NamedId<DomainId> appId,
CancellationToken ct = default);
Task<string> GetPortalLinkAsync(string userId,

6
backend/src/Squidex.Domain.Apps.Entities/Apps/Plans/NoopAppPlanBillingManager.cs

@ -22,19 +22,19 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
return Task.FromResult(string.Empty);
}
public Task<Uri?> MustRedirectToPortalAsync(string userId, NamedId<DomainId> appId, string? planId, string? referer,
public Task<Uri?> MustRedirectToPortalAsync(string userId, NamedId<DomainId> appId, string? planId,
CancellationToken ct = default)
{
return Task.FromResult<Uri?>(null);
}
public Task SubscribeAsync(string userId, NamedId<DomainId> appId, string? planId, string? referer,
public Task SubscribeAsync(string userId, NamedId<DomainId> appId, string planId,
CancellationToken ct = default)
{
return Task.CompletedTask;
}
public Task UnsubscribeAsync(string userId, NamedId<DomainId> appId, string? referer,
public Task UnsubscribeAsync(string userId, NamedId<DomainId> appId,
CancellationToken ct = default)
{
return Task.CompletedTask;

2
backend/src/Squidex/Areas/Api/Controllers/Plans/AppPlansController.cs

@ -77,7 +77,7 @@ namespace Squidex.Areas.Api.Controllers.Plans
[ApiCosts(0)]
public async Task<IActionResult> PutPlan(string app, [FromBody] ChangePlanDto request)
{
var context = await CommandBus.PublishAsync(request.ToCommand(HttpContext), HttpContext.RequestAborted);
var context = await CommandBus.PublishAsync(request.ToCommand(), HttpContext.RequestAborted);
string? redirectUri = null;

4
backend/src/Squidex/Areas/Api/Controllers/Plans/Models/ChangePlanDto.cs

@ -19,12 +19,10 @@ namespace Squidex.Areas.Api.Controllers.Plans.Models
[LocalizedRequired]
public string PlanId { get; set; }
public ChangePlan ToCommand(HttpContext httpContext)
public ChangePlan ToCommand()
{
var result = SimpleMapper.Map(this, new ChangePlan());
result.Referer = httpContext.Request.Headers["Referer"];
return result;
}
}

28
backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs

@ -59,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
A.CallTo(() => appPlansProvider.GetPlan(planIdPaid))
.Returns(new ConfigAppLimitsPlan { Id = planIdPaid, MaxContributors = 30 });
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, A<string>._, A<string>._, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, A<string>._, default))
.Returns(Task.FromResult<Uri?>(null));
// Create a non-empty setting, otherwise the event is not raised as it does not change the domain object.
@ -220,7 +220,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
{
var command = new ChangePlan { PlanId = planIdPaid };
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default))
.Returns(Task.FromResult<Uri?>(null));
await ExecuteCreateAsync();
@ -236,10 +236,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
CreateEvent(new AppPlanChanged { PlanId = planIdPaid })
);
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default))
.MustHaveHappened();
A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default))
A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, default))
.MustHaveHappened();
}
@ -261,10 +261,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
CreateEvent(new AppPlanChanged { PlanId = planIdPaid })
);
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<string?>._, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<CancellationToken>._))
.MustNotHaveHappened();
A.CallTo(() => appPlansBillingManager.SubscribeAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<string?>._, A<CancellationToken>._))
A.CallTo(() => appPlansBillingManager.SubscribeAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<CancellationToken>._))
.MustNotHaveHappened();
}
@ -287,10 +287,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
CreateEvent(new AppPlanReset())
);
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<string?>._, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<CancellationToken>._))
.MustHaveHappenedOnceExactly();
A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<CancellationToken>._))
A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A<string>._, A<NamedId<DomainId>>._, A<CancellationToken>._))
.MustNotHaveHappened();
}
@ -313,10 +313,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
CreateEvent(new AppPlanReset())
);
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default))
.MustHaveHappenedOnceExactly();
A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A<string>._, A<NamedId<DomainId>>._, A<string?>._, A<CancellationToken>._))
A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(A<string>._, A<NamedId<DomainId>>._, A<CancellationToken>._))
.MustHaveHappened();
}
@ -325,7 +325,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
{
var command = new ChangePlan { PlanId = planIdPaid };
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, default))
.Returns(new Uri("http://squidex.io"));
await ExecuteCreateAsync();
@ -350,10 +350,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
Assert.Equal(planIdPaid, sut.Snapshot.Plan?.PlanId);
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, command.Referer, default))
A.CallTo(() => appPlansBillingManager.MustRedirectToPortalAsync(Actor.Identifier, AppNamedId, planIdPaid, A<CancellationToken>._))
.MustNotHaveHappened();
A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, A<string?>._, default))
A.CallTo(() => appPlansBillingManager.SubscribeAsync(Actor.Identifier, AppNamedId, planIdPaid, A<CancellationToken>._))
.MustNotHaveHappened();
}
@ -668,7 +668,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.DomainObject
CreateEvent(new AppDeleted())
);
A.CallTo(() => appPlansBillingManager.SubscribeAsync(command.Actor.Identifier, AppNamedId, null, A<string?>._, default))
A.CallTo(() => appPlansBillingManager.UnsubscribeAsync(command.Actor.Identifier, AppNamedId, default))
.MustHaveHappened();
}

6
backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Plans/NoopAppPlanBillingManagerTests.cs

@ -22,13 +22,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
[Fact]
public async Task Should_do_nothing_if_subscribing()
{
await sut.SubscribeAsync(null!, null!, null, null);
await sut.SubscribeAsync(null!, null!, null!);
}
[Fact]
public async Task Should_do_nothing_if_unsubscribing()
{
await sut.SubscribeAsync(null!, null!, null, null);
await sut.UnsubscribeAsync(null!, null!);
}
[Fact]
@ -42,7 +42,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Plans
[Fact]
public async Task Should_do_nothing_if_checking_for_redirect()
{
var result = await sut.MustRedirectToPortalAsync(null!, null!, null, null);
var result = await sut.MustRedirectToPortalAsync(null!, null!, null);
Assert.Null(result);
}

Loading…
Cancel
Save