1. проверка целосности данных для админа

2. смена типов доступа
3. вывод текстом типа доступа
This commit is contained in:
kotcheshir73 2021-03-28 00:15:01 +04:00
parent 3893ebdb19
commit 1e1896c68d
14 changed files with 94 additions and 14 deletions

View File

@ -3,7 +3,10 @@ using ModelTools.Enums;
using ModelTools.Interfaces;
using ModelTools.Models;
using SecurityBusinessLogic.BusinessLogics;
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace DatabaseCore
{
@ -60,5 +63,63 @@ namespace DatabaseCore
return false;
}
}
public void CheckStartDataSource()
{
using var context = DatabaseManager.GetContext;
using var transaction = context.Database.BeginTransaction();
var role = context.Roles.FirstOrDefault(x => x.RoleName == "Администратор");
if (role == null)
{
role = new Role
{
RoleName = "Администратор",
RolePriority = 100
};
context.Roles.Add(role);
context.SaveChanges();
}
var accesses = context.Accesses.Where(x => x.RoleId == role.Id);
foreach (AccessOperation operation in Enum.GetValues(typeof(AccessOperation)))
{
if (!accesses.Any(x => x.AccessOperation == operation && x.AccessType == AccessType.Delete))
{
context.Accesses.Add(new Access
{
AccessOperation = operation,
AccessType = AccessType.Delete,
RoleId = role.Id
});
}
}
context.SaveChanges();
var md5 = new MD5CryptoServiceProvider();
var user = context.Users.FirstOrDefault(x => x.UserName == "admin");
if (user == null)
{
user = new User
{
UserName = "admin",
PasswordHash = Encoding.ASCII.GetString(md5.ComputeHash(Encoding.ASCII.GetBytes("qwerty"))),
CountAttempt = 0
};
context.Users.Add(user);
context.SaveChanges();
}
var link = context.UserRoles.FirstOrDefault(x => x.RoleId == role.Id && x.UserId == user.Id);
if (link == null)
{
context.UserRoles.Add(new UserRole
{
RoleId = role.Id,
UserId = user.Id
});
context.SaveChanges();
}
transaction.Commit();
}
}
}

View File

@ -8,27 +8,21 @@
/// <summary>
/// Простой просомтр
/// </summary>
SimpleView = 0,
SimpleView = 1,
/// <summary>
/// Полный просомтр
/// </summary>
FullView = 1,
FullView = 2,
/// <summary>
/// Добавление/Изменение
/// </summary>
Change = 2,
Change = 4,
/// <summary>
/// Удаление
/// </summary>
Delete = 4,
// TODO убрать
/// <summary>
/// Доступ к меню
/// </summary>
Menu = 8
Delete = 8
}
}

View File

@ -15,5 +15,10 @@ namespace ModelTools.Interfaces
/// <param name="model">Данные по операции</param>
/// <returns></returns>
bool CheckAccess(SecurityManagerCheckAccessModel model);
/// <summary>
/// Проверка наличия старотвых данных для работы с ситемой
/// </summary>
void CheckStartDataSource();
}
}

View File

@ -1,5 +1,4 @@
using DatabaseCore;
using DesktopTools.Controls;
using ModelTools.BusinessLogics;
using ModelTools.Interfaces;
using SecurityBusinessLogic.BusinessLogics;
@ -19,6 +18,9 @@ namespace DepartmentPortalDesctop
UnityContainerConfigurator.PublishService<ISecurityManager, SecurityManager>();
UnityContainerConfigurator.InitServices();
var securityManager = UnityContainerConfigurator.Resolve<ISecurityManager>();
securityManager.CheckStartDataSource();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

View File

@ -32,7 +32,25 @@ namespace SecurityBusinessLogic.ViewModels
public AccessType AccessType { get; set; }
[ViewModelOnListProperty("Тип", 150)]
public string AccessTypeTitle => AccessType.ToString("G");
public string AccessTypeTitle
{
get
{
switch (AccessType)
{
case AccessType.Delete:
return "Полные права";
case AccessType.Change:
return "Просмотр, Редактирование";
case AccessType.FullView:
return "Просмотр";
case AccessType.SimpleView:
return "Частичный просмотр";
default:
return "Неопределено";
}
}
}
public override string ToString() => $"{RoleName}-{AccessOperationTitle}({AccessTypeTitle})";
}

View File

@ -17,9 +17,9 @@ namespace SecurityBusinessLogic.ViewModels
[MapConfiguration("Key")]
public string Key { get; set; }
[ViewModelOnListProperty("Значение", 100)]
[ViewModelOnListProperty("Значение")]
[MapConfiguration("Value")]
public int Value { get; set; }
public string Value { get; set; }
public override string ToString() => Key;
}