forked from xiongyuxing/tiku-backend.net
refactor: consolidate backend into modular monolith
This commit is contained in:
@@ -47,8 +47,6 @@ using Tiku.Infrastructure.TenantAdmin;
|
||||
using Tiku.Infrastructure.Tenancy;
|
||||
using Tiku.Domain.Identity;
|
||||
using StackExchange.Redis;
|
||||
using MassTransit;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
using Tiku.Infrastructure.Observability;
|
||||
|
||||
namespace Tiku.Infrastructure;
|
||||
@@ -93,7 +91,6 @@ public static class DependencyInjection
|
||||
services.Configure<PasswordHasherOptions>(options => options.IterationCount = 210_000);
|
||||
services.AddScoped<ITenantDirectory, TenantDirectory>();
|
||||
services.AddSingleton<IRedisSecurityStore, NullRedisSecurityStore>();
|
||||
services.AddScoped<ISecurityEventPublisher, NullSecurityEventPublisher>();
|
||||
services.AddMemoryCache();
|
||||
services.AddScoped<ITenantFrontendConfigService, TenantFrontendConfigService>();
|
||||
services.AddScoped<ITenantExternalProviderConfigService, TenantExternalProviderConfigService>();
|
||||
@@ -151,12 +148,10 @@ public static class DependencyInjection
|
||||
services.AddScoped<ITenantFeatureSnapshotProvider, TenantFeatureSnapshotProvider>();
|
||||
services.AddSingleton<TenantFeatureCacheInvalidator>();
|
||||
services.AddSingleton<ITenantFeatureCacheInvalidator>(provider => provider.GetRequiredService<TenantFeatureCacheInvalidator>());
|
||||
services.AddHostedService(provider => provider.GetRequiredService<TenantFeatureCacheInvalidator>());
|
||||
services.AddScoped<IFeatureAccessService, FeatureAccessService>();
|
||||
services.AddScoped<IFeatureUsageReconciliationService, FeatureUsageReconciliationService>();
|
||||
services.AddOptions<FeatureUsageReconciliationOptions>();
|
||||
services.AddScoped<IOperationAuditService, OperationAuditService>();
|
||||
services.AddSingleton<IBackgroundJobDispatcher, NullBackgroundJobDispatcher>();
|
||||
services.AddScoped<IBackgroundJobService, BackgroundJobService>();
|
||||
services.AddScoped<ICommerceService, CommerceService>();
|
||||
services.AddScoped<ICommerceAdminService, CommerceAdminService>();
|
||||
@@ -205,65 +200,4 @@ public static class DependencyInjection
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddReliableMessaging(
|
||||
this IServiceCollection services,
|
||||
MessagingOptions options)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
if (!options.IsConfigured)
|
||||
{
|
||||
throw new ArgumentException("A valid RabbitMQ host URI is required.", nameof(options));
|
||||
}
|
||||
|
||||
services.AddMassTransit(registration =>
|
||||
{
|
||||
registration.SetKebabCaseEndpointNameFormatter();
|
||||
registration.ConfigureHealthCheckOptions(health =>
|
||||
{
|
||||
health.Name = "rabbitmq";
|
||||
health.Tags.Add("ready");
|
||||
});
|
||||
registration.AddEntityFrameworkOutbox<TikuDbContext>(outbox =>
|
||||
{
|
||||
outbox.UsePostgres();
|
||||
outbox.UseBusOutbox();
|
||||
outbox.QueryDelay = TimeSpan.FromSeconds(1);
|
||||
outbox.DuplicateDetectionWindow = TimeSpan.FromMinutes(30);
|
||||
});
|
||||
if (options.ConfigureConsumers)
|
||||
{
|
||||
registration.AddConsumer<SecurityStateChangedConsumer>(consumer =>
|
||||
{
|
||||
consumer.ConcurrentMessageLimit = 1;
|
||||
consumer.UseMessageRetry(retry => retry.Intervals(
|
||||
TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15)));
|
||||
});
|
||||
registration.AddConsumer<BackgroundJobRequestedConsumer>(consumer =>
|
||||
{
|
||||
consumer.ConcurrentMessageLimit = 1;
|
||||
consumer.UseMessageRetry(retry => retry.Intervals(
|
||||
TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15)));
|
||||
});
|
||||
registration.AddConfigureEndpointsCallback((context, _, endpoint) =>
|
||||
{
|
||||
endpoint.PrefetchCount = 1;
|
||||
endpoint.ConcurrentMessageLimit = 1;
|
||||
endpoint.UseEntityFrameworkOutbox<TikuDbContext>(context);
|
||||
});
|
||||
}
|
||||
|
||||
registration.UsingRabbitMq((context, configurator) =>
|
||||
{
|
||||
configurator.Host(new Uri(options.Host), options.VirtualHost, host =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(options.Username)) host.Username(options.Username);
|
||||
if (!string.IsNullOrWhiteSpace(options.Password)) host.Password(options.Password);
|
||||
});
|
||||
configurator.ConfigureEndpoints(context);
|
||||
});
|
||||
});
|
||||
services.AddScoped<ISecurityEventPublisher, MassTransitSecurityEventPublisher>();
|
||||
services.AddScoped<IBackgroundJobDispatcher, MassTransitBackgroundJobDispatcher>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@ namespace Tiku.Infrastructure.Jobs;
|
||||
internal sealed class BackgroundJobService(
|
||||
TikuDbContext dbContext,
|
||||
ITenantExecutionScope tenantExecutionScope,
|
||||
IFeatureAccessService featureAccessService,
|
||||
IBackgroundJobDispatcher backgroundJobDispatcher) : IBackgroundJobService
|
||||
IFeatureAccessService featureAccessService) : IBackgroundJobService
|
||||
{
|
||||
private static readonly TimeSpan LeaseDuration = TimeSpan.FromMinutes(5);
|
||||
|
||||
@@ -71,15 +70,6 @@ internal sealed class BackgroundJobService(
|
||||
}
|
||||
throw;
|
||||
}
|
||||
if (job.RunAfter is null && backgroundJobDispatcher.IsEnabled)
|
||||
{
|
||||
await backgroundJobDispatcher.DispatchAsync(
|
||||
job.Id,
|
||||
job.TenantId,
|
||||
job.JobType,
|
||||
job.Id.ToString("N"),
|
||||
cancellationToken);
|
||||
}
|
||||
return ToItem(job);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using MassTransit;
|
||||
using Tiku.Application.Jobs;
|
||||
using Tiku.Contracts;
|
||||
|
||||
namespace Tiku.Infrastructure.Messaging;
|
||||
|
||||
internal sealed class NullBackgroundJobDispatcher : IBackgroundJobDispatcher
|
||||
{
|
||||
public bool IsEnabled => false;
|
||||
|
||||
public Task DispatchAsync(
|
||||
Guid jobId,
|
||||
Guid tenantId,
|
||||
string jobType,
|
||||
string correlationId,
|
||||
CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal sealed class MassTransitBackgroundJobDispatcher(IPublishEndpoint publishEndpoint) :
|
||||
IBackgroundJobDispatcher
|
||||
{
|
||||
public bool IsEnabled => true;
|
||||
|
||||
public Task DispatchAsync(
|
||||
Guid jobId,
|
||||
Guid tenantId,
|
||||
string jobType,
|
||||
string correlationId,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
publishEndpoint.Publish(
|
||||
new BackgroundJobRequestedV1(
|
||||
Guid.NewGuid(),
|
||||
jobId,
|
||||
tenantId,
|
||||
jobType,
|
||||
DateTimeOffset.UtcNow,
|
||||
correlationId),
|
||||
context => context.MessageId = jobId,
|
||||
cancellationToken);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using MassTransit;
|
||||
using Tiku.Application.Jobs;
|
||||
using Tiku.Application.Security;
|
||||
using Tiku.Contracts;
|
||||
|
||||
namespace Tiku.Infrastructure.Messaging;
|
||||
|
||||
[ConsumerAuthorizationMetadata(
|
||||
"tenant", "dynamic-job-module", CapabilityOperation.Write, "background_job.execute",
|
||||
RequiresSystemScope = true)]
|
||||
internal sealed class BackgroundJobRequestedConsumer(
|
||||
IBackgroundJobService backgroundJobService,
|
||||
ITenantContextInitializer tenantContextInitializer) : IConsumer<BackgroundJobRequestedV1>
|
||||
{
|
||||
public async Task Consume(ConsumeContext<BackgroundJobRequestedV1> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
tenantContextInitializer.InitializeSystem(
|
||||
message.TenantId,
|
||||
$"RabbitMQ background job {message.JobType}");
|
||||
await backgroundJobService.ProcessRequestedAsync(
|
||||
message.JobId,
|
||||
message.TenantId,
|
||||
message.JobType,
|
||||
$"rabbitmq:{Environment.MachineName}",
|
||||
context.CancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace Tiku.Infrastructure.Messaging;
|
||||
|
||||
public sealed class MessagingOptions
|
||||
{
|
||||
public string Host { get; set; } = string.Empty;
|
||||
public string VirtualHost { get; set; } = "/";
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public bool ConfigureConsumers { get; set; }
|
||||
public int OutboxBacklogAlertCount { get; set; } = 1000;
|
||||
public int OutboxOldestMessageAlertSeconds { get; set; } = 300;
|
||||
|
||||
public bool IsConfigured => Uri.TryCreate(Host, UriKind.Absolute, out var uri) &&
|
||||
uri.Scheme is "rabbitmq" or "amqp" or "amqps";
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
using MassTransit;
|
||||
using Tiku.Contracts;
|
||||
|
||||
namespace Tiku.Infrastructure.Messaging;
|
||||
|
||||
public interface ISecurityEventPublisher
|
||||
{
|
||||
Task AuthorizationChangedAsync(
|
||||
Guid? tenantId,
|
||||
Guid? userId,
|
||||
string changeKind,
|
||||
long version,
|
||||
string correlationId,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task CapabilityChangedAsync(
|
||||
Guid tenantId,
|
||||
string moduleCode,
|
||||
string changeKind,
|
||||
long version,
|
||||
string correlationId,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task MembershipChangedAsync(
|
||||
Guid tenantId,
|
||||
Guid userId,
|
||||
string previousStatus,
|
||||
string currentStatus,
|
||||
string correlationId,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
internal sealed class NullSecurityEventPublisher : ISecurityEventPublisher
|
||||
{
|
||||
public Task AuthorizationChangedAsync(
|
||||
Guid? tenantId, Guid? userId, string changeKind, long version,
|
||||
string correlationId, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
|
||||
public Task CapabilityChangedAsync(
|
||||
Guid tenantId, string moduleCode, string changeKind, long version,
|
||||
string correlationId, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
|
||||
public Task MembershipChangedAsync(
|
||||
Guid tenantId, Guid userId, string previousStatus, string currentStatus,
|
||||
string correlationId, CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal sealed class MassTransitSecurityEventPublisher(IPublishEndpoint publishEndpoint) : ISecurityEventPublisher
|
||||
{
|
||||
public Task AuthorizationChangedAsync(
|
||||
Guid? tenantId, Guid? userId, string changeKind, long version,
|
||||
string correlationId, CancellationToken cancellationToken = default) =>
|
||||
publishEndpoint.Publish(new AuthorizationStateChangedV1(
|
||||
Guid.NewGuid(), tenantId, userId, changeKind, version,
|
||||
DateTimeOffset.UtcNow, correlationId), cancellationToken);
|
||||
|
||||
public Task CapabilityChangedAsync(
|
||||
Guid tenantId, string moduleCode, string changeKind, long version,
|
||||
string correlationId, CancellationToken cancellationToken = default) =>
|
||||
publishEndpoint.Publish(new TenantCapabilityChangedV1(
|
||||
Guid.NewGuid(), tenantId, moduleCode, changeKind, version,
|
||||
DateTimeOffset.UtcNow, correlationId), cancellationToken);
|
||||
|
||||
public Task MembershipChangedAsync(
|
||||
Guid tenantId, Guid userId, string previousStatus, string currentStatus,
|
||||
string correlationId, CancellationToken cancellationToken = default) =>
|
||||
publishEndpoint.Publish(new MembershipLifecycleChangedV1(
|
||||
Guid.NewGuid(), tenantId, userId, previousStatus, currentStatus,
|
||||
DateTimeOffset.UtcNow, correlationId), cancellationToken);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using MassTransit;
|
||||
using Tiku.Application.Security;
|
||||
using Tiku.Contracts;
|
||||
|
||||
namespace Tiku.Infrastructure.Messaging;
|
||||
|
||||
[ConsumerAuthorizationMetadata(
|
||||
"system", "security-state", CapabilityOperation.Read, "security.invalidation.apply")]
|
||||
internal sealed class SecurityStateChangedConsumer(IRedisSecurityStore redisSecurityStore) :
|
||||
IConsumer<AuthorizationStateChangedV1>,
|
||||
IConsumer<TenantCapabilityChangedV1>,
|
||||
IConsumer<MembershipLifecycleChangedV1>
|
||||
{
|
||||
public Task Consume(ConsumeContext<AuthorizationStateChangedV1> context) =>
|
||||
redisSecurityStore.SetInvalidationVersionAsync(
|
||||
"authorization", context.Message.TenantId, context.Message.UserId,
|
||||
context.Message.Version, context.CancellationToken);
|
||||
|
||||
public Task Consume(ConsumeContext<TenantCapabilityChangedV1> context) =>
|
||||
redisSecurityStore.SetInvalidationVersionAsync(
|
||||
$"capability-{context.Message.ModuleCode}", context.Message.TenantId, null,
|
||||
context.Message.Version, context.CancellationToken);
|
||||
|
||||
public Task Consume(ConsumeContext<MembershipLifecycleChangedV1> context) =>
|
||||
redisSecurityStore.SetInvalidationVersionAsync(
|
||||
"membership", context.Message.TenantId, context.Message.UserId,
|
||||
context.Message.OccurredAt.ToUnixTimeMilliseconds(), context.CancellationToken);
|
||||
}
|
||||
19855
Tiku.Infrastructure/Persistence/Migrations/20260730071211_RemoveDistributedMessaging.Designer.cs
generated
Normal file
19855
Tiku.Infrastructure/Persistence/Migrations/20260730071211_RemoveDistributedMessaging.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Tiku.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class RemoveDistributedMessaging : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "outbox_message");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "inbox_state");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "outbox_state");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "inbox_state",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
consumed = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
consumer_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
delivered = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
expiration_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
last_sequence_number = table.Column<long>(type: "bigint", nullable: true),
|
||||
lock_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
message_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
receive_count = table.Column<int>(type: "integer", nullable: false),
|
||||
received = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
row_version = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_inbox_state", x => x.id);
|
||||
table.UniqueConstraint("ak_inbox_state_message_id_consumer_id", x => new { x.message_id, x.consumer_id });
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "outbox_state",
|
||||
columns: table => new
|
||||
{
|
||||
outbox_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
delivered = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
last_sequence_number = table.Column<long>(type: "bigint", nullable: true),
|
||||
lock_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
row_version = table.Column<byte[]>(type: "bytea", rowVersion: true, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_outbox_state", x => x.outbox_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "outbox_message",
|
||||
columns: table => new
|
||||
{
|
||||
sequence_number = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
body = table.Column<string>(type: "text", nullable: false),
|
||||
content_type = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||
conversation_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
correlation_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
destination_address = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
enqueue_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
expiration_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
fault_address = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
headers = table.Column<string>(type: "text", nullable: true),
|
||||
inbox_consumer_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
inbox_message_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
initiator_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
message_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
message_type = table.Column<string>(type: "text", nullable: false),
|
||||
outbox_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
properties = table.Column<string>(type: "text", nullable: true),
|
||||
request_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
response_address = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
||||
sent_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
source_address = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_outbox_message", x => x.sequence_number);
|
||||
table.ForeignKey(
|
||||
name: "fk_outbox_message_inbox_state_inbox_message_id_inbox_consumer_~",
|
||||
columns: x => new { x.inbox_message_id, x.inbox_consumer_id },
|
||||
principalTable: "inbox_state",
|
||||
principalColumns: new[] { "message_id", "consumer_id" });
|
||||
table.ForeignKey(
|
||||
name: "fk_outbox_message_outbox_state_outbox_id",
|
||||
column: x => x.outbox_id,
|
||||
principalTable: "outbox_state",
|
||||
principalColumn: "outbox_id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_inbox_state_delivered",
|
||||
table: "inbox_state",
|
||||
column: "delivered");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_outbox_message_enqueue_time",
|
||||
table: "outbox_message",
|
||||
column: "enqueue_time");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_outbox_message_expiration_time",
|
||||
table: "outbox_message",
|
||||
column: "expiration_time");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_outbox_message_inbox_message_id_inbox_consumer_id_sequence_~",
|
||||
table: "outbox_message",
|
||||
columns: new[] { "inbox_message_id", "inbox_consumer_id", "sequence_number" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_outbox_message_outbox_id_sequence_number",
|
||||
table: "outbox_message",
|
||||
columns: new[] { "outbox_id", "sequence_number" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_outbox_state_created",
|
||||
table: "outbox_state",
|
||||
column: "created");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,224 +26,6 @@ namespace Tiku.Infrastructure.Persistence.Migrations
|
||||
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "pg_trgm");
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.InboxState", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<DateTime?>("Consumed")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("consumed");
|
||||
|
||||
b.Property<Guid>("ConsumerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("consumer_id");
|
||||
|
||||
b.Property<DateTime?>("Delivered")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("delivered");
|
||||
|
||||
b.Property<DateTime?>("ExpirationTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expiration_time");
|
||||
|
||||
b.Property<long?>("LastSequenceNumber")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_sequence_number");
|
||||
|
||||
b.Property<Guid>("LockId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("lock_id");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<int>("ReceiveCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("receive_count");
|
||||
|
||||
b.Property<DateTime>("Received")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("received");
|
||||
|
||||
b.Property<byte[]>("RowVersion")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("row_version");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_inbox_state");
|
||||
|
||||
b.HasAlternateKey("MessageId", "ConsumerId")
|
||||
.HasName("ak_inbox_state_message_id_consumer_id");
|
||||
|
||||
b.HasIndex("Delivered")
|
||||
.HasDatabaseName("ix_inbox_state_delivered");
|
||||
|
||||
b.ToTable("inbox_state", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.OutboxMessage", b =>
|
||||
{
|
||||
b.Property<long>("SequenceNumber")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("sequence_number");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("SequenceNumber"));
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("body");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<Guid?>("ConversationId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("conversation_id");
|
||||
|
||||
b.Property<Guid?>("CorrelationId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("correlation_id");
|
||||
|
||||
b.Property<string>("DestinationAddress")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("destination_address");
|
||||
|
||||
b.Property<DateTime?>("EnqueueTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("enqueue_time");
|
||||
|
||||
b.Property<DateTime?>("ExpirationTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expiration_time");
|
||||
|
||||
b.Property<string>("FaultAddress")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("fault_address");
|
||||
|
||||
b.Property<string>("Headers")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("headers");
|
||||
|
||||
b.Property<Guid?>("InboxConsumerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("inbox_consumer_id");
|
||||
|
||||
b.Property<Guid?>("InboxMessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("inbox_message_id");
|
||||
|
||||
b.Property<Guid?>("InitiatorId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("initiator_id");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<string>("MessageType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("message_type");
|
||||
|
||||
b.Property<Guid?>("OutboxId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("outbox_id");
|
||||
|
||||
b.Property<string>("Properties")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("properties");
|
||||
|
||||
b.Property<Guid?>("RequestId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("request_id");
|
||||
|
||||
b.Property<string>("ResponseAddress")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("response_address");
|
||||
|
||||
b.Property<DateTime>("SentTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("sent_time");
|
||||
|
||||
b.Property<string>("SourceAddress")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("source_address");
|
||||
|
||||
b.HasKey("SequenceNumber")
|
||||
.HasName("pk_outbox_message");
|
||||
|
||||
b.HasIndex("EnqueueTime")
|
||||
.HasDatabaseName("ix_outbox_message_enqueue_time");
|
||||
|
||||
b.HasIndex("ExpirationTime")
|
||||
.HasDatabaseName("ix_outbox_message_expiration_time");
|
||||
|
||||
b.HasIndex("OutboxId", "SequenceNumber")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_outbox_message_outbox_id_sequence_number");
|
||||
|
||||
b.HasIndex("InboxMessageId", "InboxConsumerId", "SequenceNumber")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_outbox_message_inbox_message_id_inbox_consumer_id_sequence_~");
|
||||
|
||||
b.ToTable("outbox_message", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.OutboxState", b =>
|
||||
{
|
||||
b.Property<Guid>("OutboxId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("outbox_id");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created");
|
||||
|
||||
b.Property<DateTime?>("Delivered")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("delivered");
|
||||
|
||||
b.Property<long?>("LastSequenceNumber")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("last_sequence_number");
|
||||
|
||||
b.Property<Guid>("LockId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("lock_id");
|
||||
|
||||
b.Property<byte[]>("RowVersion")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("row_version");
|
||||
|
||||
b.HasKey("OutboxId")
|
||||
.HasName("pk_outbox_state");
|
||||
|
||||
b.HasIndex("Created")
|
||||
.HasDatabaseName("ix_outbox_state_created");
|
||||
|
||||
b.ToTable("outbox_state", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -16266,20 +16048,6 @@ namespace Tiku.Infrastructure.Persistence.Migrations
|
||||
b.ToTable("tenant_student_notes", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MassTransit.EntityFrameworkCoreIntegration.OutboxMessage", b =>
|
||||
{
|
||||
b.HasOne("MassTransit.EntityFrameworkCoreIntegration.OutboxState", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OutboxId")
|
||||
.HasConstraintName("fk_outbox_message_outbox_state_outbox_id");
|
||||
|
||||
b.HasOne("MassTransit.EntityFrameworkCoreIntegration.InboxState", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("InboxMessageId", "InboxConsumerId")
|
||||
.HasPrincipalKey("MessageId", "ConsumerId")
|
||||
.HasConstraintName("fk_outbox_message_inbox_state_inbox_message_id_inbox_consumer_~");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Tiku.Domain.Identity.User", null)
|
||||
|
||||
@@ -16,8 +16,6 @@ using Tiku.Domain.Operations;
|
||||
using Tiku.Domain.Platform;
|
||||
using Tiku.Domain.QuestionBanks;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using MassTransit;
|
||||
using MassTransit.EntityFrameworkCoreIntegration;
|
||||
|
||||
namespace Tiku.Infrastructure.Persistence;
|
||||
|
||||
@@ -224,12 +222,6 @@ public sealed class TikuDbContext(
|
||||
modelBuilder.HasPostgresExtension("pg_trgm");
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(TikuDbContext).Assembly);
|
||||
modelBuilder.Entity<DataProtectionKey>().ToTable("data_protection_keys");
|
||||
modelBuilder.AddInboxStateEntity();
|
||||
modelBuilder.AddOutboxMessageEntity();
|
||||
modelBuilder.AddOutboxStateEntity();
|
||||
modelBuilder.Entity<InboxState>().ToTable("inbox_state");
|
||||
modelBuilder.Entity<OutboxMessage>().ToTable("outbox_message");
|
||||
modelBuilder.Entity<OutboxState>().ToTable("outbox_state");
|
||||
ApplyTenantQueryFilters(modelBuilder);
|
||||
ValidateTenantModel(modelBuilder);
|
||||
modelBuilder.UseSnakeCaseIdentifiers();
|
||||
|
||||
@@ -11,7 +11,6 @@ using Tiku.Domain.Platform;
|
||||
using Tiku.Domain.QuestionBanks;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
|
||||
namespace Tiku.Infrastructure.PlatformAdmin;
|
||||
|
||||
@@ -248,14 +247,9 @@ internal sealed class PlatformAdminService(
|
||||
ToBillingStatus = tenant.BillingStatus,
|
||||
command.Reason
|
||||
});
|
||||
await provider.GetRequiredService<ISecurityEventPublisher>().AuthorizationChangedAsync(
|
||||
tenant.Id,
|
||||
null,
|
||||
"tenant_status_changed",
|
||||
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
||||
$"tenant-status-{tenant.Id:N}",
|
||||
cancellationToken);
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
await provider.GetRequiredService<ITenantFeatureCacheInvalidator>()
|
||||
.InvalidateAsync(tenant.Id, cancellationToken);
|
||||
var domainCount = await dbContext.TenantDomains.CountAsync(domain => domain.TenantId == tenant.Id, cancellationToken);
|
||||
var expiresAt = await dbContext.TenantSaasSubscriptions
|
||||
.Where(subscription => subscription.TenantId == tenant.Id)
|
||||
|
||||
@@ -11,7 +11,6 @@ using Tiku.Domain.Growth;
|
||||
using Tiku.Domain.Operations;
|
||||
using Tiku.Domain.Platform;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
|
||||
namespace Tiku.Infrastructure.PlatformAdmin;
|
||||
|
||||
@@ -6,7 +6,6 @@ using Tiku.Application.Security;
|
||||
using Tiku.Domain.Operations;
|
||||
using Tiku.Domain.Platform;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
|
||||
namespace Tiku.Infrastructure.PlatformBilling;
|
||||
|
||||
@@ -142,13 +141,6 @@ internal sealed class PlatformBillingAdminService(
|
||||
await db.SaveChangesAsync(token);
|
||||
await services.GetRequiredService<ITenantFeatureCacheInvalidator>()
|
||||
.InvalidateAsync(command.TenantId, token);
|
||||
await services.GetRequiredService<ISecurityEventPublisher>().CapabilityChangedAsync(
|
||||
command.TenantId,
|
||||
featureCode,
|
||||
"tenant_feature_override_changed",
|
||||
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
||||
$"tenant-feature-override-{item.Id:N}",
|
||||
token);
|
||||
return item;
|
||||
}, cancellationToken);
|
||||
|
||||
|
||||
@@ -7,13 +7,11 @@ using Tiku.Domain.Platform;
|
||||
using Tiku.Domain.Common;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
|
||||
namespace Tiku.Infrastructure.PlatformBilling;
|
||||
|
||||
internal sealed class PlatformBillingSettlementService(
|
||||
TikuDbContext dbContext,
|
||||
ISecurityEventPublisher securityEventPublisher,
|
||||
ITenantFeatureCacheInvalidator featureCacheInvalidator) : IPlatformBillingSettlementService
|
||||
{
|
||||
public async Task<PlatformBillingPayment> MarkPaidAsync(
|
||||
@@ -80,10 +78,6 @@ internal sealed class PlatformBillingSettlementService(
|
||||
var subscription = await dbContext.TenantSaasSubscriptions
|
||||
.OrderByDescending(value => value.UpdatedAt)
|
||||
.FirstOrDefaultAsync(value => value.TenantId == order.TenantId, cancellationToken);
|
||||
var oldFeatures = subscription is null
|
||||
? []
|
||||
: await LoadSubscriptionFeaturesAsync(subscription, cancellationToken);
|
||||
|
||||
var now = paidAt;
|
||||
if (subscription is null)
|
||||
{
|
||||
@@ -204,41 +198,9 @@ internal sealed class PlatformBillingSettlementService(
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
await featureCacheInvalidator.InvalidateAsync(order.TenantId, cancellationToken);
|
||||
|
||||
var newFeatures = await LoadSubscriptionFeaturesAsync(subscription, cancellationToken);
|
||||
var changedFeatures = oldFeatures.Concat(newFeatures).Distinct(StringComparer.Ordinal).ToArray();
|
||||
var version = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
foreach (var featureCode in changedFeatures)
|
||||
{
|
||||
await securityEventPublisher.CapabilityChangedAsync(
|
||||
order.TenantId,
|
||||
featureCode,
|
||||
"saas_subscription_changed",
|
||||
version,
|
||||
$"platform-billing-order-{order.Id:N}",
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
return payment;
|
||||
}
|
||||
|
||||
private async Task<string[]> LoadSubscriptionFeaturesAsync(TenantSaasSubscription subscription, CancellationToken cancellationToken)
|
||||
{
|
||||
var versionIds = await dbContext.TenantSaasSubscriptionItems.AsNoTracking()
|
||||
.Where(value => value.TenantId == subscription.TenantId && value.SubscriptionId == subscription.Id &&
|
||||
value.Status == TenantSaasSubscriptionItemStatus.Active)
|
||||
.Select(value => value.OfferingVersionId)
|
||||
.ToArrayAsync(cancellationToken);
|
||||
if (!versionIds.Contains(subscription.BaseOfferingVersionId))
|
||||
{
|
||||
versionIds = [.. versionIds, subscription.BaseOfferingVersionId];
|
||||
}
|
||||
return await dbContext.SaasOfferingVersionFeatures.AsNoTracking()
|
||||
.Where(value => versionIds.Contains(value.OfferingVersionId))
|
||||
.Select(value => value.FeatureCode)
|
||||
.Distinct()
|
||||
.ToArrayAsync(cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<JsonElement> LoadBillingProfileSnapshotAsync(Guid tenantId, CancellationToken cancellationToken)
|
||||
{
|
||||
var profile = await dbContext.TenantBillingProfiles.AsNoTracking()
|
||||
|
||||
@@ -8,7 +8,6 @@ using Tiku.Application.Tenancy;
|
||||
using Tiku.Domain.Operations;
|
||||
using Tiku.Domain.Platform;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
|
||||
namespace Tiku.Infrastructure.PlatformBilling;
|
||||
@@ -93,7 +92,6 @@ internal sealed class SaasSubscriptionLifecycleService(
|
||||
|
||||
var previousStatus = subscription.Status;
|
||||
var previousBaseVersionId = subscription.BaseOfferingVersionId;
|
||||
var oldFeatures = await LoadFeaturesAsync(dbContext, subscription, cancellationToken);
|
||||
var items = await dbContext.TenantSaasSubscriptionItems
|
||||
.Where(value => value.TenantId == tenantId && value.SubscriptionId == subscription.Id)
|
||||
.ToArrayAsync(cancellationToken);
|
||||
@@ -209,23 +207,6 @@ internal sealed class SaasSubscriptionLifecycleService(
|
||||
await services.GetRequiredService<ITenantFeatureCacheInvalidator>()
|
||||
.InvalidateAsync(tenantId, cancellationToken);
|
||||
|
||||
var newFeatures = await LoadFeaturesAsync(dbContext, subscription, cancellationToken);
|
||||
var changedFeatures = oldFeatures.Concat(newFeatures).Distinct(StringComparer.Ordinal).ToArray();
|
||||
var eventPublisher = services.GetRequiredService<ISecurityEventPublisher>();
|
||||
var eventVersion = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
var correlationId = $"saas-subscription-{subscription.Id:N}-lifecycle-{subscription.LifecycleVersion}";
|
||||
foreach (var featureCode in changedFeatures)
|
||||
{
|
||||
await eventPublisher.CapabilityChangedAsync(
|
||||
tenantId,
|
||||
featureCode,
|
||||
transition,
|
||||
eventVersion,
|
||||
correlationId,
|
||||
cancellationToken);
|
||||
}
|
||||
await services.GetRequiredService<ITenantRuntimeCacheInvalidator>()
|
||||
.InvalidateAsync(tenantId, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -251,26 +232,4 @@ internal sealed class SaasSubscriptionLifecycleService(
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<string[]> LoadFeaturesAsync(
|
||||
TikuDbContext dbContext,
|
||||
TenantSaasSubscription subscription,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var versionIds = await dbContext.TenantSaasSubscriptionItems.AsNoTracking()
|
||||
.Where(value =>
|
||||
value.TenantId == subscription.TenantId &&
|
||||
value.SubscriptionId == subscription.Id &&
|
||||
value.Status == TenantSaasSubscriptionItemStatus.Active)
|
||||
.Select(value => value.OfferingVersionId)
|
||||
.ToArrayAsync(cancellationToken);
|
||||
if (!versionIds.Contains(subscription.BaseOfferingVersionId))
|
||||
{
|
||||
versionIds = [.. versionIds, subscription.BaseOfferingVersionId];
|
||||
}
|
||||
return await dbContext.SaasOfferingVersionFeatures.AsNoTracking()
|
||||
.Where(value => versionIds.Contains(value.OfferingVersionId))
|
||||
.Select(value => value.FeatureCode)
|
||||
.Distinct()
|
||||
.ToArrayAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,17 +96,6 @@ internal sealed class RedisSecurityStore(
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetInvalidationVersionAsync(
|
||||
string realm,
|
||||
Guid? tenantId,
|
||||
Guid? userId,
|
||||
long version,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var key = $"{prefix}:auth-inv:{Normalize(realm)}:{tenantId?.ToString("N") ?? "-"}:{userId?.ToString("N") ?? "-"}";
|
||||
await connection.GetDatabase().StringSetAsync(key, version, TimeSpan.FromDays(2)).WaitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
private static string Normalize(string value) =>
|
||||
string.Concat(value.Trim().ToLowerInvariant().Select(character =>
|
||||
char.IsLetterOrDigit(character) || character is '-' or '_' ? character : '-'));
|
||||
@@ -122,13 +111,6 @@ public sealed class NullRedisSecurityStore : IRedisSecurityStore
|
||||
Task.FromResult(new DistributedRateLimitResult(true));
|
||||
|
||||
public Task<bool> PingAsync(CancellationToken cancellationToken = default) => Task.FromResult(false);
|
||||
|
||||
public Task SetInvalidationVersionAsync(
|
||||
string realm,
|
||||
Guid? tenantId,
|
||||
Guid? userId,
|
||||
long version,
|
||||
CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
public sealed class RedisSecurityUnavailableException(Exception innerException)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StackExchange.Redis;
|
||||
using Tiku.Application.Security;
|
||||
using Tiku.Application.Tenancy;
|
||||
|
||||
@@ -13,11 +11,8 @@ internal sealed class TenantFeatureCacheInvalidator(
|
||||
IMemoryCache memoryCache,
|
||||
IServiceProvider serviceProvider,
|
||||
ITenantRuntimeCacheInvalidator runtimeCacheInvalidator,
|
||||
ILogger<TenantFeatureCacheInvalidator> logger) : ITenantFeatureCacheInvalidator, IHostedService
|
||||
ILogger<TenantFeatureCacheInvalidator> logger) : ITenantFeatureCacheInvalidator
|
||||
{
|
||||
private const string ChannelName = "tiku:tenant-feature-snapshot:invalidate:v1";
|
||||
private ISubscriber? subscriber;
|
||||
|
||||
public async Task InvalidateAsync(Guid tenantId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
RemoveMemory(tenantId);
|
||||
@@ -36,47 +31,6 @@ internal sealed class TenantFeatureCacheInvalidator(
|
||||
logger.LogWarning(exception, "Tenant feature distributed cache invalidation failed for tenant {TenantId}.", tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
var connection = serviceProvider.GetService<IConnectionMultiplexer>();
|
||||
if (connection is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await connection.GetSubscriber()
|
||||
.PublishAsync(RedisChannel.Literal(ChannelName), tenantId.ToString("N"))
|
||||
.WaitAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception exception) when (exception is RedisException or TimeoutException)
|
||||
{
|
||||
logger.LogWarning(exception, "Tenant feature L1 invalidation broadcast failed for tenant {TenantId}.", tenantId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var connection = serviceProvider.GetService<IConnectionMultiplexer>();
|
||||
if (connection is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
subscriber = connection.GetSubscriber();
|
||||
await subscriber.SubscribeAsync(RedisChannel.Literal(ChannelName), (_, value) =>
|
||||
{
|
||||
if (Guid.TryParseExact(value.ToString(), "N", out var tenantId))
|
||||
{
|
||||
RemoveMemory(tenantId);
|
||||
}
|
||||
}).WaitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (subscriber is not null)
|
||||
{
|
||||
await subscriber.UnsubscribeAsync(RedisChannel.Literal(ChannelName)).WaitAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveMemory(Guid tenantId)
|
||||
|
||||
@@ -15,7 +15,6 @@ using Tiku.Domain.Operations;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
using Tiku.Infrastructure.Security;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
using CommerceRefundStatus = Tiku.Domain.Commerce.CommerceRefundStatus;
|
||||
using OrderStatus = Tiku.Domain.Commerce.OrderStatus;
|
||||
using PointActivityClaimStatus = Tiku.Domain.Commerce.PointActivityClaimStatus;
|
||||
@@ -30,7 +29,6 @@ public sealed class TenantAdminDirectService(
|
||||
INotificationProvider notificationProvider,
|
||||
ICurrentAccessContext currentAccessContext,
|
||||
IAuthSessionStore sessionStore,
|
||||
ISecurityEventPublisher securityEventPublisher,
|
||||
IFeatureAccessService featureAccessService) : ITenantAdminDirectService
|
||||
{
|
||||
public async Task<TenantAdminOverviewItem> GetOverviewAsync(
|
||||
@@ -1263,9 +1261,6 @@ public sealed class TenantAdminDirectService(
|
||||
}
|
||||
|
||||
await AddAuditAsync(actor, "tenant.member.upserted", "tenant_memberships", membership.Id, cancellationToken);
|
||||
await securityEventPublisher.MembershipChangedAsync(
|
||||
actor.TenantId, user.Id, previousStatus, status.ToString(),
|
||||
$"tenant-member-{membership.Id:N}", cancellationToken);
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
if (wasStaffCounted && !willStaffBeCounted)
|
||||
{
|
||||
@@ -1322,9 +1317,6 @@ public sealed class TenantAdminDirectService(
|
||||
membership.Status = MembershipStatus.Disabled;
|
||||
await RevokeSessionsAsync(actor.TenantId, membership.UserId, cancellationToken);
|
||||
await AddAuditAsync(actor, "tenant.member.disabled", "tenant_memberships", membership.Id, cancellationToken);
|
||||
await securityEventPublisher.MembershipChangedAsync(
|
||||
actor.TenantId, membership.UserId, previousStatus.ToString(), MembershipStatus.Disabled.ToString(),
|
||||
$"tenant-member-{membership.Id:N}", cancellationToken);
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
if (previousStatus == MembershipStatus.Active && wasCounted && !otherMembershipCounted)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tiku.Application\Tiku.Application.csproj" />
|
||||
<ProjectReference Include="..\Tiku.Domain\Tiku.Domain.csproj" />
|
||||
<ProjectReference Include="..\Tiku.Contracts\Tiku.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -19,9 +18,6 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Options" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" />
|
||||
<PackageReference Include="StackExchange.Redis" />
|
||||
<PackageReference Include="MassTransit" />
|
||||
<PackageReference Include="MassTransit.RabbitMQ" />
|
||||
<PackageReference Include="MassTransit.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel" />
|
||||
<PackageReference Include="Npgsql" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
|
||||
Reference in New Issue
Block a user