House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s
Build / Build (push) Successful in 30s
- Services, controllers and jobs take their dependencies through primary constructors and use them directly; where a method already named a local after a dependency, the dependency takes its type's name. - Every async method takes a CancellationToken last and passes it down to MongoDB, HTTP and the job queue. The setup claim is still given back when a request is cancelled. - The federation and media options are read through IOptionsMonitor. - The Mastodon entities keep sending "" for empty strings, and every model field where null means something says so. - The inbox's 503 with Retry-After, which other servers retry, is the one server error left, and says why. - Arasaka.HouseRules.Analyzers checks all of this in every build, here and in PrivaPub.ClientModels as decePubClient builds it. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f0a14c737f
commit
0f73f69239
176 files changed
+2789
-3974
No files matched your search
@@ -18,24 +18,13 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
[ApiController,
|
||||
Route("clientapi/admin/domainblocks"),
|
||||
Authorize(Policy = Policies.IsAdmin)]
|
||||
public class DomainBlockController : ControllerBase
|
||||
public class DomainBlockController(
|
||||
IDomainBlocks domainBlocks,
|
||||
IStringLocalizer<GenericRes> localizer,
|
||||
Domain.Media.IMediaProxy mediaProxy,
|
||||
IModerationLog log,
|
||||
IAccountModeration moderation) : ControllerBase
|
||||
{
|
||||
readonly IDomainBlocks _domainBlocks;
|
||||
readonly IStringLocalizer _localizer;
|
||||
readonly Domain.Media.IMediaProxy _proxy;
|
||||
readonly IModerationLog _log;
|
||||
readonly IAccountModeration _moderation;
|
||||
|
||||
public DomainBlockController(IDomainBlocks domainBlocks, IStringLocalizer<GenericRes> localizer, Domain.Media.IMediaProxy proxy, IModerationLog log,
|
||||
IAccountModeration moderation)
|
||||
{
|
||||
_moderation = moderation;
|
||||
_domainBlocks = domainBlocks;
|
||||
_localizer = localizer;
|
||||
_proxy = proxy;
|
||||
_log = log;
|
||||
}
|
||||
|
||||
[HttpGet, Route("/clientapi/admin/domainblocks/list")]
|
||||
public async Task<IActionResult> List(CancellationToken token) =>
|
||||
Ok((await DB.Default.Find<DomainBlock>().Sort(b => b.Domain, Order.Ascending).ExecuteAsync(token)).Select(ToView).ToList());
|
||||
@@ -45,7 +34,7 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
{
|
||||
var domain = DomainBlocks.Normalise(form.Domain);
|
||||
if (!ModelState.IsValid || Uri.CheckHostName(domain) != UriHostNameType.Dns)
|
||||
return BadRequest(new WebResult().Invalidate(_localizer["Invalid model."]));
|
||||
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
|
||||
|
||||
var block = await DB.Default.UpdateAndGet<DomainBlock>()
|
||||
.Match(b => b.Domain == domain)
|
||||
@@ -59,13 +48,13 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
.Modify(b => b.SetOnInsert(x => x.CreatedAt, DateTime.UtcNow))
|
||||
.Option(o => o.IsUpsert = true)
|
||||
.ExecuteAsync(token);
|
||||
await _domainBlocks.Reload(token);
|
||||
await domainBlocks.Reload(token);
|
||||
// a silenced server's posts are limited from now on, and no longer once it is not (R6)
|
||||
await _moderation.DomainChanged(domain, token);
|
||||
await moderation.DomainChanged(domain, token);
|
||||
// what the media proxy holds of it goes with the block
|
||||
if (block.Severity == DomainBlockSeverity.Suspend || block.RejectMedia)
|
||||
_proxy.Purge(domain);
|
||||
await _log.Write(User.GetUserId(), AdminActions.DomainBlockInsert, AdminTargets.Domain, domain, domain,
|
||||
mediaProxy.Purge(domain);
|
||||
await log.Write(User.GetUserId(), AdminActions.DomainBlockInsert, AdminTargets.Domain, domain, domain,
|
||||
note: string.Join(", ", new[] { block.Severity.ToString().ToLowerInvariant(), block.RejectMedia ? "media rejected" : default,
|
||||
block.Published ? (block.Obfuscate ? "published, obfuscated" : "published") : default }.Where(n => n != default)), token: token);
|
||||
return Ok(ToView(block));
|
||||
@@ -76,11 +65,11 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
{
|
||||
domain = DomainBlocks.Normalise(domain);
|
||||
var deleted = await DB.Default.DeleteAsync<DomainBlock>(b => b.Domain == domain);
|
||||
await _domainBlocks.Reload(token);
|
||||
await domainBlocks.Reload(token);
|
||||
if (deleted.DeletedCount > 0)
|
||||
await _moderation.DomainChanged(domain, token);
|
||||
await moderation.DomainChanged(domain, token);
|
||||
if (deleted.DeletedCount > 0)
|
||||
await _log.Write(User.GetUserId(), AdminActions.DomainBlockDelete, AdminTargets.Domain, domain, domain, token: token);
|
||||
await log.Write(User.GetUserId(), AdminActions.DomainBlockDelete, AdminTargets.Domain, domain, domain, token: token);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user