forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/notifications
This commit is contained in:
commit
4ae769adcc
@ -62,8 +62,11 @@ namespace AsbCloudApp.Data.User
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Id состояния пользователя
|
/// Id состояния пользователя
|
||||||
|
/// 0 - не активен,
|
||||||
|
/// 1 - активен,
|
||||||
|
/// 2 - заблокирован
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public short? IdState { get; set; }
|
public short IdState { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DTO компании
|
/// DTO компании
|
||||||
|
@ -22,9 +22,10 @@ namespace AsbCloudApp.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение типов контаков
|
/// Получение типов контаков
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="idWell">ключ скважины</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(CancellationToken token);
|
Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(int idWell, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновление контактов по ключу скважины, типу контакта и ключам пользователей
|
/// Обновление контактов по ключу скважины, типу контакта и ключам пользователей
|
||||||
|
8226
AsbCloudDb/Migrations/20230711130529_Update_IdState_For_User.Designer.cs
generated
Normal file
8226
AsbCloudDb/Migrations/20230711130529_Update_IdState_For_User.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class Update_IdState_For_User : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user",
|
||||||
|
keyColumn: "state",
|
||||||
|
keyValue: null,
|
||||||
|
column: "state",
|
||||||
|
value: (short)1);
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<short>(
|
||||||
|
name: "state",
|
||||||
|
table: "t_user",
|
||||||
|
type: "smallint",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: (short)0,
|
||||||
|
comment: "состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован",
|
||||||
|
oldClrType: typeof(short),
|
||||||
|
oldType: "smallint",
|
||||||
|
oldNullable: true,
|
||||||
|
oldComment: "состояние:\n100 - удален");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id_category",
|
||||||
|
table: "t_help_page",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
comment: "Id категории файла",
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldComment: "id категории файла");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<short>(
|
||||||
|
name: "state",
|
||||||
|
table: "t_user",
|
||||||
|
type: "smallint",
|
||||||
|
nullable: true,
|
||||||
|
comment: "состояние:\n100 - удален",
|
||||||
|
oldClrType: typeof(short),
|
||||||
|
oldType: "smallint",
|
||||||
|
oldComment: "состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "id_category",
|
||||||
|
table: "t_help_page",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
comment: "id категории файла",
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldComment: "Id категории файла");
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_user",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 1,
|
||||||
|
column: "state",
|
||||||
|
value: null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8232
AsbCloudDb/Migrations/20230713050032_Add_Order_For_CompanyType.Designer.cs
generated
Normal file
8232
AsbCloudDb/Migrations/20230713050032_Add_Order_For_CompanyType.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class Add_Order_For_CompanyType : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "order",
|
||||||
|
table: "t_company_type",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_company_type",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 1,
|
||||||
|
column: "order",
|
||||||
|
value: 1);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_company_type",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 2,
|
||||||
|
column: "order",
|
||||||
|
value: 2);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "t_company_type",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 5,
|
||||||
|
column: "order",
|
||||||
|
value: 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "order",
|
||||||
|
table: "t_company_type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -122,6 +122,10 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Property<bool>("IsContact")
|
b.Property<bool>("IsContact")
|
||||||
.HasColumnType("boolean");
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<int>("Order")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("order");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("t_company_type");
|
b.ToTable("t_company_type");
|
||||||
@ -131,19 +135,22 @@ namespace AsbCloudDb.Migrations
|
|||||||
{
|
{
|
||||||
Id = 1,
|
Id = 1,
|
||||||
Caption = "Недрапользователь",
|
Caption = "Недрапользователь",
|
||||||
IsContact = false
|
IsContact = false,
|
||||||
|
Order = 1
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
Caption = "Буровой подрядчик",
|
Caption = "Буровой подрядчик",
|
||||||
IsContact = false
|
IsContact = false,
|
||||||
|
Order = 2
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = 3,
|
Id = 3,
|
||||||
Caption = "Сервис автоматизации бурения",
|
Caption = "Сервис автоматизации бурения",
|
||||||
IsContact = false
|
IsContact = false,
|
||||||
|
Order = 0
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -4846,10 +4853,10 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_company");
|
.HasColumnName("id_company");
|
||||||
|
|
||||||
b.Property<short?>("IdState")
|
b.Property<short>("IdState")
|
||||||
.HasColumnType("smallint")
|
.HasColumnType("smallint")
|
||||||
.HasColumnName("state")
|
.HasColumnName("state")
|
||||||
.HasComment("состояние:\n100 - удален");
|
.HasComment("состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован");
|
||||||
|
|
||||||
b.Property<string>("Login")
|
b.Property<string>("Login")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
@ -4911,6 +4918,7 @@ namespace AsbCloudDb.Migrations
|
|||||||
Id = 1,
|
Id = 1,
|
||||||
Email = "",
|
Email = "",
|
||||||
IdCompany = 1,
|
IdCompany = 1,
|
||||||
|
IdState = (short)1,
|
||||||
Login = "dev",
|
Login = "dev",
|
||||||
Name = "Разработчик",
|
Name = "Разработчик",
|
||||||
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072"
|
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072"
|
||||||
|
@ -16,6 +16,9 @@ namespace AsbCloudDb.Model
|
|||||||
public string Caption { get; set; } = null!;
|
public string Caption { get; set; } = null!;
|
||||||
public bool IsContact { get; set; }
|
public bool IsContact { get; set; }
|
||||||
|
|
||||||
|
[Column("order")]
|
||||||
|
public int Order { get; set; }
|
||||||
|
|
||||||
[InverseProperty(nameof(Company.CompanyType))]
|
[InverseProperty(nameof(Company.CompanyType))]
|
||||||
public virtual ICollection<Company> Companies { get; set; } = null!;
|
public virtual ICollection<Company> Companies { get; set; } = null!;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
internal class EntityFillerCompanyType : EntityFiller<CompanyType>
|
internal class EntityFillerCompanyType : EntityFiller<CompanyType>
|
||||||
{
|
{
|
||||||
public override CompanyType[] GetData() => new CompanyType[] {
|
public override CompanyType[] GetData() => new CompanyType[] {
|
||||||
new (){ Id = 1, Caption = "Недрапользователь", },
|
new (){ Id = 1, Caption = "Недрапользователь", Order = 1 },
|
||||||
new (){ Id = 2, Caption = "Буровой подрядчик", },
|
new (){ Id = 2, Caption = "Буровой подрядчик", Order = 2 },
|
||||||
new (){ Id = 3, Caption = "Сервис автоматизации бурения", },
|
new (){ Id = 3, Caption = "Сервис автоматизации бурения", Order = 0 }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
Login = "dev",
|
Login = "dev",
|
||||||
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072",
|
PasswordHash = "Vlcj|4fa529103dde7ff72cfe76185f344d4aa87931f8e1b2044e8a7739947c3d18923464eaad93843e4f809c5e126d013072",
|
||||||
Name = "Разработчик",
|
Name = "Разработчик",
|
||||||
|
IdState = 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ namespace AsbCloudDb.Model
|
|||||||
[Table("t_user"), Comment("Пользователи облака")]
|
[Table("t_user"), Comment("Пользователи облака")]
|
||||||
public partial class User : IId
|
public partial class User : IId
|
||||||
{
|
{
|
||||||
|
public const int ActiveStateId = 1;
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -23,8 +25,8 @@ namespace AsbCloudDb.Model
|
|||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
public string PasswordHash { get; set; } = null!;
|
public string PasswordHash { get; set; } = null!;
|
||||||
|
|
||||||
[Column("state"), Comment("состояние:\n100 - удален")]
|
[Column("state"), Comment("состояние:\n0 - не активен, \n1 - активен, \n2 - заблокирован")]
|
||||||
public short? IdState { get; set; }
|
public short IdState { get; set; }
|
||||||
|
|
||||||
[Column("name"), Comment("имя")]
|
[Column("name"), Comment("имя")]
|
||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
|
@ -50,9 +50,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(CancellationToken token)
|
public async Task<IEnumerable<CompanyTypeDto>> GetTypesAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = db.CompaniesTypes.Where(t => t.IsContact);
|
var query = db.CompaniesTypes
|
||||||
|
.Where(t => t.IsContact)
|
||||||
|
.Where(t => t.Companies.Any(c => c.Users.Any() && c.RelationCompaniesWells.Any(w => w.IdWell == idWell)))
|
||||||
|
.OrderBy(t => t.Order);
|
||||||
|
|
||||||
var entities = await query.AsNoTracking()
|
var entities = await query.AsNoTracking()
|
||||||
.ToArrayAsync(token)
|
.ToArrayAsync(token)
|
||||||
|
@ -29,13 +29,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// получение списка типов контактов
|
/// получение списка типов контактов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="idWell">ключ скважины</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("api/contacts/types")]
|
[HttpGet("api/well/{idWell}/contacts/types")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<CompanyTypeDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<CompanyTypeDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetTypesAsync(CancellationToken token)
|
public async Task<IActionResult> GetTypesAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await wellContactsRepository.GetTypesAsync(token).ConfigureAwait(false);
|
var result = await wellContactsRepository.GetTypesAsync(idWell, token).ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
using AsbCloudApp.Data.GTR;
|
using AsbCloudApp.Data.GTR;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Services;
|
using AsbCloudInfrastructure.Services;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
@ -23,7 +26,8 @@ namespace AsbCloudWebApi
|
|||||||
{
|
{
|
||||||
c.MapType<TimeSpan>(() => new OpenApiSchema { Type = "string", Example = new OpenApiString("1.00:00:00") });
|
c.MapType<TimeSpan>(() => new OpenApiSchema { Type = "string", Example = new OpenApiString("1.00:00:00") });
|
||||||
c.MapType<DateOnly>(() => new OpenApiSchema { Type = "string", Format = "date" });
|
c.MapType<DateOnly>(() => new OpenApiSchema { Type = "string", Format = "date" });
|
||||||
c.MapType<JsonValue>(() => new OpenApiSchema {
|
c.MapType<JsonValue>(() => new OpenApiSchema
|
||||||
|
{
|
||||||
AnyOf = new OpenApiSchema[]
|
AnyOf = new OpenApiSchema[]
|
||||||
{
|
{
|
||||||
new OpenApiSchema {Type = "string", Format = "string" },
|
new OpenApiSchema {Type = "string", Format = "string" },
|
||||||
@ -102,6 +106,30 @@ namespace AsbCloudWebApi
|
|||||||
context.Token = accessToken;
|
context.Token = accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
},
|
||||||
|
OnTokenValidated = context =>
|
||||||
|
{
|
||||||
|
var idUser = context.Principal?.GetUserId();
|
||||||
|
if (idUser is null)
|
||||||
|
{
|
||||||
|
context.Fail("idUser is null");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.HttpContext.RequestServices.GetRequiredService<IUserRepository>();
|
||||||
|
var userService = services.BuildServiceProvider().GetRequiredService<IUserRepository>();
|
||||||
|
var user = userService.GetOrDefault(idUser.Value);
|
||||||
|
|
||||||
|
if (user is null)
|
||||||
|
{
|
||||||
|
context.Fail("user is null");
|
||||||
|
}
|
||||||
|
else if (user.IdState != User.ActiveStateId)
|
||||||
|
{
|
||||||
|
context.Fail("user is not active");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user