Browse Source

Query correct plan when checking for contributors.

pull/942/head
Sebastian 4 years ago
parent
commit
6dcbc319ee
  1. 14
      backend/src/Squidex.Domain.Apps.Entities/Apps/DomainObject/AppDomainObject.cs
  2. 2
      backend/src/Squidex.Infrastructure/Commands/InMemoryCommandBus.cs
  3. 18
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DomainObject/AppDomainObjectTests.cs

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

@ -128,7 +128,9 @@ public partial class AppDomainObject : DomainObject<AppDomainObject.State>
case AssignContributor assignContributor:
return UpdateReturnAsync(assignContributor, async (c, ct) =>
{
await GuardAppContributors.CanAssign(c, Snapshot, Users, Plan);
var (plan, _, _) = await UsageGate.GetPlanForAppAsync(Snapshot, false, ct);
await GuardAppContributors.CanAssign(c, Snapshot, Users, plan);
AssignContributor(c, !Snapshot.Contributors.ContainsKey(assignContributor.ContributorId));
@ -480,6 +482,11 @@ public partial class AppDomainObject : DomainObject<AppDomainObject.State>
get => serviceProvider.GetRequiredService<IBillingManager>();
}
private IUsageGate UsageGate
{
get => serviceProvider.GetRequiredService<IUsageGate>();
}
private IUserResolver Users
{
get => serviceProvider.GetRequiredService<IUserResolver>();
@ -489,9 +496,4 @@ public partial class AppDomainObject : DomainObject<AppDomainObject.State>
{
get => BillingPlans.GetFreePlan();
}
private Plan Plan
{
get => BillingPlans.GetActualPlan(Snapshot.Plan?.PlanId).Plan;
}
}

2
backend/src/Squidex.Infrastructure/Commands/InMemoryCommandBus.cs

@ -17,7 +17,7 @@ public sealed class InMemoryCommandBus : ICommandBus
NextDelegate next = (c, ct) => Task.CompletedTask;
foreach (var middleware in middlewares.Reverse())
foreach (var middleware in reverseMiddlewares)
{
next = Create(next, middleware);
}

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

@ -30,6 +30,7 @@ public class AppDomainObjectTests : HandlerTestBase<AppDomainObject.State>
private readonly IBillingManager billingManager = A.Fake<IBillingManager>();
private readonly IUser user;
private readonly IUserResolver userResolver = A.Fake<IUserResolver>();
private readonly IUsageGate usageGate = A.Fake<IUsageGate>();
private readonly string contributorId = DomainId.NewGuid().ToString();
private readonly string clientId = "client";
private readonly string clientNewName = "My Client";
@ -53,14 +54,14 @@ public class AppDomainObjectTests : HandlerTestBase<AppDomainObject.State>
A.CallTo(() => userResolver.FindByIdOrEmailAsync(contributorId, default))
.Returns(user);
A.CallTo(() => billingPlans.GetFreePlan())
.Returns(new Plan { Id = planIdFree, MaxContributors = 10 });
A.CallTo(() => usageGate.GetPlanForAppAsync(A<IAppEntity>.That.Matches(x => x.Plan != null && x.Plan.PlanId == planIdFree), false, default))
.Returns((new Plan { Id = planIdFree, MaxContributors = 10 }, planIdFree, null));
A.CallTo(() => billingPlans.GetPlan(planIdFree))
.Returns(new Plan { Id = planIdFree, MaxContributors = 10 });
A.CallTo(() => usageGate.GetPlanForAppAsync(A<IAppEntity>.That.Matches(x => x.Plan != null && x.Plan.PlanId == planIdPaid), false, default))
.Returns((new Plan { Id = planIdPaid, MaxContributors = 30 }, planIdPaid, null));
A.CallTo(() => billingPlans.GetPlan(planIdPaid))
.Returns(new Plan { Id = planIdPaid, MaxContributors = 30 });
A.CallTo(() => billingPlans.GetFreePlan())
.Returns(new Plan { Id = planIdFree, MaxContributors = 10 });
A.CallTo(() => billingManager.MustRedirectToPortalAsync(Actor.Identifier, A<IAppEntity>._, A<string>._, default))
.Returns(Task.FromResult<Uri?>(null));
@ -80,9 +81,10 @@ public class AppDomainObjectTests : HandlerTestBase<AppDomainObject.State>
var serviceProvider =
new ServiceCollection()
.AddSingleton(appProvider)
.AddSingleton(initialSettings)
.AddSingleton(billingPlans)
.AddSingleton(billingManager)
.AddSingleton(billingPlans)
.AddSingleton(initialSettings)
.AddSingleton(usageGate)
.AddSingleton(userResolver)
.BuildServiceProvider();

Loading…
Cancel
Save