[backend/database] Rename registration_ticket table to registration_invite
This commit is contained in:
parent
b403944742
commit
5bd92d14ac
7 changed files with 6080 additions and 8 deletions
|
@ -20,7 +20,7 @@ public class AdminController(DatabaseContext db) : Controller {
|
||||||
[HttpPost("invites/generate")]
|
[HttpPost("invites/generate")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(InviteResponse))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(InviteResponse))]
|
||||||
public async Task<IActionResult> GenerateInvite() {
|
public async Task<IActionResult> GenerateInvite() {
|
||||||
var invite = new RegistrationTicket {
|
var invite = new RegistrationInvite {
|
||||||
Id = IdHelpers.GenerateSlowflakeId(),
|
Id = IdHelpers.GenerateSlowflakeId(),
|
||||||
CreatedAt = DateTime.UtcNow,
|
CreatedAt = DateTime.UtcNow,
|
||||||
Code = CryptographyHelpers.GenerateRandomString(32)
|
Code = CryptographyHelpers.GenerateRandomString(32)
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
|
||||||
public virtual DbSet<PollVote> PollVotes { get; init; } = null!;
|
public virtual DbSet<PollVote> PollVotes { get; init; } = null!;
|
||||||
public virtual DbSet<PromoNote> PromoNotes { get; init; } = null!;
|
public virtual DbSet<PromoNote> PromoNotes { get; init; } = null!;
|
||||||
public virtual DbSet<PromoRead> PromoReads { get; init; } = null!;
|
public virtual DbSet<PromoRead> PromoReads { get; init; } = null!;
|
||||||
public virtual DbSet<RegistrationTicket> RegistrationTickets { get; init; } = null!;
|
public virtual DbSet<RegistrationInvite> RegistrationInvites { get; init; } = null!;
|
||||||
public virtual DbSet<RegistryItem> RegistryItems { get; init; } = null!;
|
public virtual DbSet<RegistryItem> RegistryItems { get; init; } = null!;
|
||||||
public virtual DbSet<Relay> Relays { get; init; } = null!;
|
public virtual DbSet<Relay> Relays { get; init; } = null!;
|
||||||
public virtual DbSet<RenoteMuting> RenoteMutings { get; init; } = null!;
|
public virtual DbSet<RenoteMuting> RenoteMutings { get; init; } = null!;
|
||||||
|
@ -739,7 +739,7 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
|
||||||
entity.HasOne(d => d.User).WithMany(p => p.PromoReads);
|
entity.HasOne(d => d.User).WithMany(p => p.PromoReads);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<RegistrationTicket>(_ => { });
|
modelBuilder.Entity<RegistrationInvite>(_ => { });
|
||||||
|
|
||||||
modelBuilder.Entity<RegistryItem>(entity => {
|
modelBuilder.Entity<RegistryItem>(entity => {
|
||||||
entity.Property(e => e.CreatedAt).HasComment("The created date of the RegistryItem.");
|
entity.Property(e => e.CreatedAt).HasComment("The created date of the RegistryItem.");
|
||||||
|
|
6018
Iceshrimp.Backend/Core/Database/Migrations/20240216224747_RenameRegistrationInviteTable.Designer.cs
generated
Normal file
6018
Iceshrimp.Backend/Core/Database/Migrations/20240216224747_RenameRegistrationInviteTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,54 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RenameRegistrationInviteTable : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_registration_ticket",
|
||||||
|
table: "registration_ticket");
|
||||||
|
|
||||||
|
migrationBuilder.RenameTable(
|
||||||
|
name: "registration_ticket",
|
||||||
|
newName: "registration_invite");
|
||||||
|
|
||||||
|
migrationBuilder.RenameIndex(
|
||||||
|
name: "IX_registration_ticket_code",
|
||||||
|
table: "registration_invite",
|
||||||
|
newName: "IX_registration_invite_code");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_registration_invite",
|
||||||
|
table: "registration_invite",
|
||||||
|
column: "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_registration_invite",
|
||||||
|
table: "registration_invite");
|
||||||
|
|
||||||
|
migrationBuilder.RenameTable(
|
||||||
|
name: "registration_invite",
|
||||||
|
newName: "registration_ticket");
|
||||||
|
|
||||||
|
migrationBuilder.RenameIndex(
|
||||||
|
name: "IX_registration_invite_code",
|
||||||
|
table: "registration_ticket",
|
||||||
|
newName: "IX_registration_ticket_code");
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_registration_ticket",
|
||||||
|
table: "registration_ticket",
|
||||||
|
column: "id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3513,7 +3513,7 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
b.HasIndex("Code")
|
b.HasIndex("Code")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("registration_ticket");
|
b.ToTable("registration_invite");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.RegistryItem", b =>
|
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.RegistryItem", b =>
|
||||||
|
|
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Database.Tables;
|
namespace Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
|
||||||
[Table("registration_ticket")]
|
[Table("registration_invite")]
|
||||||
[Index("Code", IsUnique = true)]
|
[Index("Code", IsUnique = true)]
|
||||||
public class RegistrationTicket {
|
public class RegistrationInvite {
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
[StringLength(32)]
|
[StringLength(32)]
|
|
@ -203,7 +203,7 @@ public class UserService(
|
||||||
if (security.Value.Registrations == Enums.Registrations.Invite && invite == null)
|
if (security.Value.Registrations == Enums.Registrations.Invite && invite == null)
|
||||||
throw new GracefulException(HttpStatusCode.Forbidden, "Request is missing the invite code");
|
throw new GracefulException(HttpStatusCode.Forbidden, "Request is missing the invite code");
|
||||||
if (security.Value.Registrations == Enums.Registrations.Invite &&
|
if (security.Value.Registrations == Enums.Registrations.Invite &&
|
||||||
!await db.RegistrationTickets.AnyAsync(p => p.Code == invite))
|
!await db.RegistrationInvites.AnyAsync(p => p.Code == invite))
|
||||||
throw new GracefulException(HttpStatusCode.Forbidden, "The specified invite code is invalid");
|
throw new GracefulException(HttpStatusCode.Forbidden, "The specified invite code is invalid");
|
||||||
if (username.Contains('.'))
|
if (username.Contains('.'))
|
||||||
throw new GracefulException(HttpStatusCode.BadRequest, "Username must not contain the dot character");
|
throw new GracefulException(HttpStatusCode.BadRequest, "Username must not contain the dot character");
|
||||||
|
@ -242,7 +242,7 @@ public class UserService(
|
||||||
};
|
};
|
||||||
|
|
||||||
if (security.Value.Registrations == Enums.Registrations.Invite) {
|
if (security.Value.Registrations == Enums.Registrations.Invite) {
|
||||||
var ticket = await db.RegistrationTickets.FirstOrDefaultAsync(p => p.Code == invite);
|
var ticket = await db.RegistrationInvites.FirstOrDefaultAsync(p => p.Code == invite);
|
||||||
if (ticket == null)
|
if (ticket == null)
|
||||||
throw GracefulException.Forbidden("The specified invite code is invalid");
|
throw GracefulException.Forbidden("The specified invite code is invalid");
|
||||||
db.Remove(ticket);
|
db.Remove(ticket);
|
||||||
|
|
Loading…
Add table
Reference in a new issue