Changes to TenantData
This commit is contained in:
parent
fcffb57ac6
commit
c10de11bbe
6 changed files with 196 additions and 145 deletions
|
|
@ -3,20 +3,19 @@ using Npgsql;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
namespace Core.ModuleRegistry
|
namespace Core.ModuleRegistry
|
||||||
{
|
{
|
||||||
public class DbPostgreSqlModule : Module
|
public class DbPostgreSqlModule : Module
|
||||||
{
|
{
|
||||||
public string ConnectionString { get; set; }
|
public required string ConnectionString { get; set; }
|
||||||
protected override void Load(ContainerBuilder builder)
|
protected override void Load(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
|
|
||||||
builder.Register(c =>
|
builder.Register(c =>
|
||||||
{
|
{
|
||||||
IDbConnection connection = new NpgsqlConnection(ConnectionString);
|
IDbConnection connection = new NpgsqlConnection(ConnectionString);
|
||||||
return connection;
|
return connection;
|
||||||
})
|
})
|
||||||
.InstancePerLifetimeScope();
|
.InstancePerLifetimeScope();
|
||||||
|
|
||||||
//builder.RegisterType<IDbConnection>().As<IDbConnection>().InstancePerLifetimeScope();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
namespace Database
|
|
||||||
{
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Database.Tenants
|
|
||||||
{
|
|
||||||
internal class Class1
|
|
||||||
{
|
|
||||||
private async Task InsertInitialData(string schema)
|
|
||||||
{
|
|
||||||
// Indsæt roles
|
|
||||||
var insertRoles = $@"
|
|
||||||
INSERT INTO {schema}.roles (name) VALUES
|
|
||||||
('SYSTEM_ADMIN'),
|
|
||||||
('TENANT_ADMIN'),
|
|
||||||
('POWER_USER'),
|
|
||||||
('BASIC_USER')";
|
|
||||||
await _db.ExecuteAsync(insertRoles);
|
|
||||||
|
|
||||||
// Indsæt permissions
|
|
||||||
var insertPermissions = $@"
|
|
||||||
INSERT INTO {schema}.permissions (name) VALUES
|
|
||||||
('OVERVIEW_VIEW'),
|
|
||||||
('CALENDAR_VIEW'),
|
|
||||||
('SALES_VIEW'),
|
|
||||||
('CUSTOMERS_VIEW'),
|
|
||||||
('POS_VIEW'),
|
|
||||||
('STATISTICS_VIEW')";
|
|
||||||
await _db.ExecuteAsync(insertPermissions);
|
|
||||||
|
|
||||||
// Indsæt role permissions for system admin (får alle permissions)
|
|
||||||
var insertAdminPermissions = $@"
|
|
||||||
INSERT INTO {schema}.role_permissions (role_id, permission_id)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM {schema}.roles WHERE name = 'SYSTEM_ADMIN'),
|
|
||||||
id
|
|
||||||
FROM {schema}.permissions";
|
|
||||||
await _db.ExecuteAsync(insertAdminPermissions);
|
|
||||||
|
|
||||||
// Indsæt navigation templates
|
|
||||||
var insertTemplates = $@"
|
|
||||||
INSERT INTO {schema}.navigation_link_templates
|
|
||||||
(url, permission_id, icon, default_order)
|
|
||||||
VALUES
|
|
||||||
('/overview',
|
|
||||||
(SELECT id FROM {schema}.permissions WHERE name = 'OVERVIEW_VIEW'),
|
|
||||||
'home', 10),
|
|
||||||
('/calendar',
|
|
||||||
(SELECT id FROM {schema}.permissions WHERE name = 'CALENDAR_VIEW'),
|
|
||||||
'calendar', 20),
|
|
||||||
('/sales',
|
|
||||||
(SELECT id FROM {schema}.permissions WHERE name = 'SALES_VIEW'),
|
|
||||||
'shopping-cart', 30),
|
|
||||||
('/customers',
|
|
||||||
(SELECT id FROM {schema}.permissions WHERE name = 'CUSTOMERS_VIEW'),
|
|
||||||
'users', 40),
|
|
||||||
('/pos',
|
|
||||||
(SELECT id FROM {schema}.permissions WHERE name = 'POS_VIEW'),
|
|
||||||
'credit-card', 50),
|
|
||||||
('/statistics',
|
|
||||||
(SELECT id FROM {schema}.permissions WHERE name = 'STATISTICS_VIEW'),
|
|
||||||
'chart-bar', 60)";
|
|
||||||
await _db.ExecuteAsync(insertTemplates);
|
|
||||||
|
|
||||||
// Indsæt translations
|
|
||||||
var insertTranslations = $@"
|
|
||||||
INSERT INTO {schema}.navigation_link_template_translations
|
|
||||||
(template_id, language, display_name)
|
|
||||||
VALUES
|
|
||||||
(1, 'da-DK', 'Overblik'),
|
|
||||||
(1, 'en-US', 'Overview'),
|
|
||||||
(2, 'da-DK', 'Kalender'),
|
|
||||||
(2, 'en-US', 'Calendar'),
|
|
||||||
(3, 'da-DK', 'Salg'),
|
|
||||||
(3, 'en-US', 'Sales'),
|
|
||||||
(4, 'da-DK', 'Kunder'),
|
|
||||||
(4, 'en-US', 'Customers'),
|
|
||||||
(5, 'da-DK', 'Kassesystem'),
|
|
||||||
(5, 'en-US', 'POS System'),
|
|
||||||
(6, 'da-DK', 'Statistik'),
|
|
||||||
(6, 'en-US', 'Statistics')";
|
|
||||||
await _db.ExecuteAsync(insertTranslations);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
138
Database/Tenants/TenantData.cs
Normal file
138
Database/Tenants/TenantData.cs
Normal file
|
|
@ -0,0 +1,138 @@
|
||||||
|
using Insight.Database;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace Database.Tenants
|
||||||
|
{
|
||||||
|
internal class TenantData
|
||||||
|
{
|
||||||
|
private readonly IDbConnection _db;
|
||||||
|
|
||||||
|
public TenantData(IDbConnection db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task InsertInitialData(string schema)
|
||||||
|
{
|
||||||
|
// Permission types
|
||||||
|
var insertPermissionTypes = $@"
|
||||||
|
INSERT INTO {schema}.permission_types (name) VALUES
|
||||||
|
('NAVIGATION'),
|
||||||
|
('COMMAND'),
|
||||||
|
('VIEW'),
|
||||||
|
('FEATURE')";
|
||||||
|
await _db.ExecuteAsync(insertPermissionTypes);
|
||||||
|
|
||||||
|
// Permissions
|
||||||
|
var insertPermissions = $@"
|
||||||
|
INSERT INTO {schema}.permissions (name, type_id) VALUES
|
||||||
|
-- Navigation permissions
|
||||||
|
('OVERVIEW_VIEW', (SELECT id FROM {schema}.permission_types WHERE name = 'NAVIGATION')),
|
||||||
|
('CALENDAR_VIEW', (SELECT id FROM {schema}.permission_types WHERE name = 'NAVIGATION')),
|
||||||
|
('SALES_VIEW', (SELECT id FROM {schema}.permission_types WHERE name = 'NAVIGATION')),
|
||||||
|
('CUSTOMERS_VIEW', (SELECT id FROM {schema}.permission_types WHERE name = 'NAVIGATION')),
|
||||||
|
|
||||||
|
-- Command permissions
|
||||||
|
('CREATE_PRODUCT', (SELECT id FROM {schema}.permission_types WHERE name = 'COMMAND')),
|
||||||
|
('EDIT_PRODUCT', (SELECT id FROM {schema}.permission_types WHERE name = 'COMMAND')),
|
||||||
|
('DELETE_PRODUCT', (SELECT id FROM {schema}.permission_types WHERE name = 'COMMAND')),
|
||||||
|
('CREATE_CUSTOMER', (SELECT id FROM {schema}.permission_types WHERE name = 'COMMAND')),
|
||||||
|
('EDIT_CUSTOMER', (SELECT id FROM {schema}.permission_types WHERE name = 'COMMAND')),
|
||||||
|
|
||||||
|
-- View permissions
|
||||||
|
('PRODUCT_DETAILS', (SELECT id FROM {schema}.permission_types WHERE name = 'VIEW')),
|
||||||
|
('CUSTOMER_DETAILS', (SELECT id FROM {schema}.permission_types WHERE name = 'VIEW')),
|
||||||
|
('SALES_STATISTICS', (SELECT id FROM {schema}.permission_types WHERE name = 'VIEW')),
|
||||||
|
|
||||||
|
-- Feature permissions
|
||||||
|
('ADVANCED_SEARCH', (SELECT id FROM {schema}.permission_types WHERE name = 'FEATURE')),
|
||||||
|
('EXPORT_DATA', (SELECT id FROM {schema}.permission_types WHERE name = 'FEATURE')),
|
||||||
|
('BULK_OPERATIONS', (SELECT id FROM {schema}.permission_types WHERE name = 'FEATURE'))";
|
||||||
|
await _db.ExecuteAsync(insertPermissions);
|
||||||
|
|
||||||
|
// Roles
|
||||||
|
var insertRoles = $@"
|
||||||
|
INSERT INTO {schema}.roles (name) VALUES
|
||||||
|
('SYSTEM_ADMIN'),
|
||||||
|
('TENANT_ADMIN'),
|
||||||
|
('POWER_USER'),
|
||||||
|
('BASIC_USER')";
|
||||||
|
await _db.ExecuteAsync(insertRoles);
|
||||||
|
|
||||||
|
// Top-level navigation
|
||||||
|
var insertTopNav = $@"
|
||||||
|
INSERT INTO {schema}.navigation_link_templates
|
||||||
|
(parent_id, url, permission_id, icon, default_order)
|
||||||
|
VALUES
|
||||||
|
(NULL, '/overview',
|
||||||
|
(SELECT id FROM {schema}.permissions WHERE name = 'OVERVIEW_VIEW'),
|
||||||
|
'home', 10),
|
||||||
|
(NULL, '/sales',
|
||||||
|
(SELECT id FROM {schema}.permissions WHERE name = 'SALES_VIEW'),
|
||||||
|
'shopping-cart', 20),
|
||||||
|
(NULL, '/customers',
|
||||||
|
(SELECT id FROM {schema}.permissions WHERE name = 'CUSTOMERS_VIEW'),
|
||||||
|
'users', 30)";
|
||||||
|
await _db.ExecuteAsync(insertTopNav);
|
||||||
|
|
||||||
|
// Sub-navigation
|
||||||
|
var insertSubNav = $@"
|
||||||
|
INSERT INTO {schema}.navigation_link_templates
|
||||||
|
(parent_id, url, permission_id, icon, default_order)
|
||||||
|
VALUES
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/sales'),
|
||||||
|
'/sales/create',
|
||||||
|
(SELECT id FROM {schema}.permissions WHERE name = 'CREATE_PRODUCT'),
|
||||||
|
'plus', 1),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/customers'),
|
||||||
|
'/customers/create',
|
||||||
|
(SELECT id FROM {schema}.permissions WHERE name = 'CREATE_CUSTOMER'),
|
||||||
|
'user-plus', 1)";
|
||||||
|
await _db.ExecuteAsync(insertSubNav);
|
||||||
|
|
||||||
|
// Translations for top-level
|
||||||
|
var insertTopTranslations = $@"
|
||||||
|
INSERT INTO {schema}.navigation_link_template_translations
|
||||||
|
(template_id, language, display_name)
|
||||||
|
VALUES
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/overview'),
|
||||||
|
'da-DK', 'Overblik'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/overview'),
|
||||||
|
'en-US', 'Overview'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/sales'),
|
||||||
|
'da-DK', 'Salg'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/sales'),
|
||||||
|
'en-US', 'Sales'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/customers'),
|
||||||
|
'da-DK', 'Kunder'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/customers'),
|
||||||
|
'en-US', 'Customers')";
|
||||||
|
await _db.ExecuteAsync(insertTopTranslations);
|
||||||
|
|
||||||
|
// Translations for sub-navigation
|
||||||
|
var insertSubTranslations = $@"
|
||||||
|
INSERT INTO {schema}.navigation_link_template_translations
|
||||||
|
(template_id, language, display_name)
|
||||||
|
VALUES
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/sales/create'),
|
||||||
|
'da-DK', 'Opret salg'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/sales/create'),
|
||||||
|
'en-US', 'Create sale'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/customers/create'),
|
||||||
|
'da-DK', 'Opret kunde'),
|
||||||
|
((SELECT id FROM {schema}.navigation_link_templates WHERE url = '/customers/create'),
|
||||||
|
'en-US', 'Create customer')";
|
||||||
|
await _db.ExecuteAsync(insertSubTranslations);
|
||||||
|
|
||||||
|
// Giv admin alle permissions
|
||||||
|
var insertAdminPermissions = $@"
|
||||||
|
INSERT INTO {schema}.role_permissions (role_id, permission_id)
|
||||||
|
SELECT
|
||||||
|
(SELECT id FROM {schema}.roles WHERE name = 'SYSTEM_ADMIN'),
|
||||||
|
id
|
||||||
|
FROM {schema}.permissions";
|
||||||
|
await _db.ExecuteAsync(insertAdminPermissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -60,65 +60,77 @@ namespace Database.Tenants
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private async Task CreatePermissionTypesTable(string schema)
|
||||||
|
|
||||||
private async Task CreateRolesTable(string schema)
|
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
CREATE TABLE IF NOT EXISTS {schema}.roles (
|
CREATE TABLE IF NOT EXISTS {schema}.permission_types (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
name VARCHAR(100) NOT NULL UNIQUE
|
name VARCHAR(100) NOT NULL UNIQUE
|
||||||
)";
|
)";
|
||||||
await _db.ExecuteAsync(sql);
|
await _db.ExecuteAsync(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreatePermissionsTable(string schema)
|
private async Task CreatePermissionsTable(string schema)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
CREATE TABLE IF NOT EXISTS {schema}.permissions (
|
CREATE TABLE IF NOT EXISTS {schema}.permissions (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
name VARCHAR(100) NOT NULL UNIQUE
|
name VARCHAR(100) NOT NULL UNIQUE,
|
||||||
)";
|
type_id INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (type_id) REFERENCES {schema}.permission_types(id)
|
||||||
|
)";
|
||||||
|
await _db.ExecuteAsync(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CreateRolesTable(string schema)
|
||||||
|
{
|
||||||
|
var sql = $@"
|
||||||
|
CREATE TABLE IF NOT EXISTS {schema}.roles (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(100) NOT NULL UNIQUE
|
||||||
|
)";
|
||||||
await _db.ExecuteAsync(sql);
|
await _db.ExecuteAsync(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreateRolePermissionsTable(string schema)
|
private async Task CreateRolePermissionsTable(string schema)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
CREATE TABLE IF NOT EXISTS {schema}.role_permissions (
|
CREATE TABLE IF NOT EXISTS {schema}.role_permissions (
|
||||||
role_id INTEGER NOT NULL,
|
role_id INTEGER NOT NULL,
|
||||||
permission_id INTEGER NOT NULL,
|
permission_id INTEGER NOT NULL,
|
||||||
PRIMARY KEY (role_id, permission_id),
|
PRIMARY KEY (role_id, permission_id),
|
||||||
FOREIGN KEY (role_id) REFERENCES {schema}.roles(id),
|
FOREIGN KEY (role_id) REFERENCES {schema}.roles(id),
|
||||||
FOREIGN KEY (permission_id) REFERENCES {schema}.permissions(id)
|
FOREIGN KEY (permission_id) REFERENCES {schema}.permissions(id)
|
||||||
)";
|
)";
|
||||||
await _db.ExecuteAsync(sql);
|
await _db.ExecuteAsync(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreateNavigationLinkTemplatesTable(string schema)
|
private async Task CreateNavigationLinkTemplatesTable(string schema)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
CREATE TABLE IF NOT EXISTS {schema}.navigation_link_templates (
|
CREATE TABLE IF NOT EXISTS {schema}.navigation_link_templates (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
url VARCHAR(500) NOT NULL,
|
parent_id INTEGER NULL,
|
||||||
permission_id INTEGER NULL,
|
url VARCHAR(500) NOT NULL,
|
||||||
icon VARCHAR(100) NULL,
|
permission_id INTEGER NULL,
|
||||||
default_order INTEGER NOT NULL,
|
icon VARCHAR(100) NULL,
|
||||||
FOREIGN KEY (permission_id) REFERENCES {schema}.permissions(id)
|
default_order INTEGER NOT NULL,
|
||||||
)";
|
FOREIGN KEY (permission_id) REFERENCES {schema}.permissions(id),
|
||||||
|
FOREIGN KEY (parent_id) REFERENCES {schema}.navigation_link_templates(id)
|
||||||
|
)";
|
||||||
await _db.ExecuteAsync(sql);
|
await _db.ExecuteAsync(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreateNavigationLinkTemplateTranslationsTable(string schema)
|
private async Task CreateNavigationLinkTemplateTranslationsTable(string schema)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
CREATE TABLE IF NOT EXISTS {schema}.navigation_link_template_translations (
|
CREATE TABLE IF NOT EXISTS {schema}.navigation_link_template_translations (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
template_id INTEGER NOT NULL,
|
template_id INTEGER NOT NULL,
|
||||||
language VARCHAR(10) NOT NULL,
|
language VARCHAR(10) NOT NULL,
|
||||||
display_name VARCHAR(100) NOT NULL,
|
display_name VARCHAR(100) NOT NULL,
|
||||||
FOREIGN KEY (template_id) REFERENCES {schema}.navigation_link_templates(id)
|
FOREIGN KEY (template_id) REFERENCES {schema}.navigation_link_templates(id)
|
||||||
)";
|
)";
|
||||||
await _db.ExecuteAsync(sql);
|
await _db.ExecuteAsync(sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"ptdb": "Host=localhost;Port=5433;Database=ptdb01;User Id=postgres;Password=3911;"
|
"ptdb": "Host=localhost;Port=5433;Database=ptdb01;User Id=postgres;Password=3911;"
|
||||||
},
|
},
|
||||||
"SendInBlue": {
|
|
||||||
"APIkey": "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"
|
|
||||||
},
|
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue