1
0
mirror of https://github.com/bitwarden/server synced 2026-02-11 14:03:24 +00:00

[PM-26772] Importing Archived Ciphers (#6452)

* persist archive date for importing ciphers

* throw error if a user imports archived ciphers into an organization

* remove extra semi-colon

* set archive date for initial tests to avoid error thrown

* refactor ArchivedDate query

* add test for throwing for importing archived ciphers into a organization

* remove folder and organization id from test

* remove unneeded org id and null out the folderid
This commit is contained in:
Nick Krantz
2025-10-22 08:42:29 -05:00
committed by GitHub
parent 3866bc5155
commit b63fdfab0d
3 changed files with 107 additions and 2 deletions

View File

@@ -74,10 +74,14 @@ public class ImportCiphersController : Controller
throw new BadRequestException("You cannot import this much data at once.");
}
if (model.Ciphers.Any(c => c.ArchivedDate.HasValue))
{
throw new BadRequestException("You cannot import archived items into an organization.");
}
var orgId = new Guid(organizationId);
var collections = model.Collections.Select(c => c.ToCollection(orgId)).ToList();
//An User is allowed to import if CanCreate Collections or has AccessToImportExport
var authorized = await CheckOrgImportPermission(collections, orgId);
if (!authorized)
@@ -156,7 +160,7 @@ public class ImportCiphersController : Controller
if (existingCollections.Any() && (await _authorizationService.AuthorizeAsync(User, existingCollections, BulkCollectionOperations.ImportCiphers)).Succeeded)
{
return true;
};
}
return false;
}

View File

@@ -218,6 +218,8 @@ public static class BulkResourceCreationService
ciphersTable.Columns.Add(revisionDateColumn);
var deletedDateColumn = new DataColumn(nameof(c.DeletedDate), typeof(DateTime));
ciphersTable.Columns.Add(deletedDateColumn);
var archivedDateColumn = new DataColumn(nameof(c.ArchivedDate), typeof(DateTime));
ciphersTable.Columns.Add(archivedDateColumn);
var repromptColumn = new DataColumn(nameof(c.Reprompt), typeof(short));
ciphersTable.Columns.Add(repromptColumn);
var keyColummn = new DataColumn(nameof(c.Key), typeof(string));
@@ -247,6 +249,7 @@ public static class BulkResourceCreationService
row[creationDateColumn] = cipher.CreationDate;
row[revisionDateColumn] = cipher.RevisionDate;
row[deletedDateColumn] = cipher.DeletedDate.HasValue ? (object)cipher.DeletedDate : DBNull.Value;
row[archivedDateColumn] = cipher.ArchivedDate.HasValue ? cipher.ArchivedDate : DBNull.Value;
row[repromptColumn] = cipher.Reprompt.HasValue ? cipher.Reprompt.Value : DBNull.Value;
row[keyColummn] = cipher.Key;