2026-10-01 12:13:57 +02:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
using MongoDB.Entities;
|
|
|
|
|
|
|
|
|
|
using PrivaPub.ClientModels;
|
2026-10-05 05:32:32 +02:00
|
|
|
using PrivaPub.ClientModels.Admin;
|
2026-10-01 12:13:57 +02:00
|
|
|
using PrivaPub.Extensions;
|
|
|
|
|
using PrivaPub.Models.Social;
|
2023-02-18 08:52:17 +01:00
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
namespace PrivaPub.Controllers.ClientToServer
|
2023-02-18 08:52:17 +01:00
|
|
|
{
|
|
|
|
|
[ApiController,
|
2026-10-01 12:13:57 +02:00
|
|
|
Route("clientapi/moderator"),
|
|
|
|
|
Authorize(Policy = Policies.IsModerator)]
|
2023-02-18 08:52:17 +01:00
|
|
|
public class ModeratorController : ControllerBase
|
|
|
|
|
{
|
2026-10-01 12:13:57 +02:00
|
|
|
[HttpGet, Route("/clientapi/moderator/reports")]
|
|
|
|
|
public async Task<IActionResult> Reports([FromQuery] bool resolved, CancellationToken token) =>
|
|
|
|
|
Ok((await DB.Default.Find<Report>().Match(r => r.IsResolved == resolved).Sort(r => r.ID, Order.Descending).Limit(100).ExecuteAsync(token))
|
2026-10-05 05:32:32 +02:00
|
|
|
.Select(r => new ViewReport
|
2026-10-01 12:13:57 +02:00
|
|
|
{
|
2026-10-05 05:32:32 +02:00
|
|
|
ID = r.ID,
|
2026-10-01 12:13:57 +02:00
|
|
|
Reporter = r.ReporterAvatarId != default ? "local" : r.ReporterActorURI,
|
2026-10-05 05:32:32 +02:00
|
|
|
TargetAccountId = r.TargetAccountId,
|
|
|
|
|
TargetActorURI = r.TargetActorURI,
|
|
|
|
|
PostIds = r.PostIds,
|
|
|
|
|
ObjectURIs = r.ObjectURIs,
|
|
|
|
|
Category = r.Category,
|
|
|
|
|
Comment = r.Comment,
|
|
|
|
|
Forwarded = r.Forwarded,
|
|
|
|
|
IsResolved = r.IsResolved,
|
|
|
|
|
CreatedAt = r.CreatedAt,
|
2026-10-07 21:10:58 +02:00
|
|
|
ResolvedAt = r.ResolvedAt,
|
|
|
|
|
RemoteResolvedAt = r.RemoteResolvedAt,
|
|
|
|
|
RemoteResolvedBy = r.RemoteResolvedBy
|
2026-10-01 12:13:57 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
[HttpPost, Route("/clientapi/moderator/reports/{id}/resolve")]
|
|
|
|
|
public async Task<IActionResult> Resolve(string id, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await DB.Default.Update<Report>().MatchID(id)
|
|
|
|
|
.Modify(r => r.IsResolved, true)
|
|
|
|
|
.Modify(r => r.ResolvedAt, DateTime.UtcNow)
|
|
|
|
|
.Modify(r => r.ResolvedBy, User.GetUserId())
|
|
|
|
|
.ExecuteAsync(token);
|
|
|
|
|
return result.MatchedCount == 0 ? NotFound() : Ok();
|
|
|
|
|
}
|
2023-02-18 08:52:17 +01:00
|
|
|
}
|
|
|
|
|
}
|