-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add an endpoint to undeprecate files #4461
Merged
olivergrabinski
merged 25 commits into
BlueBrain:master
from
olivergrabinski:undeprecate-files
Nov 8, 2023
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9250078
Add FileUndeprecated event
olivergrabinski ab7c5f0
Add method to undeprecate files
olivergrabinski 3e6a847
Improve `.accepted`
olivergrabinski bfe30b6
Improve FileSpec undeprecation tests
olivergrabinski e6dc8b8
Make FileRoutesSpec independent w.r.t. permissions
olivergrabinski 216f931
Use non-confusing names
olivergrabinski c89bf3d
Add undeprecate endpoint and test it
olivergrabinski 2d56da3
Make FilesRoutesSpec tests independent
olivergrabinski 1f93b34
Fix user naming
olivergrabinski e40e5ed
Add integration tests
olivergrabinski f5cc6fb
scalafmt
olivergrabinski ce5a825
Add tests to FilesStmSpec for undeprecation
olivergrabinski 5cc9786
Update version of storage used in tests
olivergrabinski 9275fb7
Move `fileMetadata`
olivergrabinski d3578d8
Merge branch 'master' into undeprecate-files
olivergrabinski f53d3c4
Fix RemoteStorageClientSpec
olivergrabinski 02a60ad
Fix FileRoutesSpec
olivergrabinski 1b2b7e6
scalafmt
olivergrabinski 89148d5
scalafmt
olivergrabinski d6a5256
Merge branch 'master' into undeprecate-files
shinyhappydan 0459fa4
Update integration test
olivergrabinski ac87f61
User other `fail` method
olivergrabinski 1396655
Inline json errors
olivergrabinski ab7bc75
Add dox
olivergrabinski 38c3f3f
Merge branch 'master' into undeprecate-files
shinyhappydan 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 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 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 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 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 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 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
14 changes: 14 additions & 0 deletions
14
delta/plugins/storage/src/test/resources/files/database/file-undeprecated.json
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"id" : "https://bluebrain.github.io/nexus/vocabulary/file", | ||
"project" : "myorg/myproj", | ||
"storage": "https://bluebrain.github.io/nexus/vocabulary/disk-storage?rev=1", | ||
"storageType": "DiskStorage", | ||
"rev" : 6, | ||
"instant" : "1970-01-01T00:00:00Z", | ||
"subject" : { | ||
"subject" : "username", | ||
"realm" : "myrealm", | ||
"@type" : "User" | ||
}, | ||
"@type" : "FileUndeprecated" | ||
} |
5 changes: 0 additions & 5 deletions
5
delta/plugins/storage/src/test/resources/files/errors/already-exists.json
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
delta/plugins/storage/src/test/resources/files/sse/file-undeprecated.json
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"@context": [ | ||
"https://bluebrain.github.io/nexus/contexts/metadata.json", | ||
"https://bluebrain.github.io/nexus/contexts/files.json" | ||
], | ||
"@type": "FileUndeprecated", | ||
"_fileId": "https://bluebrain.github.io/nexus/vocabulary/file", | ||
"_instant": "1970-01-01T00:00:00Z", | ||
"_project": "http://localhost/v1/projects/myorg/myproj", | ||
"_resourceId": "https://bluebrain.github.io/nexus/vocabulary/file", | ||
"_rev": 6, | ||
"_subject": "http://localhost/v1/realms/myrealm/users/username" | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -41,7 +41,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.DoobieScalaTestFixture | |
import ch.epfl.bluebrain.nexus.testkit.remotestorage.RemoteStorageDocker | ||
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec | ||
import monix.execution.Scheduler | ||
import org.scalatest.DoNotDiscover | ||
import org.scalatest.{Assertion, DoNotDiscover} | ||
import org.scalatest.concurrent.Eventually | ||
|
||
import java.net.URLDecoder | ||
|
@@ -490,6 +490,44 @@ class FilesSpec(docker: RemoteStorageDocker) | |
|
||
} | ||
|
||
"undeprecating a file" should { | ||
|
||
"succeed" in { | ||
givenADeprecatedFile { id => | ||
files.undeprecate(id, 2).accepted.deprecated shouldEqual false | ||
assertActive(id) | ||
} | ||
} | ||
|
||
"reject if file doesn't exists" in { | ||
files.undeprecate(fileId("404"), 1).rejectedWith[FileNotFound] | ||
} | ||
|
||
"reject if file is not deprecated" in { | ||
givenAFile { id => | ||
files.undeprecate(id, 1).assertRejectedWith[FileIsNotDeprecated] | ||
assertRemainsActive(id) | ||
} | ||
} | ||
|
||
"reject if the revision passed is incorrect" in { | ||
givenADeprecatedFile { id => | ||
files.undeprecate(id, 3).assertRejectedEquals(IncorrectRev(3, 2)) | ||
assertRemainsDeprecated(id) | ||
} | ||
} | ||
|
||
"reject if project does not exist" in { | ||
val wrongProject = ProjectRef(org, Label.unsafe("other")) | ||
files.deprecate(FileId(nxv + "id", wrongProject), 1).rejectedWith[ProjectContextRejection] | ||
} | ||
|
||
"reject if project is deprecated" in { | ||
files.undeprecate(FileId(nxv + "id", deprecatedProject.ref), 2).rejectedWith[ProjectContextRejection] | ||
} | ||
|
||
} | ||
|
||
Comment on lines
+493
to
+530
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. Really nice test |
||
"fetching a file" should { | ||
val resourceRev1 = mkResource(file1, projectRef, diskRev, attributes("myfile.txt")) | ||
val resourceRev4 = mkResource(file1, projectRef, diskRev, attributes(), rev = 4) | ||
|
@@ -583,6 +621,29 @@ class FilesSpec(docker: RemoteStorageDocker) | |
} | ||
|
||
} | ||
|
||
def givenAFile(assertion: FileId => Assertion): Assertion = { | ||
val filename = genString() | ||
val id = fileId(filename) | ||
files.create(id, Some(diskId), randomEntity(filename, 1), None).accepted | ||
files.fetch(id).accepted | ||
assertion(id) | ||
} | ||
|
||
def givenADeprecatedFile(assertion: FileId => Assertion): Assertion = { | ||
givenAFile { id => | ||
files.deprecate(id, 1).accepted | ||
files.fetch(id).accepted.deprecated shouldEqual true | ||
assertion(id) | ||
} | ||
} | ||
|
||
def assertRemainsDeprecated(id: FileId): Assertion = | ||
files.fetch(id).accepted.deprecated shouldEqual true | ||
def assertActive(id: FileId): Assertion = | ||
files.fetch(id).accepted.deprecated shouldEqual false | ||
def assertRemainsActive(id: FileId): Assertion = | ||
assertActive(id) | ||
} | ||
|
||
} |
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.
Not really an issue of your PR but we should be doing indexing within the
Files
here