diff --git a/DepartmentPortal/Common/ModuleTools/Attributes/MapConfigurationAttribute.cs b/DepartmentPortal/Common/ModuleTools/Attributes/MapConfigurationAttribute.cs
index 79e24f4..358439b 100644
--- a/DepartmentPortal/Common/ModuleTools/Attributes/MapConfigurationAttribute.cs
+++ b/DepartmentPortal/Common/ModuleTools/Attributes/MapConfigurationAttribute.cs
@@ -21,15 +21,22 @@ namespace ModuleTools.Attributes
///
public bool IsDifficle { get; set; }
+ ///
+ /// Можно копировать поле даже при доступе без прав
+ ///
+ public bool AllowCopyWithoutRigth { get; set; }
+
///
/// Настройка для полей сущности правил маппинга
///
/// Название свойства с класса, из которого извлекаем данные
/// Сложное свойство (свойствое в другом классе-свойстве)
- public MapConfigurationAttribute(string propertyNameFromMModel, bool isDifficle = false)
+ /// Можно копировать поле даже при доступе без прав
+ public MapConfigurationAttribute(string propertyNameFromMModel, bool isDifficle = false, bool allowCopyWithoutRigth = true)
{
PropertyNameFromModel = propertyNameFromMModel;
IsDifficle = isDifficle;
+ AllowCopyWithoutRigth = allowCopyWithoutRigth;
}
}
}
\ No newline at end of file
diff --git a/DepartmentPortal/Common/ModuleTools/BindingModels/GetBindingModel.cs b/DepartmentPortal/Common/ModuleTools/BindingModels/GetBindingModel.cs
index 0efb260..5f872de 100644
--- a/DepartmentPortal/Common/ModuleTools/BindingModels/GetBindingModel.cs
+++ b/DepartmentPortal/Common/ModuleTools/BindingModels/GetBindingModel.cs
@@ -7,6 +7,11 @@ namespace ModuleTools.BindingModels
///
public class GetBindingModel : AccessBindingModel
{
+ ///
+ /// Наличие прав на операцию
+ ///
+ public bool HaveRight { get; set; }
+
///
/// Идентификатор получаемой записи (для одной записи)
///
diff --git a/DepartmentPortal/Common/ModuleTools/BusinessLogics/BusinessLogicCore.cs b/DepartmentPortal/Common/ModuleTools/BusinessLogics/BusinessLogicCore.cs
index 5efde9d..f15accc 100644
--- a/DepartmentPortal/Common/ModuleTools/BusinessLogics/BusinessLogicCore.cs
+++ b/DepartmentPortal/Common/ModuleTools/BusinessLogics/BusinessLogicCore.cs
@@ -87,8 +87,8 @@ namespace ModuleTools.BusinessLogics
Errors.Clear();
try
{
- var fullView = NoAccess(model, AccessType.View);
- if (fullView && !_allowSimpleView)
+ model.HaveRight = NoAccess(model, AccessType.View);
+ if (model.HaveRight && !_allowSimpleView)
{
throw new MethodAccessException("Нет прав на получение списка");
}
@@ -118,8 +118,8 @@ namespace ModuleTools.BusinessLogics
Errors.Clear();
try
{
- var fullView = NoAccess(model, AccessType.View);
- if (fullView && !_allowSimpleView)
+ model.HaveRight = NoAccess(model, AccessType.View);
+ if (model.HaveRight && !_allowSimpleView)
{
throw new MethodAccessException("Нет прав на получение списка");
}
diff --git a/DepartmentPortal/Common/ModuleTools/BusinessLogics/Mapper.cs b/DepartmentPortal/Common/ModuleTools/BusinessLogics/Mapper.cs
index c56e4ce..46b7151 100644
--- a/DepartmentPortal/Common/ModuleTools/BusinessLogics/Mapper.cs
+++ b/DepartmentPortal/Common/ModuleTools/BusinessLogics/Mapper.cs
@@ -15,8 +15,9 @@ namespace ModuleTools.BusinessLogics
///
///
///
+ ///
///
- public static To MapToClass(From obj) where To : class => FillObject(obj, (To)Activator.CreateInstance(typeof(To)));
+ public static To MapToClass(From obj, bool haveRigth) where To : class => FillObject(obj, (To)Activator.CreateInstance(typeof(To)), haveRigth);
///
/// Преобразование из одного класса в другой
@@ -26,7 +27,7 @@ namespace ModuleTools.BusinessLogics
///
///
///
- public static To MapToClass(From obj, To newObject) where To : class => FillObject(obj, newObject);
+ public static To MapToClass(From obj, To newObject, bool haveRigth) where To : class => FillObject(obj, newObject, haveRigth);
///
/// Заполнение объекта
@@ -35,8 +36,9 @@ namespace ModuleTools.BusinessLogics
///
///
///
+ ///
///
- private static To FillObject(From obj, To newObject)
+ private static To FillObject(From obj, To newObject, bool haveRigth)
where To : class
{
if (obj == null)
@@ -90,7 +92,10 @@ namespace ModuleTools.BusinessLogics
{
continue;
}
- property.SetValue(newObject, value);
+ if ((haveRigth && !customAttribute.AllowCopyWithoutRigth) || customAttribute.AllowCopyWithoutRigth)
+ {
+ property.SetValue(newObject, value);
+ }
}
}
diff --git a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/AccessService.cs b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/AccessService.cs
index d01a769..818eaa8 100644
--- a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/AccessService.cs
+++ b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/AccessService.cs
@@ -25,10 +25,10 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var exsistEntity = context.Accesses.FirstOrDefault(x => x.AccessOperation == model.Operation && x.RoleId == model.RoleId && x.AccessType == model.AccessType);
if (exsistEntity == null)
{
- var entity = Mapper.MapToClass(model);
+ var entity = Mapper.MapToClass(model, true);
context.Accesses.Add(entity);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
else
{
@@ -36,7 +36,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
exsistEntity.IsDeleted = false;
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(exsistEntity));
+ return OperationResultModel.Success(Mapper.MapToClass(exsistEntity, true));
}
else
{
@@ -79,7 +79,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound);
}
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight));
}
var query = context.Accesses.Where(x => !x.IsDeleted).AsQueryable();
@@ -107,7 +107,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var result = new AccessListViewModel
{
MaxCount = countPages,
- List = query.Select(Mapper.MapToClass).ToList()
+ List = query.Select(x => Mapper.MapToClass(x, model.HaveRight)).ToList()
};
return OperationResultModel.Success(result);
@@ -126,11 +126,11 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент был удален", ResultServiceStatusCode.WasDelete);
}
- entity = Mapper.MapToClass(model, entity);
+ entity = Mapper.MapToClass(model, entity, true);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
}
}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/EnviromentSettingService.cs b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/EnviromentSettingService.cs
index 4432730..440fea4 100644
--- a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/EnviromentSettingService.cs
+++ b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/EnviromentSettingService.cs
@@ -24,10 +24,10 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var exsistEntity = context.EnviromentSettings.FirstOrDefault(x => x.Key == model.Key);
if (exsistEntity == null)
{
- var entity = Mapper.MapToClass(model);
+ var entity = Mapper.MapToClass(model, true);
context.EnviromentSettings.Add(entity);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
return OperationResultModel.Error("Error:", "Элемент уже существует", ResultServiceStatusCode.ExsistItem);
}
@@ -61,7 +61,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound);
}
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight));
}
if (model.Key.IsNotEmpty())
@@ -71,7 +71,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound);
}
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight));
}
var query = context.EnviromentSettings.AsQueryable();
@@ -89,7 +89,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var result = new EnviromentSettingListViewModel
{
MaxCount = countPages,
- List = query.Select(Mapper.MapToClass).ToList()
+ List = query.Select(x => Mapper.MapToClass(x, model.HaveRight)).ToList()
};
return OperationResultModel.Success(result);
@@ -104,11 +104,11 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound);
}
- entity = Mapper.MapToClass(model, entity);
+ entity = Mapper.MapToClass(model, entity, true);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
}
}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/RoleService.cs b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/RoleService.cs
index 3f015de..51cb434 100644
--- a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/RoleService.cs
+++ b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/RoleService.cs
@@ -23,10 +23,10 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var exsistEntity = context.Roles.FirstOrDefault(x => x.RoleName == model.RoleName);
if (exsistEntity == null)
{
- var entity = Mapper.MapToClass(model);
+ var entity = Mapper.MapToClass(model, true);
context.Roles.Add(entity);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
else
{
@@ -34,7 +34,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
exsistEntity.IsDeleted = false;
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(exsistEntity));
+ return OperationResultModel.Success(Mapper.MapToClass(exsistEntity, true));
}
else
{
@@ -103,7 +103,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound);
}
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight));
}
var query = context.Roles.Where(x => !x.IsDeleted).AsQueryable();
@@ -121,7 +121,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var result = new RoleListViewModel
{
MaxCount = countPages,
- List = query.Select(Mapper.MapToClass).ToList()
+ List = query.Select(x => Mapper.MapToClass(x, model.HaveRight)).ToList()
};
return OperationResultModel.Success(result);
@@ -140,11 +140,11 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент был удален", ResultServiceStatusCode.WasDelete);
}
- entity = Mapper.MapToClass(model, entity);
+ entity = Mapper.MapToClass(model, entity, true);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
}
}
\ No newline at end of file
diff --git a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/UserService.cs b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/UserService.cs
index 6921e0c..d036aef 100644
--- a/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/UserService.cs
+++ b/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/UserService.cs
@@ -23,10 +23,10 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var exsistEntity = context.Users.FirstOrDefault(x => x.UserName == model.Login);
if (exsistEntity == null)
{
- var entity = Mapper.MapToClass(model);
+ var entity = Mapper.MapToClass(model, true);
context.Users.Add(entity);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
else
{
@@ -34,7 +34,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
exsistEntity.IsDeleted = false;
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(exsistEntity));
+ return OperationResultModel.Success(Mapper.MapToClass(exsistEntity, true));
}
else
{
@@ -95,7 +95,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент не найден", ResultServiceStatusCode.NotFound);
}
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, model.HaveRight));
}
var query = context.Users.Where(x => !x.IsDeleted).AsQueryable();
@@ -113,7 +113,7 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
var result = new UserListViewModel
{
MaxCount = countPages,
- List = query.Select(Mapper.MapToClass).ToList()
+ List = query.Select(x => Mapper.MapToClass(x, model.HaveRight)).ToList()
};
return OperationResultModel.Success(result);
@@ -132,11 +132,11 @@ namespace SecurityImplementation.SecurityDatabaseImplementation
{
return OperationResultModel.Error("Error:", "Элемент был удален", ResultServiceStatusCode.WasDelete);
}
- entity = Mapper.MapToClass(model, entity);
+ entity = Mapper.MapToClass(model, entity, true);
context.SaveChanges();
- return OperationResultModel.Success(Mapper.MapToClass(entity));
+ return OperationResultModel.Success(Mapper.MapToClass(entity, true));
}
}
}
\ No newline at end of file