-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-22992] Check cipher revision date when handling attachments #6451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikwithak
wants to merge
8
commits into
main
Choose a base branch
from
vault/PM-22992/attachments-revision-date
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd5b59d
Add lastKnownRevisionDate to Attachment functions
nikwithak 6f4d497
Add lastKnownRevisionDate to attachment endpoints
nikwithak 3713c8b
Change lastKnownCipherRevisionDate to lastKnownRevisionDate for consiโฆ
nikwithak c1a37e4
Add tests for RevisionDate checks in Attachment endpoints
nikwithak 01a4222
Improve validation on lastKnownRevisionDate
nikwithak 0c30a5c
Harden datetime parsing
nikwithak a324e38
Rename ValidateCipherLastKnownRevisionDate - removed 'Async' suffix
nikwithak 349814e
Cleanup and address PR feedback
nikwithak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,4 +9,9 @@ public class AttachmentRequestModel | |||||||||
public string FileName { get; set; } | ||||||||||
public long FileSize { get; set; } | ||||||||||
public bool AdminRequest { get; set; } = false; | ||||||||||
|
||||||||||
/// <summary> | ||||||||||
/// The last known revision date of the Cipher that this attachment belongs to. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โ๏ธ (non-blocking): I think we can use the proper xml documentation here
Suggested change
|
||||||||||
/// </summary> | ||||||||||
public DateTime? LastKnownRevisionDate { get; set; } | ||||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,7 @@ public async Task SaveAsync(Cipher cipher, Guid savingUserId, DateTime? lastKnow | |
} | ||
else | ||
{ | ||
ValidateCipherLastKnownRevisionDateAsync(cipher, lastKnownRevisionDate); | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
cipher.RevisionDate = DateTime.UtcNow; | ||
await _cipherRepository.ReplaceAsync(cipher); | ||
await _eventService.LogCipherEventAsync(cipher, Bit.Core.Enums.EventType.Cipher_Updated); | ||
|
@@ -168,7 +168,7 @@ public async Task SaveDetailsAsync(CipherDetails cipher, Guid savingUserId, Date | |
} | ||
else | ||
{ | ||
ValidateCipherLastKnownRevisionDateAsync(cipher, lastKnownRevisionDate); | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
cipher.RevisionDate = DateTime.UtcNow; | ||
await ValidateChangeInCollectionsAsync(cipher, collectionIds, savingUserId); | ||
await ValidateViewPasswordUserAsync(cipher); | ||
|
@@ -180,8 +180,9 @@ public async Task SaveDetailsAsync(CipherDetails cipher, Guid savingUserId, Date | |
} | ||
} | ||
|
||
public async Task UploadFileForExistingAttachmentAsync(Stream stream, Cipher cipher, CipherAttachment.MetaData attachment) | ||
public async Task UploadFileForExistingAttachmentAsync(Stream stream, Cipher cipher, CipherAttachment.MetaData attachment, DateTime? lastKnownRevisionDate = null) | ||
{ | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
if (attachment == null) | ||
{ | ||
throw new BadRequestException("Cipher attachment does not exist"); | ||
|
@@ -196,8 +197,9 @@ public async Task UploadFileForExistingAttachmentAsync(Stream stream, Cipher cip | |
} | ||
|
||
public async Task<(string attachmentId, string uploadUrl)> CreateAttachmentForDelayedUploadAsync(Cipher cipher, | ||
string key, string fileName, long fileSize, bool adminRequest, Guid savingUserId) | ||
string key, string fileName, long fileSize, bool adminRequest, Guid savingUserId, DateTime? lastKnownRevisionDate = null) | ||
{ | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
await ValidateCipherEditForAttachmentAsync(cipher, savingUserId, adminRequest, fileSize); | ||
|
||
var attachmentId = Utilities.CoreHelpers.SecureRandomString(32, upper: false, special: false); | ||
|
@@ -232,8 +234,9 @@ await _cipherRepository.UpdateAttachmentAsync(new CipherAttachment | |
} | ||
|
||
public async Task CreateAttachmentAsync(Cipher cipher, Stream stream, string fileName, string key, | ||
long requestLength, Guid savingUserId, bool orgAdmin = false) | ||
long requestLength, Guid savingUserId, bool orgAdmin = false, DateTime? lastKnownRevisionDate = null) | ||
{ | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
await ValidateCipherEditForAttachmentAsync(cipher, savingUserId, orgAdmin, requestLength); | ||
|
||
var attachmentId = Utilities.CoreHelpers.SecureRandomString(32, upper: false, special: false); | ||
|
@@ -284,10 +287,11 @@ public async Task CreateAttachmentAsync(Cipher cipher, Stream stream, string fil | |
} | ||
|
||
public async Task CreateAttachmentShareAsync(Cipher cipher, Stream stream, string fileName, string key, | ||
long requestLength, string attachmentId, Guid organizationId) | ||
long requestLength, string attachmentId, Guid organizationId, DateTime? lastKnownRevisionDate = null) | ||
{ | ||
try | ||
{ | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
if (requestLength < 1) | ||
{ | ||
throw new BadRequestException("No data to attach."); | ||
|
@@ -859,7 +863,7 @@ private async Task<bool> UserCanRestoreAsync(CipherDetails cipher, Guid userId) | |
return NormalCipherPermissions.CanRestore(user, cipher, organizationAbility); | ||
} | ||
|
||
private void ValidateCipherLastKnownRevisionDateAsync(Cipher cipher, DateTime? lastKnownRevisionDate) | ||
private void ValidateCipherLastKnownRevisionDate(Cipher cipher, DateTime? lastKnownRevisionDate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐๐ผ Thanks for renaming this |
||
{ | ||
if (cipher.Id == default || !lastKnownRevisionDate.HasValue) | ||
{ | ||
|
@@ -1007,7 +1011,7 @@ private async Task ValidateCipherCanBeShared( | |
throw new BadRequestException("Not enough storage available for this organization."); | ||
} | ||
|
||
ValidateCipherLastKnownRevisionDateAsync(cipher, lastKnownRevisionDate); | ||
ValidateCipherLastKnownRevisionDate(cipher, lastKnownRevisionDate); | ||
} | ||
|
||
private async Task ValidateViewPasswordUserAsync(Cipher cipher) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
โ Non-blocking. This kind of begs the question, what format are we expecting, and is this specific error being handled by the client? Or is this just a helpful hint for debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's the ISO8601 standard - It's more a helpful hint for debugging. If the client is getting this error message, it indicates a bug with the date format in the first place.