28 lines
994 B
C#
28 lines
994 B
C#
using Flawless.Communication.Shared;
|
|
using Flawless.Server.Models;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Flawless.Server.Services;
|
|
|
|
public class AppDbContext(DbContextOptions<AppDbContext> options)
|
|
: IdentityDbContext<AppUser, IdentityRole<Guid>, Guid>(options)
|
|
{
|
|
public DbSet<AppUserRefreshKey> RefreshTokens { get; set; }
|
|
|
|
public DbSet<Repository> Repositories { get; set; }
|
|
|
|
public async ValueTask<(bool existed, bool authorized)> CheckRepositoryExistedAuthorizedAsync(
|
|
AppUser owner, string name, AppUser user, RepositoryRole role)
|
|
{
|
|
var r = await Repositories
|
|
.FirstOrDefaultAsync(r => r.Name == name && r.Owner == owner);
|
|
|
|
var existed = r != null;
|
|
var authorized = existed && (r!.Owner == owner || r.Members.Any(m => m.User == owner && m.Role >= role));
|
|
|
|
return (existed, authorized);
|
|
}
|
|
|
|
} |