Browse Source

update request/response models

PM-27884
jaasen-livefront 6 days ago
parent
commit
ce4f5edde6
No known key found for this signature in database
  1. 36
      src/Api/Vault/Controllers/CiphersController.cs
  2. 2
      src/Api/Vault/Models/Request/CipherRequestModel.cs
  3. 2
      src/Api/Vault/Models/Response/CipherResponseModel.cs
  4. 2
      src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_UpdateWithCollections.sql

36
src/Api/Vault/Controllers/CiphersController.cs

@ -911,7 +911,7 @@ public class CiphersController : Controller
[HttpPut("{id}/archive")] [HttpPut("{id}/archive")]
[RequireFeature(FeatureFlagKeys.ArchiveVaultItems)] [RequireFeature(FeatureFlagKeys.ArchiveVaultItems)]
public async Task<CipherMiniResponseModel> PutArchive(Guid id) public async Task<CipherResponseModel> PutArchive(Guid id)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
@ -922,12 +922,16 @@ public class CiphersController : Controller
throw new BadRequestException("Cipher was not archived. Ensure the provided ID is correct and you have permission to archive it."); throw new BadRequestException("Cipher was not archived. Ensure the provided ID is correct and you have permission to archive it.");
} }
return new CipherMiniResponseModel(archivedCipherOrganizationDetails.First(), _globalSettings, archivedCipherOrganizationDetails.First().OrganizationUseTotp); return new CipherResponseModel(archivedCipherOrganizationDetails.First(),
await _userService.GetUserByIdAsync(userId),
await _applicationCacheService.GetOrganizationAbilitiesAsync(),
_globalSettings
);
} }
[HttpPut("archive")] [HttpPut("archive")]
[RequireFeature(FeatureFlagKeys.ArchiveVaultItems)] [RequireFeature(FeatureFlagKeys.ArchiveVaultItems)]
public async Task<ListResponseModel<CipherMiniResponseModel>> PutArchiveMany([FromBody] CipherBulkArchiveRequestModel model) public async Task<ListResponseModel<CipherResponseModel>> PutArchiveMany([FromBody] CipherBulkArchiveRequestModel model)
{ {
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -935,6 +939,7 @@ public class CiphersController : Controller
} }
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var user = await _userService.GetUserByIdAsync(userId);
var cipherIdsToArchive = new HashSet<Guid>(model.Ids); var cipherIdsToArchive = new HashSet<Guid>(model.Ids);
@ -945,9 +950,14 @@ public class CiphersController : Controller
throw new BadRequestException("No ciphers were archived. Ensure the provided IDs are correct and you have permission to archive them."); throw new BadRequestException("No ciphers were archived. Ensure the provided IDs are correct and you have permission to archive them.");
} }
var responses = archivedCiphers.Select(c => new CipherMiniResponseModel(c, _globalSettings, c.OrganizationUseTotp)); var organizationAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
var responses = archivedCiphers.Select(c => new CipherResponseModel(c,
user,
organizationAbilities,
_globalSettings
));
return new ListResponseModel<CipherMiniResponseModel>(responses); return new ListResponseModel<CipherResponseModel>(responses);
} }
[HttpDelete("{id}")] [HttpDelete("{id}")]
@ -1109,7 +1119,7 @@ public class CiphersController : Controller
[HttpPut("{id}/unarchive")] [HttpPut("{id}/unarchive")]
[RequireFeature(FeatureFlagKeys.ArchiveVaultItems)] [RequireFeature(FeatureFlagKeys.ArchiveVaultItems)]
public async Task<CipherMiniResponseModel> PutUnarchive(Guid id) public async Task<CipherResponseModel> PutUnarchive(Guid id)
{ {
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
@ -1120,12 +1130,16 @@ public class CiphersController : Controller
throw new BadRequestException("Cipher was not unarchived. Ensure the provided ID is correct and you have permission to archive it."); throw new BadRequestException("Cipher was not unarchived. Ensure the provided ID is correct and you have permission to archive it.");
} }
return new CipherMiniResponseModel(unarchivedCipherDetails.First(), _globalSettings, unarchivedCipherDetails.First().OrganizationUseTotp); return new CipherResponseModel(unarchivedCipherDetails.First(),
await _userService.GetUserByIdAsync(userId),
await _applicationCacheService.GetOrganizationAbilitiesAsync(),
_globalSettings
);
} }
[HttpPut("unarchive")] [HttpPut("unarchive")]
[RequireFeature(FeatureFlagKeys.ArchiveVaultItems)] [RequireFeature(FeatureFlagKeys.ArchiveVaultItems)]
public async Task<ListResponseModel<CipherMiniResponseModel>> PutUnarchiveMany([FromBody] CipherBulkUnarchiveRequestModel model) public async Task<ListResponseModel<CipherResponseModel>> PutUnarchiveMany([FromBody] CipherBulkUnarchiveRequestModel model)
{ {
if (!_globalSettings.SelfHosted && model.Ids.Count() > 500) if (!_globalSettings.SelfHosted && model.Ids.Count() > 500)
{ {
@ -1133,6 +1147,8 @@ public class CiphersController : Controller
} }
var userId = _userService.GetProperUserId(User).Value; var userId = _userService.GetProperUserId(User).Value;
var user = await _userService.GetUserByIdAsync(userId);
var organizationAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync();
var cipherIdsToUnarchive = new HashSet<Guid>(model.Ids); var cipherIdsToUnarchive = new HashSet<Guid>(model.Ids);
@ -1143,9 +1159,9 @@ public class CiphersController : Controller
throw new BadRequestException("Ciphers were not unarchived. Ensure the provided ID is correct and you have permission to archive it."); throw new BadRequestException("Ciphers were not unarchived. Ensure the provided ID is correct and you have permission to archive it.");
} }
var responses = unarchivedCipherOrganizationDetails.Select(c => new CipherMiniResponseModel(c, _globalSettings, c.OrganizationUseTotp)); var responses = unarchivedCipherOrganizationDetails.Select(c => new CipherResponseModel(c, user, organizationAbilities, _globalSettings));
return new ListResponseModel<CipherMiniResponseModel>(responses); return new ListResponseModel<CipherResponseModel>(responses);
} }
[HttpPut("{id}/restore")] [HttpPut("{id}/restore")]

