mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
[PM-15015] Add Country Name to auth request from request headers (#5471)
* feat(pm-15015) : * Add `CountryName` column to AuthRequest Table in Database, and refreshing AuthRequestView * Modify database stored procedures and Entity Framework migrations for AuthRequest Repositories * Add property to `ICurrentContext` and response models.
This commit is contained in:
168
util/Migrator/DbScripts/2025-02-27_00_AlterAuthRequest.sql
Normal file
168
util/Migrator/DbScripts/2025-02-27_00_AlterAuthRequest.sql
Normal file
@ -0,0 +1,168 @@
|
||||
ALTER TABLE
|
||||
[dbo].[AuthRequest]
|
||||
ADD
|
||||
[RequestCountryName] NVARCHAR(200) NULL;
|
||||
GO
|
||||
|
||||
EXECUTE sp_refreshview 'dbo.AuthRequestView'
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[AuthRequest_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER = NULL,
|
||||
@Type TINYINT,
|
||||
@RequestDeviceIdentifier NVARCHAR(50),
|
||||
@RequestDeviceType TINYINT,
|
||||
@RequestIpAddress VARCHAR(50),
|
||||
@RequestCountryName NVARCHAR(200),
|
||||
@ResponseDeviceId UNIQUEIDENTIFIER,
|
||||
@AccessCode VARCHAR(25),
|
||||
@PublicKey VARCHAR(MAX),
|
||||
@Key VARCHAR(MAX),
|
||||
@MasterPasswordHash VARCHAR(MAX),
|
||||
@Approved BIT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@ResponseDate DATETIME2(7),
|
||||
@AuthenticationDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[AuthRequest]
|
||||
(
|
||||
[Id],
|
||||
[UserId],
|
||||
[OrganizationId],
|
||||
[Type],
|
||||
[RequestDeviceIdentifier],
|
||||
[RequestDeviceType],
|
||||
[RequestIpAddress],
|
||||
[RequestCountryName],
|
||||
[ResponseDeviceId],
|
||||
[AccessCode],
|
||||
[PublicKey],
|
||||
[Key],
|
||||
[MasterPasswordHash],
|
||||
[Approved],
|
||||
[CreationDate],
|
||||
[ResponseDate],
|
||||
[AuthenticationDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@UserId,
|
||||
@OrganizationId,
|
||||
@Type,
|
||||
@RequestDeviceIdentifier,
|
||||
@RequestDeviceType,
|
||||
@RequestIpAddress,
|
||||
@RequestCountryName,
|
||||
@ResponseDeviceId,
|
||||
@AccessCode,
|
||||
@PublicKey,
|
||||
@Key,
|
||||
@MasterPasswordHash,
|
||||
@Approved,
|
||||
@CreationDate,
|
||||
@ResponseDate,
|
||||
@AuthenticationDate
|
||||
)
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[AuthRequest_Update]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER = NULL,
|
||||
@Type SMALLINT,
|
||||
@RequestDeviceIdentifier NVARCHAR(50),
|
||||
@RequestDeviceType SMALLINT,
|
||||
@RequestIpAddress VARCHAR(50),
|
||||
@RequestCountryName NVARCHAR(200),
|
||||
@ResponseDeviceId UNIQUEIDENTIFIER,
|
||||
@AccessCode VARCHAR(25),
|
||||
@PublicKey VARCHAR(MAX),
|
||||
@Key VARCHAR(MAX),
|
||||
@MasterPasswordHash VARCHAR(MAX),
|
||||
@Approved BIT,
|
||||
@CreationDate DATETIME2 (7),
|
||||
@ResponseDate DATETIME2 (7),
|
||||
@AuthenticationDate DATETIME2 (7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[AuthRequest]
|
||||
SET
|
||||
[UserId] = @UserId,
|
||||
[Type] = @Type,
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[RequestDeviceIdentifier] = @RequestDeviceIdentifier,
|
||||
[RequestDeviceType] = @RequestDeviceType,
|
||||
[RequestIpAddress] = @RequestIpAddress,
|
||||
[RequestCountryName] = @RequestCountryName,
|
||||
[ResponseDeviceId] = @ResponseDeviceId,
|
||||
[AccessCode] = @AccessCode,
|
||||
[PublicKey] = @PublicKey,
|
||||
[Key] = @Key,
|
||||
[MasterPasswordHash] = @MasterPasswordHash,
|
||||
[Approved] = @Approved,
|
||||
[CreationDate] = @CreationDate,
|
||||
[ResponseDate] = @ResponseDate,
|
||||
[AuthenticationDate] = @AuthenticationDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE AuthRequest_UpdateMany
|
||||
@jsonData NVARCHAR(MAX)
|
||||
AS
|
||||
BEGIN
|
||||
UPDATE AR
|
||||
SET
|
||||
[Id] = ARI.[Id],
|
||||
[UserId] = ARI.[UserId],
|
||||
[Type] = ARI.[Type],
|
||||
[RequestDeviceIdentifier] = ARI.[RequestDeviceIdentifier],
|
||||
[RequestDeviceType] = ARI.[RequestDeviceType],
|
||||
[RequestIpAddress] = ARI.[RequestIpAddress],
|
||||
[RequestCountryName] = ARI.[RequestCountryName],
|
||||
[ResponseDeviceId] = ARI.[ResponseDeviceId],
|
||||
[AccessCode] = ARI.[AccessCode],
|
||||
[PublicKey] = ARI.[PublicKey],
|
||||
[Key] = ARI.[Key],
|
||||
[MasterPasswordHash] = ARI.[MasterPasswordHash],
|
||||
[Approved] = ARI.[Approved],
|
||||
[CreationDate] = ARI.[CreationDate],
|
||||
[ResponseDate] = ARI.[ResponseDate],
|
||||
[AuthenticationDate] = ARI.[AuthenticationDate],
|
||||
[OrganizationId] = ARI.[OrganizationId]
|
||||
FROM
|
||||
[dbo].[AuthRequest] AR
|
||||
INNER JOIN
|
||||
OPENJSON(@jsonData)
|
||||
WITH (
|
||||
Id UNIQUEIDENTIFIER '$.Id',
|
||||
UserId UNIQUEIDENTIFIER '$.UserId',
|
||||
Type SMALLINT '$.Type',
|
||||
RequestDeviceIdentifier NVARCHAR(50) '$.RequestDeviceIdentifier',
|
||||
RequestDeviceType SMALLINT '$.RequestDeviceType',
|
||||
RequestIpAddress VARCHAR(50) '$.RequestIpAddress',
|
||||
RequestCountryName NVARCHAR(200) '$.RequestCountryName',
|
||||
ResponseDeviceId UNIQUEIDENTIFIER '$.ResponseDeviceId',
|
||||
AccessCode VARCHAR(25) '$.AccessCode',
|
||||
PublicKey VARCHAR(MAX) '$.PublicKey',
|
||||
[Key] VARCHAR(MAX) '$.Key',
|
||||
MasterPasswordHash VARCHAR(MAX) '$.MasterPasswordHash',
|
||||
Approved BIT '$.Approved',
|
||||
CreationDate DATETIME2 '$.CreationDate',
|
||||
ResponseDate DATETIME2 '$.ResponseDate',
|
||||
AuthenticationDate DATETIME2 '$.AuthenticationDate',
|
||||
OrganizationId UNIQUEIDENTIFIER '$.OrganizationId'
|
||||
) ARI ON AR.Id = ARI.Id;
|
||||
END
|
||||
GO
|
3014
util/MySqlMigrations/Migrations/20250304221039_AlterAuthRequest.Designer.cs
generated
Normal file
3014
util/MySqlMigrations/Migrations/20250304221039_AlterAuthRequest.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.MySqlMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AlterAuthRequest : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "RequestCountryName",
|
||||
table: "AuthRequest",
|
||||
type: "varchar(200)",
|
||||
maxLength: 200,
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RequestCountryName",
|
||||
table: "AuthRequest");
|
||||
}
|
||||
}
|
@ -407,6 +407,10 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Property<DateTime?>("AuthenticationDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("RequestCountryName")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("varchar(200)");
|
||||
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
|
3020
util/PostgresMigrations/Migrations/20250304204625_AlterAuthRequestTable.Designer.cs
generated
Normal file
3020
util/PostgresMigrations/Migrations/20250304204625_AlterAuthRequestTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AlterAuthRequestTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "RequestCountryName",
|
||||
table: "AuthRequest",
|
||||
type: "character varying(200)",
|
||||
maxLength: 200,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RequestCountryName",
|
||||
table: "AuthRequest");
|
||||
}
|
||||
}
|
@ -410,6 +410,10 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.Property<DateTime?>("AuthenticationDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("RequestCountryName")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("character varying(200)");
|
||||
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
|
3003
util/SqliteMigrations/Migrations/20250304204635_AlterAuthRequestTable.Designer.cs
generated
Normal file
3003
util/SqliteMigrations/Migrations/20250304204635_AlterAuthRequestTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.SqliteMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AlterAuthRequestTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "RequestCountryName",
|
||||
table: "AuthRequest",
|
||||
type: "TEXT",
|
||||
maxLength: 200,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RequestCountryName",
|
||||
table: "AuthRequest");
|
||||
}
|
||||
}
|
@ -402,6 +402,10 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Property<DateTime?>("AuthenticationDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RequestCountryName")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
Reference in New Issue
Block a user