forked from adam/discord-bot-shtik
Compare commits
No commits in common. "631347aed80d219a303d25556be2054c2b3d4f36" and "8b41696e0032287bb3b5e5c658505f0d6fec30d6" have entirely different histories.
631347aed8
...
8b41696e00
@ -65,7 +65,8 @@ public class Behaver
|
|||||||
|
|
||||||
internal bool IsSelf(Guid AccountId)
|
internal bool IsSelf(Guid AccountId)
|
||||||
{
|
{
|
||||||
var acc = Rememberer.SearchAccount(a => a.Id == AccountId);
|
var db = new ChattingContext();
|
||||||
|
var acc = db.Accounts.Find(AccountId);
|
||||||
|
|
||||||
return SelfAccounts.Any(acc => acc.Id == AccountId);
|
return SelfAccounts.Any(acc => acc.Id == AccountId);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
public abstract class Behavior
|
public abstract class Behavior
|
||||||
{
|
{
|
||||||
//recommendation: set up your UACs in your constructor.
|
|
||||||
public abstract Task<bool> ActOn(Message message);
|
public abstract Task<bool> ActOn(Message message);
|
||||||
|
|
||||||
public virtual bool ShouldAct(Message message)
|
public virtual bool ShouldAct(Message message)
|
||||||
|
@ -11,37 +11,6 @@ public class TwitchSummon : Behavior
|
|||||||
|
|
||||||
public override string Trigger => "!twitchsummon";
|
public override string Trigger => "!twitchsummon";
|
||||||
|
|
||||||
private static Guid uacID = new Guid("06ad2008-3d48-4ba6-8722-7eaea000ec70");
|
|
||||||
private static UAC myUAC;
|
|
||||||
|
|
||||||
public TwitchSummon()
|
|
||||||
{
|
|
||||||
myUAC = Rememberer.SearchUAC(uac => uac.OwnerId == uacID);
|
|
||||||
if(myUAC == null)
|
|
||||||
{
|
|
||||||
myUAC = new()
|
|
||||||
{
|
|
||||||
OwnerId = uacID,
|
|
||||||
DisplayName = Name
|
|
||||||
};
|
|
||||||
Rememberer.RememberUAC(myUAC);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public override bool ShouldAct(Message message)
|
|
||||||
{
|
|
||||||
if (!base.ShouldAct(message))
|
|
||||||
return false;
|
|
||||||
var uacConf = Rememberer.SearchUAC(uac => uac.OwnerId == uacID);
|
|
||||||
if (uacConf == null)
|
|
||||||
{
|
|
||||||
Console.Error.WriteLine("no UAC conf for TwitchSummon! Set one up!");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"uacConf: {uacConf} users: {uacConf?.Users?.Count()}. message author: {message?.Author}. has an IsUser: {message?.Author?.IsUser}.");
|
|
||||||
Console.WriteLine($"and therefore: {uacConf.Users.Contains(message.Author.IsUser)}");
|
|
||||||
return uacConf.Users.Contains(message.Author.IsUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<bool> ActOn(Message message)
|
public override async Task<bool> ActOn(Message message)
|
||||||
{
|
{
|
||||||
var ti = ProtocolInterfaces.ProtocolList.twitchs.FirstOrDefault();
|
var ti = ProtocolInterfaces.ProtocolList.twitchs.FirstOrDefault();
|
||||||
|
378
Migrations/20250423002254_UAC.Designer.cs
generated
378
Migrations/20250423002254_UAC.Designer.cs
generated
@ -1,378 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
using vassago.Models;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace vassago.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(ChattingContext))]
|
|
||||||
[Migration("20250423002254_UAC")]
|
|
||||||
partial class UAC
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.5")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("AccountUAC", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("AccountInChannelsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("UACsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("AccountInChannelsId", "UACsId");
|
|
||||||
|
|
||||||
b.HasIndex("UACsId");
|
|
||||||
|
|
||||||
b.ToTable("AccountUAC");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("ChannelUAC", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("ChannelsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("UACsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("ChannelsId", "UACsId");
|
|
||||||
|
|
||||||
b.HasIndex("UACsId");
|
|
||||||
|
|
||||||
b.ToTable("ChannelUAC");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UACUser", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("UACsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("UsersId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("UACsId", "UsersId");
|
|
||||||
|
|
||||||
b.HasIndex("UsersId");
|
|
||||||
|
|
||||||
b.ToTable("UACUser");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Account", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("DisplayName")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("ExternalId")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<bool>("IsBot")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<Guid?>("IsUserId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("Protocol")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid?>("SeenInChannelId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("Username")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("IsUserId");
|
|
||||||
|
|
||||||
b.HasIndex("SeenInChannelId");
|
|
||||||
|
|
||||||
b.ToTable("Accounts");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Attachment", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<byte[]>("Content")
|
|
||||||
.HasColumnType("bytea");
|
|
||||||
|
|
||||||
b.Property<string>("ContentType")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<decimal?>("ExternalId")
|
|
||||||
.HasColumnType("numeric(20,0)");
|
|
||||||
|
|
||||||
b.Property<string>("Filename")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid?>("MessageId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<int>("Size")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<string>("Source")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("MessageId");
|
|
||||||
|
|
||||||
b.ToTable("Attachments");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Channel", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<int>("ChannelType")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<string>("DisplayName")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("ExternalId")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<int?>("LewdnessFilterLevel")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<bool?>("LinksAllowed")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<decimal?>("MaxAttachmentBytes")
|
|
||||||
.HasColumnType("numeric(20,0)");
|
|
||||||
|
|
||||||
b.Property<long?>("MaxTextChars")
|
|
||||||
.HasColumnType("bigint");
|
|
||||||
|
|
||||||
b.Property<int?>("MeannessFilterLevel")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<Guid?>("ParentChannelId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("Protocol")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<bool?>("ReactionsPossible")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ParentChannelId");
|
|
||||||
|
|
||||||
b.ToTable("Channels");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Message", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<bool>("ActedOn")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<Guid?>("AuthorId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid?>("ChannelId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("Content")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("ExternalId")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<bool>("MentionsMe")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<string>("Protocol")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<DateTimeOffset>("Timestamp")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("AuthorId");
|
|
||||||
|
|
||||||
b.HasIndex("ChannelId");
|
|
||||||
|
|
||||||
b.ToTable("Messages");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.UAC", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("DisplayName")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid>("OwnerId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("UACs");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.User", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Users");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("AccountUAC", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Account", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("AccountInChannelsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.UAC", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UACsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("ChannelUAC", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Channel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ChannelsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.UAC", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UACsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UACUser", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.UAC", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UACsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.User", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UsersId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Account", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.User", "IsUser")
|
|
||||||
.WithMany("Accounts")
|
|
||||||
.HasForeignKey("IsUserId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.Channel", "SeenInChannel")
|
|
||||||
.WithMany("Users")
|
|
||||||
.HasForeignKey("SeenInChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.Navigation("IsUser");
|
|
||||||
|
|
||||||
b.Navigation("SeenInChannel");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Attachment", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Message", "Message")
|
|
||||||
.WithMany("Attachments")
|
|
||||||
.HasForeignKey("MessageId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.Navigation("Message");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Channel", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Channel", "ParentChannel")
|
|
||||||
.WithMany("SubChannels")
|
|
||||||
.HasForeignKey("ParentChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.Navigation("ParentChannel");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Message", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Account", "Author")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("AuthorId");
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.Channel", "Channel")
|
|
||||||
.WithMany("Messages")
|
|
||||||
.HasForeignKey("ChannelId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
b.Navigation("Author");
|
|
||||||
|
|
||||||
b.Navigation("Channel");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Channel", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Messages");
|
|
||||||
|
|
||||||
b.Navigation("SubChannels");
|
|
||||||
|
|
||||||
b.Navigation("Users");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Message", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Attachments");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.User", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Accounts");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,131 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace vassago.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class UAC : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "UACs",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
OwnerId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
DisplayName = table.Column<string>(type: "text", nullable: true)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_UACs", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "AccountUAC",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
AccountInChannelsId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
UACsId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_AccountUAC", x => new { x.AccountInChannelsId, x.UACsId });
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_AccountUAC_Accounts_AccountInChannelsId",
|
|
||||||
column: x => x.AccountInChannelsId,
|
|
||||||
principalTable: "Accounts",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_AccountUAC_UACs_UACsId",
|
|
||||||
column: x => x.UACsId,
|
|
||||||
principalTable: "UACs",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "ChannelUAC",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
ChannelsId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
UACsId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_ChannelUAC", x => new { x.ChannelsId, x.UACsId });
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_ChannelUAC_Channels_ChannelsId",
|
|
||||||
column: x => x.ChannelsId,
|
|
||||||
principalTable: "Channels",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_ChannelUAC_UACs_UACsId",
|
|
||||||
column: x => x.UACsId,
|
|
||||||
principalTable: "UACs",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "UACUser",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
UACsId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
||||||
UsersId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_UACUser", x => new { x.UACsId, x.UsersId });
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_UACUser_UACs_UACsId",
|
|
||||||
column: x => x.UACsId,
|
|
||||||
principalTable: "UACs",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_UACUser_Users_UsersId",
|
|
||||||
column: x => x.UsersId,
|
|
||||||
principalTable: "Users",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_AccountUAC_UACsId",
|
|
||||||
table: "AccountUAC",
|
|
||||||
column: "UACsId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_ChannelUAC_UACsId",
|
|
||||||
table: "ChannelUAC",
|
|
||||||
column: "UACsId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_UACUser_UsersId",
|
|
||||||
table: "UACUser",
|
|
||||||
column: "UsersId");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "AccountUAC");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "ChannelUAC");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "UACUser");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "UACs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,51 +22,6 @@ namespace vassago.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.Entity("AccountUAC", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("AccountInChannelsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("UACsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("AccountInChannelsId", "UACsId");
|
|
||||||
|
|
||||||
b.HasIndex("UACsId");
|
|
||||||
|
|
||||||
b.ToTable("AccountUAC");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("ChannelUAC", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("ChannelsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("UACsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("ChannelsId", "UACsId");
|
|
||||||
|
|
||||||
b.HasIndex("UACsId");
|
|
||||||
|
|
||||||
b.ToTable("ChannelUAC");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UACUser", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("UACsId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("UsersId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("UACsId", "UsersId");
|
|
||||||
|
|
||||||
b.HasIndex("UsersId");
|
|
||||||
|
|
||||||
b.ToTable("UACUser");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Account", b =>
|
modelBuilder.Entity("vassago.Models.Account", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@ -225,23 +180,6 @@ namespace vassago.Migrations
|
|||||||
b.ToTable("Messages");
|
b.ToTable("Messages");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.UAC", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("DisplayName")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid>("OwnerId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("UACs");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.User", b =>
|
modelBuilder.Entity("vassago.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@ -253,51 +191,6 @@ namespace vassago.Migrations
|
|||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AccountUAC", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Account", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("AccountInChannelsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.UAC", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UACsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("ChannelUAC", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.Channel", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ChannelsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.UAC", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UACsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UACUser", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("vassago.Models.UAC", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UACsId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("vassago.Models.User", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UsersId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("vassago.Models.Account", b =>
|
modelBuilder.Entity("vassago.Models.Account", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("vassago.Models.User", "IsUser")
|
b.HasOne("vassago.Models.User", "IsUser")
|
||||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
public class Account
|
public class Account
|
||||||
{
|
{
|
||||||
@ -27,7 +28,6 @@ public class Account
|
|||||||
public bool IsBot { get; set; } //webhook counts
|
public bool IsBot { get; set; } //webhook counts
|
||||||
public Channel SeenInChannel { get; set; }
|
public Channel SeenInChannel { get; set; }
|
||||||
public string Protocol { get; set; }
|
public string Protocol { get; set; }
|
||||||
public List<UAC> UACs { get; set; }
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public User IsUser {get; set;}
|
public User IsUser {get; set;}
|
||||||
}
|
}
|
@ -35,8 +35,6 @@ public class Channel
|
|||||||
public Enumerations.LewdnessFilterLevel? LewdnessFilterLevel { get; set; }
|
public Enumerations.LewdnessFilterLevel? LewdnessFilterLevel { get; set; }
|
||||||
public Enumerations.MeannessFilterLevel? MeannessFilterLevel { get; set; }
|
public Enumerations.MeannessFilterLevel? MeannessFilterLevel { get; set; }
|
||||||
|
|
||||||
public List<UAC> UACs { get; set; }
|
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public Func<string, string, Task> SendFile;
|
public Func<string, string, Task> SendFile;
|
||||||
|
|
||||||
@ -113,4 +111,4 @@ public class DefinitePermissionSettings
|
|||||||
public bool ReactionsPossible { get; set; }
|
public bool ReactionsPossible { get; set; }
|
||||||
public Enumerations.LewdnessFilterLevel LewdnessFilterLevel { get; set; }
|
public Enumerations.LewdnessFilterLevel LewdnessFilterLevel { get; set; }
|
||||||
public Enumerations.MeannessFilterLevel MeannessFilterLevel { get; set; }
|
public Enumerations.MeannessFilterLevel MeannessFilterLevel { get; set; }
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ public class ChattingContext : DbContext
|
|||||||
{
|
{
|
||||||
public DbSet<Attachment> Attachments { get; set; }
|
public DbSet<Attachment> Attachments { get; set; }
|
||||||
public DbSet<Channel> Channels { get; set; }
|
public DbSet<Channel> Channels { get; set; }
|
||||||
public DbSet<UAC> UACs { get; set; }
|
//public DbSet<Emoji> Emoji {get;set;}
|
||||||
public DbSet<Message> Messages { get; set; }
|
public DbSet<Message> Messages { get; set; }
|
||||||
public DbSet<Account> Accounts { get; set; }
|
public DbSet<Account> Accounts { get; set; }
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
@ -19,4 +19,4 @@ public class ChattingContext : DbContext
|
|||||||
optionsBuilder.UseNpgsql(Shared.DBConnectionString);
|
optionsBuilder.UseNpgsql(Shared.DBConnectionString);
|
||||||
//.EnableSensitiveDataLogging(true); //"sensitive" is one thing. writing "did something" every time you think a thought is a different thing.
|
//.EnableSensitiveDataLogging(true); //"sensitive" is one thing. writing "did something" every time you think a thought is a different thing.
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,23 +0,0 @@
|
|||||||
namespace vassago.Models;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using vassago.Models;
|
|
||||||
|
|
||||||
public class UAC
|
|
||||||
{
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
|
|
||||||
///<summary indulgence="haiku-like">
|
|
||||||
///behaviors will have
|
|
||||||
///a hardcoded ID thing
|
|
||||||
///so they can find theirs.
|
|
||||||
///</summary>
|
|
||||||
public Guid OwnerId { get; set;}
|
|
||||||
public string DisplayName { get; set; }
|
|
||||||
public List<Account> AccountInChannels { get; set; }
|
|
||||||
public List<Channel> Channels { get; set; }
|
|
||||||
public List<User> Users { get; set; }
|
|
||||||
}
|
|
@ -13,8 +13,6 @@ public class User
|
|||||||
[DeleteBehavior(DeleteBehavior.Cascade)]
|
[DeleteBehavior(DeleteBehavior.Cascade)]
|
||||||
public List<Account> Accounts { get; set; }
|
public List<Account> Accounts { get; set; }
|
||||||
|
|
||||||
public List<UAC> UACs { get; set; }
|
|
||||||
|
|
||||||
//if I ever get lots and lots of tags, or some automatic way to register a feature's arbitrary tags, then I can move this off.
|
//if I ever get lots and lots of tags, or some automatic way to register a feature's arbitrary tags, then I can move this off.
|
||||||
//public bool Tag_CanTwitchSummon { get; set; }
|
//public bool Tag_CanTwitchSummon { get; set; }
|
||||||
|
|
||||||
@ -32,8 +30,8 @@ public class User
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $"[accountless {Id}]";
|
return $"[accountless {Id}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -142,9 +142,8 @@ public class TwitchInterface
|
|||||||
|
|
||||||
private Account UpsertAccount(string username, Channel inChannel)
|
private Account UpsertAccount(string username, Channel inChannel)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"upserting twitch account. username: {username}. inChannel: {inChannel?.Id}");
|
var acc = Rememberer.SearchAccount(ui => ui.ExternalId == username && ui.SeenInChannel.ExternalId == inChannel.ToString());
|
||||||
var acc = Rememberer.SearchAccount(ui => ui.ExternalId == username && ui.SeenInChannel.ExternalId == inChannel.ExternalId);
|
Console.WriteLine($"upserting account, retrieved {acc?.Id}.");
|
||||||
Console.WriteLine($"upserting twitch account, retrieved {acc?.Id}.");
|
|
||||||
if (acc != null)
|
if (acc != null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"acc's usser: {acc.IsUser?.Id}");
|
Console.WriteLine($"acc's usser: {acc.IsUser?.Id}");
|
||||||
@ -205,7 +204,7 @@ public class TwitchInterface
|
|||||||
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
||||||
c = Rememberer.RememberChannel(c);
|
c = Rememberer.RememberChannel(c);
|
||||||
|
|
||||||
var selfAccountInChannel = c.Users?.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId);
|
var selfAccountInChannel = c.Users?.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId.ToString());
|
||||||
if(selfAccountInChannel == null)
|
if(selfAccountInChannel == null)
|
||||||
{
|
{
|
||||||
selfAccountInChannel = UpsertAccount(selfAccountInProtocol.Username, c);
|
selfAccountInChannel = UpsertAccount(selfAccountInProtocol.Username, c);
|
||||||
@ -248,7 +247,7 @@ Channel c = Rememberer.SearchChannel(ci => ci.ExternalId == $"w_{whisperWith}"
|
|||||||
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); };
|
||||||
c = Rememberer.RememberChannel(c);
|
c = Rememberer.RememberChannel(c);
|
||||||
|
|
||||||
var selfAccountInChannel = c.Users.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId);
|
var selfAccountInChannel = c.Users.FirstOrDefault(a => a.ExternalId == selfAccountInProtocol.ExternalId.ToString());
|
||||||
if(selfAccountInChannel == null)
|
if(selfAccountInChannel == null)
|
||||||
{
|
{
|
||||||
selfAccountInChannel = UpsertAccount(selfAccountInChannel.Username, c);
|
selfAccountInChannel = UpsertAccount(selfAccountInChannel.Username, c);
|
||||||
|
@ -13,7 +13,7 @@ public static class Rememberer
|
|||||||
{
|
{
|
||||||
Account toReturn;
|
Account toReturn;
|
||||||
dbAccessSemaphore.Wait();
|
dbAccessSemaphore.Wait();
|
||||||
toReturn = db.Accounts?.Include(a => a.IsUser)?.FirstOrDefault(predicate);
|
toReturn = db.Accounts.Include(a => a.IsUser).FirstOrDefault(predicate);
|
||||||
dbAccessSemaphore.Release();
|
dbAccessSemaphore.Release();
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ public static class Rememberer
|
|||||||
dbAccessSemaphore.Wait();
|
dbAccessSemaphore.Wait();
|
||||||
db.Accounts.Remove(toForget);
|
db.Accounts.Remove(toForget);
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
dbAccessSemaphore.Release();
|
dbAccessSemaphore.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void ForgetChannel(Channel toForget)
|
public static void ForgetChannel(Channel toForget)
|
||||||
@ -162,28 +162,4 @@ public static class Rememberer
|
|||||||
dbAccessSemaphore.Release();
|
dbAccessSemaphore.Release();
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
public static List<UAC> UACsOverview()
|
|
||||||
{
|
|
||||||
List<UAC> toReturn;
|
|
||||||
dbAccessSemaphore.Wait();
|
|
||||||
toReturn = db.UACs.Include(uac => uac.Users).Include(uac => uac.Channels).Include(uac => uac.AccountInChannels).ToList();
|
|
||||||
dbAccessSemaphore.Release();
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
public static UAC SearchUAC(Expression<Func<UAC, bool>> predicate)
|
|
||||||
{
|
|
||||||
UAC toReturn;
|
|
||||||
dbAccessSemaphore.Wait();
|
|
||||||
toReturn = db.UACs.Include(uac => uac.Users).Include(uac => uac.Channels).Include(uac => uac.AccountInChannels)
|
|
||||||
.FirstOrDefault(predicate);
|
|
||||||
dbAccessSemaphore.Release();
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
public static void RememberUAC(UAC toRemember)
|
|
||||||
{
|
|
||||||
dbAccessSemaphore.Wait();
|
|
||||||
db.Update(toRemember);
|
|
||||||
db.SaveChanges();
|
|
||||||
dbAccessSemaphore.Release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,61 +25,10 @@ public class HomeController : Controller
|
|||||||
Console.WriteLine($"accounts: {allAccounts?.Count ?? 0}, channels: {allChannels?.Count ?? 0}");
|
Console.WriteLine($"accounts: {allAccounts?.Count ?? 0}, channels: {allChannels?.Count ?? 0}");
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append('[');
|
sb.Append('[');
|
||||||
|
sb.Append("{text: \"channels\", expanded:true, nodes: [");
|
||||||
|
|
||||||
//UACs
|
|
||||||
var allUACs = Rememberer.UACsOverview();
|
|
||||||
var first = true;
|
var first = true;
|
||||||
if(allUACs.Any())
|
|
||||||
{
|
|
||||||
sb.Append("{text: \"uacs\", expanded:true, nodes: [");
|
|
||||||
first=true;
|
|
||||||
foreach(var uac in allUACs)
|
|
||||||
{
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.Append(',');
|
|
||||||
}
|
|
||||||
sb.Append($"{{\"text\": \"<a href=\\\"{Url.ActionLink(action: "Details", controller: "UACs", values: new {id = uac.Id})}\\\">{uac.DisplayName}</a>\"}}");
|
|
||||||
}
|
|
||||||
sb.Append("]}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.Append("{text: \"uacs (0)\", }");
|
|
||||||
}
|
|
||||||
|
|
||||||
//users
|
|
||||||
var users = Rememberer.UsersOverview();
|
|
||||||
if(users.Any())
|
|
||||||
{
|
|
||||||
sb.Append(",{text: \"users\", expanded:true, nodes: [");
|
|
||||||
first=true;
|
|
||||||
//refresh list; we'll be knocking them out again in serializeUser
|
|
||||||
allAccounts = Rememberer.AccountsOverview();
|
|
||||||
foreach(var user in users)
|
|
||||||
{
|
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sb.Append(',');
|
|
||||||
}
|
|
||||||
serializeUser(ref sb, ref allAccounts, user);
|
|
||||||
}
|
|
||||||
sb.Append("]}");
|
|
||||||
}
|
|
||||||
|
|
||||||
//type error, e is not defined
|
|
||||||
//channels
|
|
||||||
sb.Append(",{text: \"channels\", expanded:true, nodes: [");
|
|
||||||
var topLevelChannels = Rememberer.ChannelsOverview().Where(x => x.ParentChannel == null);
|
var topLevelChannels = Rememberer.ChannelsOverview().Where(x => x.ParentChannel == null);
|
||||||
first = true;
|
|
||||||
foreach (var topLevelChannel in topLevelChannels)
|
foreach (var topLevelChannel in topLevelChannels)
|
||||||
{
|
{
|
||||||
if (first)
|
if (first)
|
||||||
@ -135,8 +84,28 @@ public class HomeController : Controller
|
|||||||
}
|
}
|
||||||
sb.Append("]}");
|
sb.Append("]}");
|
||||||
}
|
}
|
||||||
|
var users = Rememberer.UsersOverview();// _db.Users.ToList();
|
||||||
sb.Append("]");
|
if(users.Any())
|
||||||
|
{
|
||||||
|
sb.Append(",{text: \"users\", expanded:true, nodes: [");
|
||||||
|
first=true;
|
||||||
|
//refresh list; we'll be knocking them out again in serializeUser
|
||||||
|
allAccounts = Rememberer.AccountsOverview();
|
||||||
|
foreach(var user in users)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append(',');
|
||||||
|
}
|
||||||
|
serializeUser(ref sb, ref allAccounts, user);
|
||||||
|
}
|
||||||
|
sb.Append("]}");
|
||||||
|
}
|
||||||
|
sb.Append(']');
|
||||||
ViewData.Add("treeString", sb.ToString());
|
ViewData.Add("treeString", sb.ToString());
|
||||||
return View("Index");
|
return View("Index");
|
||||||
}
|
}
|
||||||
@ -152,6 +121,7 @@ public class HomeController : Controller
|
|||||||
if (currentChannel.SubChannels != null || theseAccounts != null)
|
if (currentChannel.SubChannels != null || theseAccounts != null)
|
||||||
{
|
{
|
||||||
sb.Append(", \"nodes\": [");
|
sb.Append(", \"nodes\": [");
|
||||||
|
}
|
||||||
if (currentChannel.SubChannels != null)
|
if (currentChannel.SubChannels != null)
|
||||||
{
|
{
|
||||||
foreach (var subChannel in currentChannel.SubChannels)
|
foreach (var subChannel in currentChannel.SubChannels)
|
||||||
@ -189,9 +159,7 @@ public class HomeController : Controller
|
|||||||
}
|
}
|
||||||
sb.Append("]}");
|
sb.Append("]}");
|
||||||
}
|
}
|
||||||
sb.Append(']');
|
sb.Append("]}");
|
||||||
}
|
|
||||||
sb.Append('}');
|
|
||||||
}
|
}
|
||||||
private void serializeAccount(ref StringBuilder sb, Account currentAccount)
|
private void serializeAccount(ref StringBuilder sb, Account currentAccount)
|
||||||
{
|
{
|
||||||
@ -203,21 +171,17 @@ public class HomeController : Controller
|
|||||||
sb.Append(currentUser.DisplayName);
|
sb.Append(currentUser.DisplayName);
|
||||||
sb.Append("</a>\", ");
|
sb.Append("</a>\", ");
|
||||||
var ownedAccounts = allAccounts.Where(a => a.IsUser == currentUser);
|
var ownedAccounts = allAccounts.Where(a => a.IsUser == currentUser);
|
||||||
if (ownedAccounts?.Count() > 0)
|
sb.Append("nodes: [");
|
||||||
|
sb.Append($"{{\"text\": \"owned accounts:\", \"expanded\":true, \"nodes\": [");
|
||||||
|
if (ownedAccounts != null)
|
||||||
{
|
{
|
||||||
sb.Append("nodes: [");
|
|
||||||
sb.Append($"{{\"text\": \"owned accounts:\", \"expanded\":true, \"nodes\": [");
|
|
||||||
var first = true;
|
|
||||||
foreach (var acc in ownedAccounts)
|
foreach (var acc in ownedAccounts)
|
||||||
{
|
{
|
||||||
if(!first)
|
|
||||||
sb.Append(',');
|
|
||||||
serializeAccount(ref sb, acc);
|
serializeAccount(ref sb, acc);
|
||||||
first = false;
|
sb.Append(',');
|
||||||
}
|
}
|
||||||
sb.Append("]}]");
|
|
||||||
}
|
}
|
||||||
sb.Append("}");
|
sb.Append("]}]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using vassago.Models;
|
|
||||||
using vassago.WebInterface.Models;
|
|
||||||
|
|
||||||
namespace vassago.WebInterface.Controllers;
|
|
||||||
|
|
||||||
public class UACsController() : Controller
|
|
||||||
{
|
|
||||||
public IActionResult Index()
|
|
||||||
{
|
|
||||||
return View(Rememberer.UACsOverview());
|
|
||||||
}
|
|
||||||
public IActionResult Details(Guid id)
|
|
||||||
{
|
|
||||||
return View(Rememberer.SearchUAC(uac => uac.Id == id));
|
|
||||||
}
|
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
||||||
public IActionResult Error()
|
|
||||||
{
|
|
||||||
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
||||||
}
|
|
||||||
}
|
|
@ -36,4 +36,4 @@ public class UsersController(ChattingContext db) : Controller
|
|||||||
{
|
{
|
||||||
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,213 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using vassago.Models;
|
|
||||||
using vassago.ProtocolInterfaces.DiscordInterface;
|
|
||||||
|
|
||||||
namespace vassago.Controllers.api;
|
|
||||||
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController]
|
|
||||||
public class UACController: ControllerBase
|
|
||||||
{
|
|
||||||
private readonly ILogger<UACController> _logger;
|
|
||||||
|
|
||||||
public UACController(ILogger<UACController> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
//microsoft: "you can't have multiple [FromBody]. The reason for this rule is some bullshti about storage buffers."
|
|
||||||
//cool story, bro. nobody gives a fuck, look at the boilerplate you've necessitated.
|
|
||||||
public class extraSpecialObjectReadGlorifiedTupleFor_LinkChannel
|
|
||||||
{
|
|
||||||
public Guid uac_guid;
|
|
||||||
public Guid channel_guid;
|
|
||||||
}
|
|
||||||
[HttpPatch]
|
|
||||||
[Route("LinkChannel")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public IActionResult LinkChannel([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkChannel req)
|
|
||||||
{
|
|
||||||
var uac_guid = req.uac_guid;
|
|
||||||
var channel_guid = req.channel_guid;
|
|
||||||
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
|
|
||||||
if (uacFromDb == null)
|
|
||||||
{
|
|
||||||
var err =$"attempt to link channel for uac {uac_guid}, not found";
|
|
||||||
_logger.LogError(err);
|
|
||||||
return NotFound(err);
|
|
||||||
}
|
|
||||||
var channelFromDb = Rememberer.SearchChannel(c => c.Id == channel_guid);
|
|
||||||
if (channelFromDb == null)
|
|
||||||
{
|
|
||||||
var err = $"attempt to link channel for channel {channel_guid}, not found";
|
|
||||||
_logger.LogError(err);
|
|
||||||
return NotFound(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
uacFromDb.Channels ??= [];
|
|
||||||
if (uacFromDb.Channels.Contains(channelFromDb))
|
|
||||||
{
|
|
||||||
return BadRequest("channel already linked");
|
|
||||||
}
|
|
||||||
uacFromDb.Channels.Add(channelFromDb);
|
|
||||||
Rememberer.RememberUAC(uacFromDb);
|
|
||||||
return Ok(uacFromDb);
|
|
||||||
}
|
|
||||||
public class extraSpecialObjectReadGlorifiedTupleFor_LinkUser
|
|
||||||
{
|
|
||||||
public Guid uac_guid;
|
|
||||||
public Guid user_guid;
|
|
||||||
}
|
|
||||||
[HttpPatch]
|
|
||||||
[Route("LinkUser")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public IActionResult LinkUser([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkUser req)
|
|
||||||
{
|
|
||||||
var uac_guid = req.uac_guid;
|
|
||||||
var user_guid = req.user_guid;
|
|
||||||
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
|
|
||||||
if (uacFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to link channal for uac {uac_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
var userFromDb = Rememberer.SearchUser(c => c.Id == user_guid);
|
|
||||||
if (userFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to link user for user {user_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
uacFromDb.Users ??= [];
|
|
||||||
if (uacFromDb.Users.Contains(userFromDb))
|
|
||||||
{
|
|
||||||
return BadRequest("user already linked");
|
|
||||||
}
|
|
||||||
uacFromDb.Users.Add(userFromDb);
|
|
||||||
Rememberer.RememberUAC(uacFromDb);
|
|
||||||
return Ok(uacFromDb);
|
|
||||||
}
|
|
||||||
public class extraSpecialObjectReadGlorifiedTupleFor_LinkAccount
|
|
||||||
{
|
|
||||||
public Guid uac_guid;
|
|
||||||
public Guid account_guid;
|
|
||||||
}
|
|
||||||
[HttpPatch]
|
|
||||||
[Route("LinkAccount")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public IActionResult LinkAccount([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkAccount req)
|
|
||||||
{
|
|
||||||
var uac_guid = req.uac_guid;
|
|
||||||
var account_guid = req.account_guid;
|
|
||||||
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
|
|
||||||
if (uacFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to link channal for uac {uac_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
var accountFromDb = Rememberer.SearchAccount(c => c.Id == account_guid);
|
|
||||||
if (accountFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to link account for user {account_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
uacFromDb.AccountInChannels ??= [];
|
|
||||||
if (uacFromDb.AccountInChannels.Contains(accountFromDb))
|
|
||||||
{
|
|
||||||
return BadRequest("account already linked");
|
|
||||||
}
|
|
||||||
uacFromDb.AccountInChannels.Add(accountFromDb);
|
|
||||||
Rememberer.RememberUAC(uacFromDb);
|
|
||||||
return Ok(uacFromDb);
|
|
||||||
}
|
|
||||||
[HttpPatch]
|
|
||||||
[Route("UnlinkUser")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public IActionResult UnlinkUser([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkUser req)
|
|
||||||
{
|
|
||||||
var uac_guid = req.uac_guid;
|
|
||||||
var user_guid = req.user_guid;
|
|
||||||
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
|
|
||||||
if (uacFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to unlink uac for uac {uac_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
var userFromDb = Rememberer.SearchUser(c => c.Id == user_guid);
|
|
||||||
if (userFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to unlink user for user {user_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
uacFromDb.Users ??= [];
|
|
||||||
if (!uacFromDb.Users.Contains(userFromDb))
|
|
||||||
{
|
|
||||||
return BadRequest("user not linked");
|
|
||||||
}
|
|
||||||
uacFromDb.Users.Remove(userFromDb);
|
|
||||||
Rememberer.RememberUAC(uacFromDb);
|
|
||||||
return Ok(uacFromDb);
|
|
||||||
}
|
|
||||||
[HttpPatch]
|
|
||||||
[Route("UnlinkAccount")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public IActionResult UnlinkAccount([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkAccount req)
|
|
||||||
{
|
|
||||||
var uac_guid = req.uac_guid;
|
|
||||||
var account_guid = req.account_guid;
|
|
||||||
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
|
|
||||||
if (uacFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to unlink uac for uac {uac_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
var accountFromDb = Rememberer.SearchAccount(a => a.Id == account_guid);
|
|
||||||
if (accountFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to unlink account for user {account_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
uacFromDb.AccountInChannels ??= [];
|
|
||||||
if (!uacFromDb.AccountInChannels.Contains(accountFromDb))
|
|
||||||
{
|
|
||||||
return BadRequest("account not linked");
|
|
||||||
}
|
|
||||||
uacFromDb.AccountInChannels.Remove(accountFromDb);
|
|
||||||
Rememberer.RememberUAC(uacFromDb);
|
|
||||||
return Ok(uacFromDb);
|
|
||||||
}
|
|
||||||
[HttpPatch]
|
|
||||||
[Route("UnlinkChannel")]
|
|
||||||
[Produces("application/json")]
|
|
||||||
public IActionResult UnlinkChannel([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkChannel req)
|
|
||||||
{
|
|
||||||
var uac_guid = req.uac_guid;
|
|
||||||
var channel_guid = req.channel_guid;
|
|
||||||
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
|
|
||||||
if (uacFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to unlink channal for uac {uac_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
var channelFromDb = Rememberer.SearchChannel(c => c.Id == channel_guid);
|
|
||||||
if (channelFromDb == null)
|
|
||||||
{
|
|
||||||
_logger.LogError($"attempt to unlink user for user {channel_guid}, not found");
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
uacFromDb.Users ??= [];
|
|
||||||
if (!uacFromDb.Channels.Contains(channelFromDb))
|
|
||||||
{
|
|
||||||
return BadRequest("user not linked");
|
|
||||||
}
|
|
||||||
uacFromDb.Channels.Remove(channelFromDb);
|
|
||||||
Rememberer.RememberUAC(uacFromDb);
|
|
||||||
return Ok(uacFromDb);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,11 +7,10 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function getTree() {
|
function getTree() {
|
||||||
var tree = @Html.Raw(ViewData["treeString"]);
|
var tree = @Html.Raw(ViewData["treeString"]);
|
||||||
console.log('tree');
|
console.log(tree);
|
||||||
console.log('@ViewData["treeString"]');
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#tree').bstreeview({ data: getTree() });
|
$('#tree').bstreeview({ data: getTree() });
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
@ -1,214 +0,0 @@
|
|||||||
@using System.ComponentModel
|
|
||||||
@using Newtonsoft.Json
|
|
||||||
@using System.Text;
|
|
||||||
@model UAC
|
|
||||||
|
|
||||||
<a href="/">home</a>/
|
|
||||||
@Html.Raw(ViewData["breadcrumbs"])
|
|
||||||
|
|
||||||
<table class="table">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Display Name</th>
|
|
||||||
<td>@Model.DisplayName</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Channels</th>
|
|
||||||
<td>
|
|
||||||
@Html.Raw("<div id=\"channelsTree\"></div>")
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">Users</th>
|
|
||||||
<td>
|
|
||||||
@Html.Raw("<div id=\"usersTree\"></div>")
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">AccountInChannels</th>
|
|
||||||
<td>
|
|
||||||
@Html.Raw("<div id=\"accountsTree\"></div>")
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div id="add-modal" class="modal" tabindex="-1" role="dialog">
|
|
||||||
<div class="modal-dialog" role="document">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title">Insert GUID</h5>
|
|
||||||
<button type="button" class="btn btn-close" data-dismiss="add-modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<p>
|
|
||||||
<ul>
|
|
||||||
<li>//TODO: search</li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<input id="addmodaltext" type="text" />
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button id="modalsubmit" type="button" class="btn btn-primary">Save changes</button>
|
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="add-modal">Close</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="remove-modal" class="modal" tabindex="-1" role="dialog">
|
|
||||||
<div class="modal-dialog" role="document">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title">Confirm</h5>
|
|
||||||
<button type="button" class="btn-close" data-dismiss="remove-modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<p>
|
|
||||||
are you sure you wnat to unlink
|
|
||||||
<input id="removeModalText" enabled="false" type="text" />
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
to be clear; this is going to "unlink", not like.. delete.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button id="modalsubmit" type="button" class="btn btn-danger">unlink</button>
|
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="remove-modal">Close</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
@section Scripts{
|
|
||||||
<script type="text/javascript">
|
|
||||||
function addChannel(){
|
|
||||||
let modalbutton = document.querySelector("#add-modal button#modalsubmit");
|
|
||||||
modalbutton.onclick = addChannelSubmit;
|
|
||||||
$("#add-modal").modal("show");
|
|
||||||
}
|
|
||||||
function addChannelSubmit(){
|
|
||||||
let guid = document.querySelector("#add-modal #addmodaltext").value;
|
|
||||||
linkUAC_Channel(guid, () => { window.location.reload(); });
|
|
||||||
$("#add-modal").modal("hide");
|
|
||||||
console.log(guid);
|
|
||||||
}
|
|
||||||
function addUser(){
|
|
||||||
let modalbutton = document.querySelector("#add-modal button#modalsubmit");
|
|
||||||
modalbutton.onclick = addUserSubmit;
|
|
||||||
$("#add-modal").modal("show");
|
|
||||||
}
|
|
||||||
function addUserSubmit(){
|
|
||||||
let guid = document.querySelector("#add-modal #addmodaltext").value;
|
|
||||||
linkUAC_User(guid, () => {window.location.reload(); });
|
|
||||||
$("#add-modal").modal("hide");
|
|
||||||
console.log(guid);
|
|
||||||
}
|
|
||||||
function addAccount(){
|
|
||||||
let modalbutton = document.querySelector("#add-modal button#modalsubmit");
|
|
||||||
modalbutton.onclick = addAccountSubmit;
|
|
||||||
$("#add-modal").modal("show");
|
|
||||||
}
|
|
||||||
function addAccountSubmit(){
|
|
||||||
let guid = document.querySelector("#add-modal #addmodaltext").value;
|
|
||||||
linkUAC_Account(guid, () => { window.location.reload(); });
|
|
||||||
$("#add-modal").modal("hide");
|
|
||||||
console.log(guid);
|
|
||||||
}
|
|
||||||
function removeUser(guid){
|
|
||||||
document.querySelector("#remove-modal #removeModalText").value = guid;
|
|
||||||
let modalbutton = document.querySelector("#remove-modal button#modalsubmit");
|
|
||||||
modalbutton.onclick = removeUserSubmit;
|
|
||||||
$("#remove-modal").modal("show");
|
|
||||||
}
|
|
||||||
function removeUserSubmit(){
|
|
||||||
let guid = document.querySelector("#remove-modal #removeModalText").value;
|
|
||||||
unlinkUAC_User(guid, () => { window.location.reload(); });
|
|
||||||
$("#remove-modal").modal("hide");
|
|
||||||
}
|
|
||||||
function removeChannel(guid){
|
|
||||||
document.querySelector("#remove-modal #removeModalText").value = guid;
|
|
||||||
let modalbutton = document.querySelector("#remove-modal button#modalsubmit");
|
|
||||||
modalbutton.onclick = removeChannelSubmit;
|
|
||||||
$("#remove-modal").modal("show");
|
|
||||||
}
|
|
||||||
function removeChannelSubmit(){
|
|
||||||
let guid = document.querySelector("#remove-modal #removeModalText").value;
|
|
||||||
unlinkUAC_Channel(guid, () => { window.location.reload(); });
|
|
||||||
$("#remove-modal").modal("hide");
|
|
||||||
}
|
|
||||||
function removeAccount(guid){
|
|
||||||
document.querySelector("#remove-modal #removeModalText").value = guid;
|
|
||||||
let modalbutton = document.querySelector("#remove-modal button#modalsubmit");
|
|
||||||
modalbutton.onclick = removeAccountSubmit;
|
|
||||||
$("#remove-modal").modal("show");
|
|
||||||
}
|
|
||||||
function removeAccountSubmit(){
|
|
||||||
let guid = document.querySelector("#remove-modal #removeModalText").value;
|
|
||||||
unlinkUAC_Account(guid , () => { window.location.reload(); });
|
|
||||||
$("#remove-modal").modal("hide");
|
|
||||||
}
|
|
||||||
function channelsTree() {
|
|
||||||
@{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append("[{text: \"Channels\", \"expanded\":true, nodes: [");
|
|
||||||
|
|
||||||
sb.Append($"{{text: \"<button type=\\\"button\\\" class=\\\"btn btn-primary\\\" onclick=\\\"addChannel()\\\">add channel</button>\"}}");
|
|
||||||
foreach (var acc in Model.Channels?.OrderBy(a => a.DisplayName))
|
|
||||||
{
|
|
||||||
sb.Append(',');
|
|
||||||
sb.Append($"{{text: \"<a href=\\\"/Channels/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn btn-danger\\\" onclick=\\\"removeChannel('{acc.Id}')\\\">remove</button>\"}}");
|
|
||||||
}
|
|
||||||
sb.Append("]}]");
|
|
||||||
}
|
|
||||||
var tree = @Html.Raw(sb.ToString());
|
|
||||||
return tree;
|
|
||||||
}
|
|
||||||
function usersTree() {
|
|
||||||
@{
|
|
||||||
sb = new StringBuilder();
|
|
||||||
sb.Append("[{text: \"Users\", \"expanded\":true, nodes: [");
|
|
||||||
|
|
||||||
sb.Append($"{{text: \"<button type=\\\"button\\\" class=\\\"btn btn-primary\\\" onclick=\\\"addUser()\\\">add user</button>\"}}");
|
|
||||||
foreach (var acc in Model.Users?.OrderBy(a => a.DisplayName))
|
|
||||||
{
|
|
||||||
sb.Append(',');
|
|
||||||
sb.Append($"{{text: \"<a href=\\\"/Users/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn btn-danger\\\" onclick=\\\"removeUser('{acc.Id}')\\\">remove</button>\"}}");
|
|
||||||
}
|
|
||||||
sb.Append("]}]");
|
|
||||||
}
|
|
||||||
var tree = @Html.Raw(sb.ToString());
|
|
||||||
return tree;
|
|
||||||
}
|
|
||||||
function accountsTree() {
|
|
||||||
@{
|
|
||||||
sb = new StringBuilder();
|
|
||||||
sb.Append("[{text: \"Accounts\", \"expanded\":true, nodes: [");
|
|
||||||
|
|
||||||
sb.Append($"{{text: \"<button type=\\\"button\\\" class=\\\"btn btn-primary\\\" onclick=\\\"addAccount()\\\">add account</button>\"}}");
|
|
||||||
foreach (var acc in Model.AccountInChannels?.OrderBy(a => a.DisplayName))
|
|
||||||
{
|
|
||||||
sb.Append(',');
|
|
||||||
sb.Append($"{{text: \"<a href=\\\"/Accounts/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn btn-danger\\\" onclick=\\\"removeAccount('{acc.Id}')\\\">remove</button>\"}}");
|
|
||||||
}
|
|
||||||
sb.Append("]}]");
|
|
||||||
}
|
|
||||||
var tree = @Html.Raw(sb.ToString());
|
|
||||||
return tree;
|
|
||||||
}
|
|
||||||
$('#channelsTree').bstreeview({ data: channelsTree() });
|
|
||||||
$('#usersTree').bstreeview({ data: usersTree() });
|
|
||||||
$('#accountsTree').bstreeview({ data: accountsTree() });
|
|
||||||
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var uacId = components[3];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
}
|
|
@ -19,7 +19,13 @@
|
|||||||
<div id="accountsTree"></div>
|
<div id="accountsTree"></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
<tr>
|
||||||
|
<th scope="row">Permission Tags</th>
|
||||||
|
<td>
|
||||||
|
<div id="tagsTree"></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@section Scripts{
|
@section Scripts{
|
||||||
@ -59,7 +65,26 @@
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTagsTree() {
|
||||||
|
@{
|
||||||
|
sb = new StringBuilder();
|
||||||
|
sb.Append("[{text: \"permission tags\", \"expanded\":true, nodes: [");
|
||||||
|
first = true;
|
||||||
|
for (int i = 0; i < 1; i++)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
sb.Append(',');
|
||||||
|
sb.Append($"{{text: \"<input type=\\\"checkbox\\\" > is goated (w/ sauce)</input>\"}}");
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
sb.Append("]}]");
|
||||||
|
}
|
||||||
|
console.log(@Html.Raw(sb.ToString()));
|
||||||
|
var tree = @Html.Raw(sb.ToString());
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
$('#accountsTree').bstreeview({ data: getAccountsTree() });
|
$('#accountsTree').bstreeview({ data: getAccountsTree() });
|
||||||
|
$('#tagsTree').bstreeview({ data: getTagsTree() });
|
||||||
document.querySelectorAll("input[type=checkbox]").forEach(node => { node.onchange = () => { patchModel(jsonifyUser(), '/api/Users/') } });
|
document.querySelectorAll("input[type=checkbox]").forEach(node => { node.onchange = () => { patchModel(jsonifyUser(), '/api/Users/') } });
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
var apiUrl = '/api/';
|
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||||
|
// for details on configuring this project to bundle and minify static web assets.
|
||||||
|
|
||||||
|
// Write your JavaScript code.
|
||||||
function Account(displayName, accountId, protocol){
|
function Account(displayName, accountId, protocol){
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
@ -8,21 +10,23 @@ function Account(displayName, accountId, protocol){
|
|||||||
//todo: figure out what the URL actually needs to be, rather than assuming you get a whole-ass server to yourself.
|
//todo: figure out what the URL actually needs to be, rather than assuming you get a whole-ass server to yourself.
|
||||||
//you selfish fuck... What are you, fox?
|
//you selfish fuck... What are you, fox?
|
||||||
//as it stands, you want something like /api/Channels/, trailing slash intentional
|
//as it stands, you want something like /api/Channels/, trailing slash intentional
|
||||||
function patchModel(model, deprecated_apiUrl)
|
function patchModel(model, apiUrl)
|
||||||
{
|
{
|
||||||
//structure the model your (dang) self into a nice object
|
//structure the model your (dang) self into a nice object
|
||||||
console.log(model);
|
console.log(model);
|
||||||
|
//i know the page url.
|
||||||
console.log(window.location.pathname);
|
console.log(window.location.pathname);
|
||||||
var components = window.location.pathname.split('/');
|
var components = window.location.pathname.split('/');
|
||||||
// if(components[2] !== "Details")
|
if(components[2] !== "Details")
|
||||||
// {
|
{
|
||||||
// console.log("wtf are you doing? " + components[2] + " is something other than Details");
|
console.log("wtf are you doing? " + components[2] + " is something other than Details");
|
||||||
// }
|
}
|
||||||
var type=components[1];
|
var type=components[1];
|
||||||
// var id=components[3];
|
var id=components[3];
|
||||||
|
|
||||||
|
console.log("dexter impression: I am now ready to post the following content:");
|
||||||
console.log(JSON.stringify(model));
|
console.log(JSON.stringify(model));
|
||||||
fetch(apiUrl + type + '/', {
|
fetch(apiUrl, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -44,17 +48,16 @@ function patchModel(model, deprecated_apiUrl)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteModel(model, deprecated_apiUrl)
|
function deleteModel(model, apiUrl)
|
||||||
{
|
{
|
||||||
var components = window.location.pathname.split('/');
|
var components = window.location.pathname.split('/');
|
||||||
// if(components[2] !== "Details")
|
if(components[2] !== "Details")
|
||||||
// {
|
{
|
||||||
// console.log("wtf are you doing? " + components[2] + " is something other than Details");
|
console.log("wtf are you doing? " + components[2] + " is something other than Details");
|
||||||
// }
|
}
|
||||||
var type=components[1];
|
var type=components[1];
|
||||||
let result = null;
|
var id=components[3];
|
||||||
// var id=components[3];
|
fetch(apiUrl, {
|
||||||
fetch(apiUrl + type + '/', {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -70,179 +73,8 @@ function deleteModel(model, deprecated_apiUrl)
|
|||||||
.then(returnedSuccessdata => {
|
.then(returnedSuccessdata => {
|
||||||
// perhaps a success callback
|
// perhaps a success callback
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
console.log('returnedSuccessdata:', returnedSuccessdata);
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function linkUAC_Channel(channel_guid, callback)
|
|
||||||
{
|
|
||||||
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var id=components[3];
|
|
||||||
let model={"uac_guid": id,
|
|
||||||
"channel_guid": channel_guid};
|
|
||||||
fetch(apiUrl + "UAC/LinkChannel/", {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(model),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not "ok". which is not ok.');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(returnedSuccessdata => {
|
|
||||||
// perhaps a success callback
|
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function linkUAC_User(user_guid, callback)
|
|
||||||
{
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var id=components[3];
|
|
||||||
let model={"uac_guid": id,
|
|
||||||
"user_guid": user_guid};
|
|
||||||
fetch(apiUrl + "UAC/LinkUser/", {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(model),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not "ok". which is not ok.');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(returnedSuccessdata => {
|
|
||||||
// perhaps a success callback
|
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function linkUAC_Account(account_guid, callback)
|
|
||||||
{
|
|
||||||
var reuslt = null;
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var id=components[3];
|
|
||||||
let model={"uac_guid": id,
|
|
||||||
"account_guid": account_guid};
|
|
||||||
fetch(apiUrl + "UAC/LinkAccount/", {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(model),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not "ok". which is not ok.');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(returnedSuccessdata => {
|
|
||||||
// perhaps a success callback
|
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function unlinkUAC_User(user_guid, callback)
|
|
||||||
{
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var id=components[3];
|
|
||||||
let model={"uac_guid": id,
|
|
||||||
"user_guid": user_guid};
|
|
||||||
fetch(apiUrl + "UAC/UnlinkUser/", {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(model),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not "ok". which is not ok.');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(returnedSuccessdata => {
|
|
||||||
// perhaps a success callback
|
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function unlinkUAC_Account(account_guid, callback)
|
|
||||||
{
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var id=components[3];
|
|
||||||
let model={"uac_guid": id,
|
|
||||||
"account_guid": account_guid};
|
|
||||||
fetch(apiUrl + "UAC/UnlinkAccount/", {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(model),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not "ok". which is not ok.');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(returnedSuccessdata => {
|
|
||||||
// perhaps a success callback
|
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function unlinkUAC_Channel(user_guid, callback)
|
|
||||||
{
|
|
||||||
var components = window.location.pathname.split('/');
|
|
||||||
var id=components[3];
|
|
||||||
let model={"uac_guid": id,
|
|
||||||
"channel_guid": user_guid};
|
|
||||||
fetch(apiUrl + "UAC/UnlinkChannel/", {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(model),
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not "ok". which is not ok.');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(returnedSuccessdata => {
|
|
||||||
// perhaps a success callback
|
|
||||||
console.log('returnedSuccessdata:', returnedSuccessdata);
|
|
||||||
if(callback !== null) { callback(); }
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user