mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-16 20:56:03 +00:00
2e9d7e625e
Adds server-side group and channel management, private invitations, member moderation, avatar handling, and required-channel configuration. This change also introduces SignalR group profile/member notifications, updates registration to atomically join required channels, and adds EF migration and test coverage for group membership, permissions, and invitation expiry rules.
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using Govor.Domain;
|
|
using Govor.Application.Infrastructure.Common;
|
|
using Govor.Domain.Common;
|
|
using Govor.Domain.Models;
|
|
using Govor.Domain.Models.Users;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SmartRes;
|
|
|
|
namespace Govor.Application.Authentication;
|
|
|
|
public class InvitesService : IInvitesService
|
|
{
|
|
private readonly GovorDbContext _context;
|
|
private readonly INowDateTimeProvider _clock;
|
|
|
|
public InvitesService(GovorDbContext context, INowDateTimeProvider clock)
|
|
{
|
|
_context = context;
|
|
_clock = clock;
|
|
}
|
|
|
|
public async Task<string> GetRoleNameAsync(User user)
|
|
{
|
|
return await GetRoleNameAsync(user.InviteId);
|
|
}
|
|
|
|
public async Task<string> GetRoleNameAsync(Guid sessionId)
|
|
{
|
|
var invitation = await _context.Invitations.AsNoTracking().FirstOrDefaultAsync(s => s.Id == sessionId);
|
|
|
|
if (invitation == null)
|
|
return "User";
|
|
|
|
return invitation.IsAdmin ? "Admin" : "User";
|
|
}
|
|
|
|
public async Task<Result<Invitation, Error>> ValidateAsync(string inviteCode)
|
|
{
|
|
var invite = await _context.Invitations
|
|
.Include(s => s.Users)
|
|
.FirstOrDefaultAsync(s => s.Code == inviteCode);
|
|
|
|
if (invite == null)
|
|
return Result.Failure<Invitation>(Error.NotFound("Auth.LinkNotFount","Invitation not found."));
|
|
|
|
if (!invite.IsActive || invite.EndDate <= _clock.Now || invite.MaxParticipants <= invite.Users.Count || invite.MaxParticipants <= invite.Participants)
|
|
{
|
|
invite.IsActive = false;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Result.Failure<Invitation>(
|
|
Error.Failure(
|
|
"Auth.InviteLinkInvalid", $"Invite link invalid: {inviteCode}"
|
|
)
|
|
);
|
|
}
|
|
|
|
return invite;
|
|
}
|
|
}
|
|
|