2
src/Api/Vault/Models/Request/CipherRequestModel.cs

@ -80,6 +80,7 @@ public class CipherRequestModel
{ {
existingCipher.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId); existingCipher.FolderId = string.IsNullOrWhiteSpace(FolderId) ? null : (Guid?)new Guid(FolderId);
existingCipher.Favorite = Favorite; existingCipher.Favorite = Favorite;
existingCipher.ArchivedDate = ArchivedDate;
ToCipher(existingCipher); ToCipher(existingCipher);
return existingCipher; return existingCipher;
} }
@ -129,6 +130,7 @@ public class CipherRequestModel
existingCipher.Key = Key; existingCipher.Key = Key;
existingCipher.Folders = UpdateUserSpecificJsonField(existingCipher.Folders, userIdKey, FolderId); existingCipher.Folders = UpdateUserSpecificJsonField(existingCipher.Folders, userIdKey, FolderId);
existingCipher.Favorites = UpdateUserSpecificJsonField(existingCipher.Favorites, userIdKey, Favorite); existingCipher.Favorites = UpdateUserSpecificJsonField(existingCipher.Favorites, userIdKey, Favorite);
existingCipher.Archives = UpdateUserSpecificJsonField(existingCipher.Archives, userIdKey, ArchivedDate);
var hasAttachments2 = (Attachments2?.Count ?? 0) > 0; var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
var hasAttachments = (Attachments?.Count ?? 0) > 0; var hasAttachments = (Attachments?.Count ?? 0) > 0;

2
src/Api/Vault/Models/Response/CipherResponseModel.cs

@ -110,7 +110,6 @@ public class CipherMiniResponseModel : ResponseModel
public DateTime? DeletedDate { get; set; } public DateTime? DeletedDate { get; set; }
public CipherRepromptType Reprompt { get; set; } public CipherRepromptType Reprompt { get; set; }
public string Key { get; set; } public string Key { get; set; }
public DateTime? ArchivedDate { get; set; }
} }
public class CipherResponseModel : CipherMiniResponseModel public class CipherResponseModel : CipherMiniResponseModel
@ -135,6 +134,7 @@ public class CipherResponseModel : CipherMiniResponseModel
public bool Favorite { get; set; } public bool Favorite { get; set; }
public bool Edit { get; set; } public bool Edit { get; set; }
public bool ViewPassword { get; set; } public bool ViewPassword { get; set; }
public DateTime? ArchivedDate { get; set; }
public CipherPermissionsResponseModel Permissions { get; set; } public CipherPermissionsResponseModel Permissions { get; set; }
} }

2
src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_UpdateWithCollections.sql

@ -12,7 +12,7 @@
@DeletedDate DATETIME2(7), @DeletedDate DATETIME2(7),
@Reprompt TINYINT, @Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL, @Key VARCHAR(MAX) = NULL,
@Archives NVARCHAR(MAX), @Archives NVARCHAR(MAX) = NULL,
@CollectionIds AS [dbo].[GuidIdArray] READONLY @CollectionIds AS [dbo].[GuidIdArray] READONLY
AS AS
BEGIN BEGIN

Loading…
Cancel
Save