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
@@ -13,52 +13,45 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
[ApiController,
|
||||
Route("clientapi/group"),
|
||||
Authorize(Policy = Policies.IsUser)]
|
||||
public class GroupController : ControllerBase
|
||||
public class GroupController(
|
||||
IGroupUsersService groupUsersService,
|
||||
IStringLocalizer<GenericRes> localizer) : ControllerBase
|
||||
{
|
||||
readonly IGroupUsersService _groupUsersService;
|
||||
readonly IStringLocalizer _localizer;
|
||||
|
||||
public GroupController(IGroupUsersService groupUsersService, IStringLocalizer<GenericRes> localizer)
|
||||
{
|
||||
_groupUsersService = groupUsersService;
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
[HttpGet, Route("/clientapi/group/list")]
|
||||
public async Task<IActionResult> List([FromQuery] string avatarId, CancellationToken token) =>
|
||||
Answer(await _groupUsersService.GetGroups(User.GetUserId(), avatarId, token));
|
||||
Answer(await groupUsersService.GetGroups(User.GetUserId(), avatarId, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/insert")]
|
||||
public async Task<IActionResult> Insert(InsertGroupForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.InsertGroup(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.InsertGroup(User.GetUserId(), form, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/update")]
|
||||
public async Task<IActionResult> Update(UpdateGroupForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.UpdateGroup(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.UpdateGroup(User.GetUserId(), form, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/join")]
|
||||
public async Task<IActionResult> Join(JoinGroupForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.JoinGroup(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.JoinGroup(User.GetUserId(), form, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/leave")]
|
||||
public async Task<IActionResult> Leave(GroupMembershipForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.LeaveGroup(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.LeaveGroup(User.GetUserId(), form, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/approve")]
|
||||
public async Task<IActionResult> Approve(GroupMembershipForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.ApproveMember(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.ApproveMember(User.GetUserId(), form, token));
|
||||
|
||||
[HttpGet, Route("/clientapi/group/members")]
|
||||
public async Task<IActionResult> Members([FromQuery] string avatarId, [FromQuery] string groupId, CancellationToken token) =>
|
||||
Answer(await _groupUsersService.GetMembers(User.GetUserId(), avatarId, groupId, token));
|
||||
Answer(await groupUsersService.GetMembers(User.GetUserId(), avatarId, groupId, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/reject")]
|
||||
public async Task<IActionResult> Reject(GroupMembershipForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.RejectMember(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.RejectMember(User.GetUserId(), form, token));
|
||||
|
||||
[HttpPost, Route("/clientapi/group/remove")]
|
||||
public async Task<IActionResult> Remove(GroupMembershipForm form, CancellationToken token) =>
|
||||
!ModelState.IsValid ? Invalid() : Answer(await _groupUsersService.RemoveMember(User.GetUserId(), form, token));
|
||||
!ModelState.IsValid ? Invalid() : Answer(await groupUsersService.RemoveMember(User.GetUserId(), form, token));
|
||||
|
||||
// the group's owner deletes it, with the login's password (R6): its members and followers are told, its name stays
|
||||
// taken (GroupRemoval)
|
||||
@@ -69,19 +62,19 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
if (!ModelState.IsValid)
|
||||
return Invalid();
|
||||
var rootId = User.GetUserId();
|
||||
if (!await users.PasswordMatches(rootId, form.Password))
|
||||
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(_localizer[RootUsersService.NoMatch], StatusCodes.Status403Forbidden));
|
||||
if (!await users.PasswordMatches(rootId, form.Password, token))
|
||||
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer[RootUsersService.NoMatch], StatusCodes.Status403Forbidden));
|
||||
var owns = await dbEntities.RootToAvatars.Match(ra => ra.RootId == rootId && ra.AvatarId == form.AvatarId).ExecuteAnyAsync(token);
|
||||
var group = owns ? await dbEntities.Groups.MatchID(form.GroupId).Match(g => !g.DeletionAt.HasValue).ExecuteFirstAsync(token) : default;
|
||||
if (group == default)
|
||||
return NotFound(new WebResult().Invalidate(_localizer["Group not found."], StatusCodes.Status404NotFound));
|
||||
return NotFound(new WebResult().Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound));
|
||||
if (group.OwnerAvatarId != form.AvatarId)
|
||||
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(_localizer["Only the group's owner can delete it."], StatusCodes.Status403Forbidden));
|
||||
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer["Only the group's owner can delete it."], StatusCodes.Status403Forbidden));
|
||||
await groups.Remove(group.ID, CancellationToken.None);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(_localizer["Invalid model."]));
|
||||
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
|
||||
|
||||
IActionResult Answer(WebResult result) => result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user