Move Password from Phone to Extension

I misunderstood pjsip's concept of endpoints/AoRs. Multiple devices can be bound to a single endpoint, which in turn can have multiple AoRs. So the password should be bound to an Extension, not a Phone.
This commit is contained in:
snow flurry 2023-10-20 12:57:22 -07:00
parent f4552cbccf
commit 4fb88d6cbb
8 changed files with 421 additions and 21 deletions

View file

@ -79,6 +79,9 @@ namespace PhoneToolMX.Data {
ext.HasKey(x => x.Id);
ext.Property(x => x.Id).UseIdentityColumn();
ext.Property(x => x.ExtId).HasComputedColumnSql("\"Id\" + 1000", stored: true);
ext
.Property(p => p.Password)
.HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')");
var phone = modelBuilder.Entity<Phone>();
phone
@ -87,9 +90,6 @@ namespace PhoneToolMX.Data {
phone.HasKey(p => p.Id);
phone.Property(p => p.Id).UseIdentityColumn();
// Randomly generates a 24-char password
phone
.Property(p => p.Password)
.HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')");
// Wallpapers, ringtones, etc
var cd = modelBuilder.Entity<CustomData>();

View file

@ -0,0 +1,358 @@
// <auto-generated />
using System;
using System.Net.NetworkInformation;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using PhoneToolMX.Data;
#nullable disable
namespace PhoneToolMX.Models.Migrations
{
[DbContext(typeof(PTMXContext))]
[Migration("20231020040540_ExtensionPassword")]
partial class ExtensionPassword
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.23")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ExtensionPhone", b =>
{
b.Property<int>("ExtensionsId")
.HasColumnType("integer");
b.Property<int>("PhonesId")
.HasColumnType("integer");
b.HasKey("ExtensionsId", "PhonesId");
b.HasIndex("PhonesId");
b.ToTable("ExtensionPhone");
});
modelBuilder.Entity("ExtensionUser", b =>
{
b.Property<int>("ExtensionsId")
.HasColumnType("integer");
b.Property<string>("OwnersId")
.HasColumnType("text");
b.HasKey("ExtensionsId", "OwnersId");
b.HasIndex("OwnersId");
b.ToTable("ExtensionUser");
});
modelBuilder.Entity("PhoneToolMX.Models.CustomData", b =>
{
b.Property<int?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
b.Property<byte[]>("Data")
.HasColumnType("bytea");
b.Property<int>("DataType")
.HasColumnType("integer");
b.Property<string>("FriendlyName")
.HasMaxLength(16)
.HasColumnType("character varying(16)");
b.Property<int?>("PhoneId")
.HasColumnType("integer");
b.Property<long>("Size")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("PhoneId");
b.ToTable("CustomData");
});
modelBuilder.Entity("PhoneToolMX.Models.Extension", b =>
{
b.Property<int?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
b.Property<string>("DirectoryName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("ExtId")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("integer")
.HasComputedColumnSql("\"Id\" + 1000", true);
b.Property<int?>("HoldMusicId")
.HasColumnType("integer");
b.Property<bool>("Listed")
.HasColumnType("boolean");
b.Property<string>("Password")
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')");
b.HasKey("Id");
b.HasIndex("HoldMusicId");
b.ToTable("Extensions");
});
modelBuilder.Entity("PhoneToolMX.Models.Phone", b =>
{
b.Property<int?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
b.Property<int?>("BackgroundId")
.HasColumnType("integer");
b.Property<string>("FriendlyName")
.IsRequired()
.HasColumnType("text");
b.Property<PhysicalAddress>("MacAddress")
.IsRequired()
.HasColumnType("macaddr");
b.Property<int>("ModelId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("BackgroundId");
b.HasIndex("ModelId");
b.ToTable("Phones");
});
modelBuilder.Entity("PhoneToolMX.Models.PhoneModel", b =>
{
b.Property<int?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
b.Property<long>("MaxExtensions")
.HasColumnType("bigint");
b.Property<string>("ModelName")
.HasColumnType("text");
b.Property<bool>("PreVvxPolycom")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("PhoneModels");
b.HasData(
new
{
Id = 0,
MaxExtensions = 6L,
ModelName = "Polycom VVX300/310",
PreVvxPolycom = false
});
});
modelBuilder.Entity("PhoneToolMX.Models.Role", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("NormalizedName")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Role");
});
modelBuilder.Entity("PhoneToolMX.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.HasColumnType("text");
b.Property<string>("Email")
.HasColumnType("text");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasColumnType("text");
b.Property<string>("NormalizedUserName")
.HasColumnType("text");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("PhoneUser", b =>
{
b.Property<string>("OwnersId")
.HasColumnType("text");
b.Property<int>("PhonesId")
.HasColumnType("integer");
b.HasKey("OwnersId", "PhonesId");
b.HasIndex("PhonesId");
b.ToTable("PhoneUser");
});
modelBuilder.Entity("ExtensionPhone", b =>
{
b.HasOne("PhoneToolMX.Models.Extension", null)
.WithMany()
.HasForeignKey("ExtensionsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PhoneToolMX.Models.Phone", null)
.WithMany()
.HasForeignKey("PhonesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ExtensionUser", b =>
{
b.HasOne("PhoneToolMX.Models.Extension", null)
.WithMany()
.HasForeignKey("ExtensionsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PhoneToolMX.Models.User", null)
.WithMany()
.HasForeignKey("OwnersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("PhoneToolMX.Models.CustomData", b =>
{
b.HasOne("PhoneToolMX.Models.Phone", null)
.WithMany("Ringtones")
.HasForeignKey("PhoneId");
});
modelBuilder.Entity("PhoneToolMX.Models.Extension", b =>
{
b.HasOne("PhoneToolMX.Models.CustomData", "HoldMusic")
.WithMany()
.HasForeignKey("HoldMusicId");
b.Navigation("HoldMusic");
});
modelBuilder.Entity("PhoneToolMX.Models.Phone", b =>
{
b.HasOne("PhoneToolMX.Models.CustomData", "Background")
.WithMany()
.HasForeignKey("BackgroundId");
b.HasOne("PhoneToolMX.Models.PhoneModel", "Model")
.WithMany()
.HasForeignKey("ModelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Background");
b.Navigation("Model");
});
modelBuilder.Entity("PhoneUser", b =>
{
b.HasOne("PhoneToolMX.Models.User", null)
.WithMany()
.HasForeignKey("OwnersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PhoneToolMX.Models.Phone", null)
.WithMany()
.HasForeignKey("PhonesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("PhoneToolMX.Models.Phone", b =>
{
b.Navigation("Ringtones");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PhoneToolMX.Models.Migrations
{
public partial class ExtensionPassword : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Password",
table: "Phones");
migrationBuilder.AddColumn<string>(
name: "Password",
table: "Extensions",
type: "text",
nullable: true,
defaultValueSql: "encode(gen_random_bytes(18), 'base64')");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Password",
table: "Extensions");
migrationBuilder.AddColumn<string>(
name: "Password",
table: "Phones",
type: "text",
nullable: true,
defaultValueSql: "encode(gen_random_bytes(18), 'base64')");
}
}
}

View file

@ -18,7 +18,7 @@ namespace PhoneToolMX.Models.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.16")
.HasAnnotation("ProductVersion", "6.0.23")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -35,7 +35,7 @@ namespace PhoneToolMX.Models.Migrations
b.HasIndex("PhonesId");
b.ToTable("ExtensionPhone", (string)null);
b.ToTable("ExtensionPhone");
});
modelBuilder.Entity("ExtensionUser", b =>
@ -50,16 +50,16 @@ namespace PhoneToolMX.Models.Migrations
b.HasIndex("OwnersId");
b.ToTable("ExtensionUser", (string)null);
b.ToTable("ExtensionUser");
});
modelBuilder.Entity("PhoneToolMX.Models.CustomData", b =>
{
b.Property<int>("Id")
b.Property<int?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int?>("Id"));
b.Property<byte[]>("Data")
.HasColumnType("bytea");
@ -81,7 +81,7 @@ namespace PhoneToolMX.Models.Migrations
b.HasIndex("PhoneId");
b.ToTable("CustomData", (string)null);
b.ToTable("CustomData");
});
modelBuilder.Entity("PhoneToolMX.Models.Extension", b =>
@ -107,11 +107,16 @@ namespace PhoneToolMX.Models.Migrations
b.Property<bool>("Listed")
.HasColumnType("boolean");
b.Property<string>("Password")
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')");
b.HasKey("Id");
b.HasIndex("HoldMusicId");
b.ToTable("Extensions", (string)null);
b.ToTable("Extensions");
});
modelBuilder.Entity("PhoneToolMX.Models.Phone", b =>
@ -136,18 +141,13 @@ namespace PhoneToolMX.Models.Migrations
b.Property<int>("ModelId")
.HasColumnType("integer");
b.Property<string>("Password")
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValueSql("encode(gen_random_bytes(18), 'base64')");
b.HasKey("Id");
b.HasIndex("BackgroundId");
b.HasIndex("ModelId");
b.ToTable("Phones", (string)null);
b.ToTable("Phones");
});
modelBuilder.Entity("PhoneToolMX.Models.PhoneModel", b =>
@ -169,7 +169,7 @@ namespace PhoneToolMX.Models.Migrations
b.HasKey("Id");
b.ToTable("PhoneModels", (string)null);
b.ToTable("PhoneModels");
b.HasData(
new
@ -198,7 +198,7 @@ namespace PhoneToolMX.Models.Migrations
b.HasKey("Id");
b.ToTable("Role", (string)null);
b.ToTable("Role");
});
modelBuilder.Entity("PhoneToolMX.Models.User", b =>
@ -250,7 +250,7 @@ namespace PhoneToolMX.Models.Migrations
b.HasKey("Id");
b.ToTable("Users", (string)null);
b.ToTable("Users");
});
modelBuilder.Entity("PhoneUser", b =>
@ -265,7 +265,7 @@ namespace PhoneToolMX.Models.Migrations
b.HasIndex("PhonesId");
b.ToTable("PhoneUser", (string)null);
b.ToTable("PhoneUser");
});
modelBuilder.Entity("ExtensionPhone", b =>

View file

@ -21,5 +21,7 @@ namespace PhoneToolMX.Models {
[NotMapped]
public string ListViewName => $"{DirectoryName} ({ExtId})";
public string Password { get; set; }
}
}

View file

@ -23,6 +23,5 @@ namespace PhoneToolMX.Models {
public ICollection<Extension> Extensions { get; set; }
public CustomData Background { get; set; }
public ICollection<CustomData> Ringtones { get; set; }
public string Password { get; set; }
}
}

View file

@ -4,6 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>

View file

@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>