👔 Update publication site limits for perk members

This commit is contained in:
2025-11-19 00:48:36 +08:00
parent ac51bbde6c
commit 18d50346a9
3 changed files with 35 additions and 15 deletions

View File

@@ -24,7 +24,7 @@ public class ExperienceService(AppDatabase db, SubscriptionService subscriptions
{
SubscriptionType.Stellar => 1.5,
SubscriptionType.Nova => 2,
SubscriptionType.Supernova => 2,
SubscriptionType.Supernova => 2.5,
_ => 1
};
if (record.Delta >= 0)

View File

@@ -1,11 +1,17 @@
using System.Text.RegularExpressions;
using DysonNetwork.Shared.Auth;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Registry;
using DysonNetwork.Sphere.Publisher;
using Microsoft.EntityFrameworkCore;
namespace DysonNetwork.Sphere.Publication;
public class PublicationSiteService(AppDatabase db, PublisherService publisherService)
public class PublicationSiteService(
AppDatabase db,
PublisherService publisherService,
RemoteAccountService remoteAccounts
)
{
public async Task<SnPublicationSite?> GetSiteById(Guid id)
{
@@ -37,10 +43,21 @@ public class PublicationSiteService(AppDatabase db, PublisherService publisherSe
public async Task<SnPublicationSite> CreateSite(SnPublicationSite site, Guid accountId)
{
// Check if account already has a site
var existingSite = await db.PublicationSites.FirstOrDefaultAsync(s => s.AccountId == accountId);
if (existingSite != null)
throw new InvalidOperationException("Account already has a site.");
var perk = (await remoteAccounts.GetAccount(accountId)).PerkSubscription;
var perkLevel = perk is not null ? PerkSubscriptionPrivilege.GetPrivilegeFromIdentifier(perk.Identifier) : 0;
var maxSite = (perkLevel) switch
{
1 => 2,
2 => 3,
3 => 5,
_ => 1
};
// Check if account has reached the maximum number of sites
var existingSitesCount = await db.PublicationSites.CountAsync(s => s.AccountId == accountId);
if (existingSitesCount >= maxSite)
throw new InvalidOperationException("Account has reached the maximum number of sites allowed.");
// Check if account is member of the publisher
var isMember = await publisherService.IsMemberWithRole(site.PublisherId, accountId, PublisherMemberRole.Editor);
@@ -70,7 +87,8 @@ public class PublicationSiteService(AppDatabase db, PublisherService publisherSe
if (site != null)
{
// Check permission
var isMember = await publisherService.IsMemberWithRole(site.PublisherId, accountId, PublisherMemberRole.Owner);
var isMember =
await publisherService.IsMemberWithRole(site.PublisherId, accountId, PublisherMemberRole.Owner);
if (!isMember)
throw new UnauthorizedAccessException("Account is not an owner of the publisher.");
@@ -137,9 +155,11 @@ public class PublicationSiteService(AppDatabase db, PublisherService publisherSe
if (site != null)
{
// Check permission
var isMember = await publisherService.IsMemberWithRole(site.PublisherId, accountId, PublisherMemberRole.Editor);
var isMember =
await publisherService.IsMemberWithRole(site.PublisherId, accountId, PublisherMemberRole.Editor);
if (!isMember)
throw new UnauthorizedAccessException("Account is not a member of the publisher with sufficient role.");
throw new UnauthorizedAccessException(
"Account is not a member of the publisher with sufficient role.");
db.PublicationPages.Remove(page);
await db.SaveChangesAsync();

View File

@@ -11,6 +11,7 @@ using DysonNetwork.Sphere.Discovery;
using DysonNetwork.Sphere.Localization;
using DysonNetwork.Sphere.Poll;
using DysonNetwork.Sphere.Post;
using DysonNetwork.Sphere.Publication;
using DysonNetwork.Sphere.Publisher;
using DysonNetwork.Sphere.Sticker;
using DysonNetwork.Sphere.Timeline;
@@ -112,9 +113,8 @@ public static class ServiceCollectionExtensions
services.AddScoped<WebFeedService>();
services.AddScoped<DiscoveryService>();
services.AddScoped<PollService>();
services.AddScoped<RemoteAccountService>();
services.AddScoped<RemoteRealmService>();
services.AddScoped<AutocompletionService>();
services.AddScoped<PublicationSiteService>();
var translationProvider = configuration["Translation:Provider"]?.ToLower();
switch (translationProvider)