♻️ Moved the site to the Zone project

This commit is contained in:
2025-11-19 22:28:52 +08:00
parent 9b4cbade5c
commit 1b774c1de6
16 changed files with 2537 additions and 151 deletions

View File

@@ -14,7 +14,7 @@ public class SnPublicationSite : ModelBase
public List<SnPublicationPage> Pages { get; set; } = [];
public Guid PublisherId { get; set; }
public SnPublisher Publisher { get; set; } = null!;
[NotMapped] public SnPublisher Publisher { get; set; } = null!;
public Guid AccountId { get; set; }
// Preloaded via the remote services
[NotMapped] public SnAccount? Account { get; set; }

View File

@@ -1,8 +1,10 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using DysonNetwork.Shared.Proto;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using NodaTime.Extensions;
using NodaTime.Serialization.Protobuf;
namespace DysonNetwork.Shared.Models;
@@ -148,23 +150,42 @@ public class SnPublisherMember : ModelBase
public Instant? JoinedAt { get; set; }
public Proto.PublisherMember ToProto()
public PublisherMember ToProto()
{
return new Proto.PublisherMember()
return new PublisherMember
{
PublisherId = PublisherId.ToString(),
AccountId = AccountId.ToString(),
Role = Role switch
{
PublisherMemberRole.Owner => Shared.Proto.PublisherMemberRole.Owner,
PublisherMemberRole.Manager => Shared.Proto.PublisherMemberRole.Manager,
PublisherMemberRole.Editor => Shared.Proto.PublisherMemberRole.Editor,
PublisherMemberRole.Viewer => Shared.Proto.PublisherMemberRole.Viewer,
PublisherMemberRole.Owner => Proto.PublisherMemberRole.Owner,
PublisherMemberRole.Manager => Proto.PublisherMemberRole.Manager,
PublisherMemberRole.Editor => Proto.PublisherMemberRole.Editor,
PublisherMemberRole.Viewer => Proto.PublisherMemberRole.Viewer,
_ => throw new ArgumentOutOfRangeException(nameof(Role), Role, null)
},
JoinedAt = JoinedAt?.ToTimestamp()
};
}
public static SnPublisherMember FromProtoValue(PublisherMember proto)
{
return new SnPublisherMember
{
PublisherId = Guid.Parse(proto.PublisherId),
AccountId = Guid.Parse(proto.AccountId),
Role = proto.Role switch
{
Proto.PublisherMemberRole.Owner => PublisherMemberRole.Owner,
Proto.PublisherMemberRole.Manager => PublisherMemberRole.Manager,
Proto.PublisherMemberRole.Editor => PublisherMemberRole.Editor,
_ => PublisherMemberRole.Viewer
},
JoinedAt = proto.JoinedAt?.ToDateTimeOffset().ToInstant(),
CreatedAt = proto.CreatedAt.ToDateTimeOffset().ToInstant(),
UpdatedAt = proto.UpdatedAt.ToDateTimeOffset().ToInstant()
};
}
}
public enum PublisherSubscriptionStatus
@@ -200,4 +221,4 @@ public abstract class PublisherFeatureFlag
{
public static List<string> AllFlags => [Develop];
public static string Develop = "develop";
}
}

View File

@@ -0,0 +1,111 @@
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto;
namespace DysonNetwork.Shared.Registry;
public class RemotePublisherService(PublisherService.PublisherServiceClient publishers)
{
public async Task<SnPublisher> GetPublisher(string? name = null, string? id = null,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(id))
throw new ArgumentException("Either name or id must be provided.");
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(id))
throw new ArgumentException("Only one of name or id can be provided.");
var request = new GetPublisherRequest();
if (!string.IsNullOrEmpty(name))
request.Name = name;
else
request.Id = id;
var response = await publishers.GetPublisherAsync(request, cancellationToken: cancellationToken);
return SnPublisher.FromProtoValue(response.Publisher);
}
public async Task<List<SnPublisher>> GetPublishersBatch(List<string> ids,
CancellationToken cancellationToken = default)
{
var request = new GetPublisherBatchRequest();
request.Ids.AddRange(ids);
var response = await publishers.GetPublisherBatchAsync(request, cancellationToken: cancellationToken);
return response.Publishers.Select(SnPublisher.FromProtoValue).ToList();
}
public async Task<List<SnPublisher>> ListPublishers(string? accountId = null, string? realmId = null,
CancellationToken cancellationToken = default)
{
var request = new ListPublishersRequest
{
AccountId = accountId ?? "",
RealmId = realmId ?? ""
};
var response = await publishers.ListPublishersAsync(request, cancellationToken: cancellationToken);
return response.Publishers.Select(SnPublisher.FromProtoValue).ToList();
}
public async Task<List<SnPublisherMember>> ListPublisherMembers(string publisherId,
CancellationToken cancellationToken = default)
{
var request = new ListPublisherMembersRequest { PublisherId = publisherId };
var response = await publishers.ListPublisherMembersAsync(request, cancellationToken: cancellationToken);
return response.Members.Select(SnPublisherMember.FromProtoValue).ToList();
}
public async Task<string?> SetPublisherFeatureFlag(string publisherId, string flag,
CancellationToken cancellationToken = default)
{
var request = new SetPublisherFeatureFlagRequest
{
PublisherId = publisherId,
Flag = flag
};
var response = await publishers.SetPublisherFeatureFlagAsync(request, cancellationToken: cancellationToken);
return response.Value;
}
public async Task<bool> HasPublisherFeature(string publisherId, string flag,
CancellationToken cancellationToken = default)
{
var request = new HasPublisherFeatureRequest
{
PublisherId = publisherId,
Flag = flag
};
var response = await publishers.HasPublisherFeatureAsync(request, cancellationToken: cancellationToken);
return response.Enabled;
}
public async Task<bool> IsPublisherMember(string publisherId, string accountId,
Proto.PublisherMemberRole? role = null, CancellationToken cancellationToken = default)
{
var request = new IsPublisherMemberRequest
{
PublisherId = publisherId,
AccountId = accountId,
};
if (role.HasValue) request.Role = role.Value;
var response = await publishers.IsPublisherMemberAsync(request, cancellationToken: cancellationToken);
return response.Valid;
}
public async Task<List<SnPublisher>> GetUserPublishers(Guid accountId,
CancellationToken cancellationToken = default)
{
return await ListPublishers(accountId: accountId.ToString(), realmId: null, cancellationToken);
}
public async Task<bool> IsMemberWithRole(Guid publisherId, Guid accountId, Models.PublisherMemberRole role,
CancellationToken cancellationToken = default)
{
var protoRole = role switch
{
Models.PublisherMemberRole.Owner => Proto.PublisherMemberRole.Owner,
Models.PublisherMemberRole.Manager => Proto.PublisherMemberRole.Manager,
Models.PublisherMemberRole.Editor => Proto.PublisherMemberRole.Editor,
Models.PublisherMemberRole.Viewer => Proto.PublisherMemberRole.Viewer,
_ => Proto.PublisherMemberRole.Unspecified
};
return await IsPublisherMember(publisherId.ToString(), accountId.ToString(), protoRole, cancellationToken);
}
}

View File

@@ -116,6 +116,7 @@ public static class ServiceInjectionHelper
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
{ ServerCertificateCustomValidationCallback = (_, _, _, _) => true }
);
services.AddSingleton<RemotePublisherService>();
return services;
}