mirror of
https://github.com/bitwarden/server
synced 2025-12-06 00:03:34 +00:00
[SM-1274] Adding Project Events (#6022)
* Adding new logging for secrets * fixing secrest controller tests * fixing the tests * Server side changes for adding ProjectId to Event table, adding Project event logging to projectsController * Rough draft with TODO's need to work on EventRepository.cs, and ProjectRepository.cs * Undoing changes to make projects soft delete, we want those to be fully deleted still. Adding GetManyTrashedSecretsByIds to secret repo so we can get soft deleted secrets, getSecrets in eventsController takes in orgdId, so that we can check the permission even if the secret was permanently deleted and doesn' thave the org Id set. Adding Secret Perm Deleted, and Restored to event logs * db changes * fixing the way we log events * Trying to undo some manual changes that should have been migrations * adding migration files * fixing test * setting up userid for project controller tests * adding sql * sql * Rename file * Trying to get it to for sure add the column before we try and update sprocs * Adding code to refresh the view to include ProjectId I hope * code improvements * Suggested changes * suggested changes * trying to fix sql issues * fixing swagger issue * Update src/Core/SecretsManager/Repositories/Noop/NoopSecretRepository.cs Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * Suggested changes --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
IF COL_LENGTH('[dbo].[Event]', 'ProjectId') IS NULL
|
||||
BEGIN
|
||||
EXEC('ALTER TABLE [dbo].[Event] ADD [ProjectId] UNIQUEIDENTIFIER NULL');
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[EventView]', 'V') IS NOT NULL
|
||||
BEGIN
|
||||
DROP VIEW [dbo].[EventView];
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE VIEW [dbo].[EventView]
|
||||
AS
|
||||
SELECT * FROM [dbo].[Event];
|
||||
GO
|
||||
@@ -0,0 +1,174 @@
|
||||
-- Create or alter Event_Create procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[Event_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@Type INT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@InstallationId UNIQUEIDENTIFIER,
|
||||
@ProviderId UNIQUEIDENTIFIER,
|
||||
@CipherId UNIQUEIDENTIFIER,
|
||||
@CollectionId UNIQUEIDENTIFIER,
|
||||
@PolicyId UNIQUEIDENTIFIER,
|
||||
@GroupId UNIQUEIDENTIFIER,
|
||||
@OrganizationUserId UNIQUEIDENTIFIER,
|
||||
@ProviderUserId UNIQUEIDENTIFIER,
|
||||
@ProviderOrganizationId UNIQUEIDENTIFIER = NULL,
|
||||
@ActingUserId UNIQUEIDENTIFIER,
|
||||
@DeviceType SMALLINT,
|
||||
@IpAddress VARCHAR(50),
|
||||
@Date DATETIME2(7),
|
||||
@SystemUser TINYINT = NULL,
|
||||
@DomainName VARCHAR(256),
|
||||
@SecretId UNIQUEIDENTIFIER = NULL,
|
||||
@ServiceAccountId UNIQUEIDENTIFIER = NULL,
|
||||
@ProjectId UNIQUEIDENTIFIER = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
INSERT INTO [dbo].[Event]
|
||||
(
|
||||
[Id],
|
||||
[Type],
|
||||
[UserId],
|
||||
[OrganizationId],
|
||||
[InstallationId],
|
||||
[ProviderId],
|
||||
[CipherId],
|
||||
[CollectionId],
|
||||
[PolicyId],
|
||||
[GroupId],
|
||||
[OrganizationUserId],
|
||||
[ProviderUserId],
|
||||
[ProviderOrganizationId],
|
||||
[ActingUserId],
|
||||
[DeviceType],
|
||||
[IpAddress],
|
||||
[Date],
|
||||
[SystemUser],
|
||||
[DomainName],
|
||||
[SecretId],
|
||||
[ServiceAccountId],
|
||||
[ProjectId]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@Type,
|
||||
@UserId,
|
||||
@OrganizationId,
|
||||
@InstallationId,
|
||||
@ProviderId,
|
||||
@CipherId,
|
||||
@CollectionId,
|
||||
@PolicyId,
|
||||
@GroupId,
|
||||
@OrganizationUserId,
|
||||
@ProviderUserId,
|
||||
@ProviderOrganizationId,
|
||||
@ActingUserId,
|
||||
@DeviceType,
|
||||
@IpAddress,
|
||||
@Date,
|
||||
@SystemUser,
|
||||
@DomainName,
|
||||
@SecretId,
|
||||
@ServiceAccountId,
|
||||
@ProjectId
|
||||
);
|
||||
END
|
||||
GO
|
||||
|
||||
-- Create or alter Event_ReadPageByProjectId procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[Event_ReadPageByProjectId]
|
||||
@ProjectId UNIQUEIDENTIFIER,
|
||||
@StartDate DATETIME2(7),
|
||||
@EndDate DATETIME2(7),
|
||||
@BeforeDate DATETIME2(7),
|
||||
@PageSize INT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
e.Id,
|
||||
e.Date,
|
||||
e.Type,
|
||||
e.UserId,
|
||||
e.OrganizationId,
|
||||
e.InstallationId,
|
||||
e.ProviderId,
|
||||
e.CipherId,
|
||||
e.CollectionId,
|
||||
e.PolicyId,
|
||||
e.GroupId,
|
||||
e.OrganizationUserId,
|
||||
e.ProviderUserId,
|
||||
e.ProviderOrganizationId,
|
||||
e.DeviceType,
|
||||
e.IpAddress,
|
||||
e.ActingUserId,
|
||||
e.SystemUser,
|
||||
e.DomainName,
|
||||
e.SecretId,
|
||||
e.ServiceAccountId,
|
||||
e.ProjectId
|
||||
FROM
|
||||
[dbo].[EventView] e
|
||||
WHERE
|
||||
[Date] >= @StartDate
|
||||
AND (@BeforeDate IS NOT NULL OR [Date] <= @EndDate)
|
||||
AND (@BeforeDate IS NULL OR [Date] < @BeforeDate)
|
||||
AND [ProjectId] = @ProjectId
|
||||
ORDER BY [Date] DESC
|
||||
OFFSET 0 ROWS
|
||||
FETCH NEXT @PageSize ROWS ONLY;
|
||||
END
|
||||
GO
|
||||
|
||||
-- Create or alter Event_ReadPageBySecretId procedure
|
||||
CREATE OR ALTER PROCEDURE [dbo].[Event_ReadPageBySecretId]
|
||||
@SecretId UNIQUEIDENTIFIER,
|
||||
@StartDate DATETIME2(7),
|
||||
@EndDate DATETIME2(7),
|
||||
@BeforeDate DATETIME2(7),
|
||||
@PageSize INT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT
|
||||
e.Id,
|
||||
e.Date,
|
||||
e.Type,
|
||||
e.UserId,
|
||||
e.OrganizationId,
|
||||
e.InstallationId,
|
||||
e.ProviderId,
|
||||
e.CipherId,
|
||||
e.CollectionId,
|
||||
e.PolicyId,
|
||||
e.GroupId,
|
||||
e.OrganizationUserId,
|
||||
e.ProviderUserId,
|
||||
e.ProviderOrganizationId,
|
||||
e.DeviceType,
|
||||
e.IpAddress,
|
||||
e.ActingUserId,
|
||||
e.SystemUser,
|
||||
e.DomainName,
|
||||
e.SecretId,
|
||||
e.ServiceAccountId,
|
||||
e.ProjectId
|
||||
FROM
|
||||
[dbo].[EventView] e
|
||||
WHERE
|
||||
[Date] >= @StartDate
|
||||
AND (@BeforeDate IS NOT NULL OR [Date] <= @EndDate)
|
||||
AND (@BeforeDate IS NULL OR [Date] < @BeforeDate)
|
||||
AND [SecretId] = @SecretId
|
||||
ORDER BY [Date] DESC
|
||||
OFFSET 0 ROWS
|
||||
FETCH NEXT @PageSize ROWS ONLY;
|
||||
END
|
||||
GO
|
||||
3266
util/MySqlMigrations/Migrations/20250717164642_20250717_AddingProjectIdToEvent.Designer.cs
generated
Normal file
3266
util/MySqlMigrations/Migrations/20250717164642_20250717_AddingProjectIdToEvent.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.MySqlMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class _20250717_AddingProjectIdToEvent : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ProjectId",
|
||||
table: "Event",
|
||||
type: "char(36)",
|
||||
nullable: true,
|
||||
collation: "ascii_general_ci");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ProjectId",
|
||||
table: "Event");
|
||||
}
|
||||
}
|
||||
@@ -1295,6 +1295,9 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.Property<Guid?>("PolicyId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<Guid?>("ProviderId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
|
||||
3272
util/PostgresMigrations/Migrations/20250717164620_20250717_AddingProjectIdToEvent.Designer.cs
generated
Normal file
3272
util/PostgresMigrations/Migrations/20250717164620_20250717_AddingProjectIdToEvent.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class _20250717_AddingProjectIdToEvent : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ProjectId",
|
||||
table: "Event",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ProjectId",
|
||||
table: "Event");
|
||||
}
|
||||
}
|
||||
@@ -1300,6 +1300,9 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.Property<Guid?>("PolicyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("ProviderId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
|
||||
3255
util/SqliteMigrations/Migrations/20250717164556_20250717_AddingProjectIdToEvent.Designer.cs
generated
Normal file
3255
util/SqliteMigrations/Migrations/20250717164556_20250717_AddingProjectIdToEvent.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.SqliteMigrations.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class _20250717_AddingProjectIdToEvent : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ProjectId",
|
||||
table: "Event",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ProjectId",
|
||||
table: "Event");
|
||||
}
|
||||
}
|
||||
@@ -1284,6 +1284,9 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.Property<Guid?>("PolicyId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid?>("ProjectId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid?>("ProviderId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user