Skip to content

Commit 4f6a6e3

Browse files
max-zillalmarini
andauthored
Delete elasticsearch index on deletion, omit trash search results (#390)
* Add trash checks for Datasets, Collections * Update CHANGELOG.md * Remove entries from Elasticsearch * check if files are in trash --------- Co-authored-by: Luigi Marini <[email protected]>
1 parent a515dac commit 4f6a6e3

11 files changed

+52
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Search results are checked to verify nothing has been put in trash before display [#377](https://github.com/clowder-framework/clowder/issues/377)
813

914
## Unreleased
1015

app/api/Collections.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ class Collections @Inject() (datasets: DatasetService,
157157
case Some(collection) => {
158158
val useTrash = play.api.Play.configuration.getBoolean("useTrash").getOrElse(false)
159159
if (!useTrash || (useTrash && collection.trash)){
160+
Logger.debug("Deleting collection from indexes " + collectionId)
161+
current.plugin[ElasticsearchPlugin].foreach {
162+
_.delete(collectionId.stringify)
163+
}
160164
events.addObjectEvent(request.user , collection.id, collection.name, EventType.DELETE_COLLECTION.toString)
161165
collections.delete(collectionId)
162166
current.plugin[AdminsNotifierPlugin].foreach {

app/api/Datasets.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,11 @@ class Datasets @Inject()(
20412041
def deleteDatasetHelper(id: UUID, request: UserRequest[AnyContent]) = {
20422042
datasets.get(id) match {
20432043
case Some(dataset) => {
2044+
Logger.debug("Deleting dataset from indexes " + id)
2045+
current.plugin[ElasticsearchPlugin].foreach {
2046+
_.delete(id.stringify)
2047+
}
2048+
20442049
//remove dataset from RDF triple store if triple store is used
20452050
configuration.getString("userdfSPARQLStore").getOrElse("no") match {
20462051
case "yes" => rdfsparql.removeDatasetFromGraphs(id)

app/api/Files.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,9 @@ class Files @Inject()(
16971697
current.plugin[VersusPlugin].foreach {
16981698
_.removeFromIndexes(id)
16991699
}
1700+
current.plugin[ElasticsearchPlugin].foreach {
1701+
_.delete(id.stringify)
1702+
}
17001703
Logger.debug("Deleting file: " + file.filename)
17011704
files.removeFile(id, Utils.baseUrl(request), request.apiKey, request.user)
17021705

app/services/CollectionService.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,6 @@ trait CollectionService {
252252

253253
def getMetrics(): Iterator[Collection]
254254

255+
def isInTrash(id: UUID): Boolean
256+
255257
}

app/services/DatasetService.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,5 +389,7 @@ trait DatasetService {
389389

390390
def getTrashedIds(): List[UUID]
391391

392+
def isInTrash(id: UUID): Boolean
393+
392394
def recursiveArchive(dataset: Dataset, host: String, parameters: JsObject, apiKey: Option[String], user: Option[User])
393395
}

app/services/ElasticsearchPlugin.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,18 @@ class ElasticsearchPlugin(application: Application) extends Plugin {
228228
// Check permissions for each resource
229229
results.foreach(resource => {
230230
resource.resourceType match {
231-
case ResourceRef.file => if (Permission.checkPermission(user, Permission.ViewFile, resource))
232-
filesFound += resource.id
233-
case ResourceRef.dataset => if (Permission.checkPermission(user, Permission.ViewDataset, resource))
234-
datasetsFound += resource.id
235-
case ResourceRef.collection => if (Permission.checkPermission(user, Permission.ViewDataset, resource))
236-
collectionsFound += resource.id
231+
case ResourceRef.file => {
232+
if (Permission.checkPermission(user, Permission.ViewFile, resource) && !files.isInTrash(resource.id))
233+
filesFound += resource.id
234+
}
235+
case ResourceRef.dataset => {
236+
if (Permission.checkPermission(user, Permission.ViewDataset, resource) && !datasets.isInTrash(resource.id))
237+
datasetsFound += resource.id
238+
}
239+
case ResourceRef.collection => {
240+
if (Permission.checkPermission(user, Permission.ViewDataset, resource) && !collections.isInTrash(resource.id))
241+
collectionsFound += resource.id
242+
}
237243
case _ => {}
238244
}
239245
})

app/services/FileService.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,6 @@ trait FileService {
248248

249249
def getIterator(space: Option[String], since: Option[String], until: Option[String]): Iterator[File]
250250

251+
def isInTrash(id: UUID): Boolean
252+
251253
}

app/services/mongodb/MongoDBCollectionService.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,10 @@ class MongoDBCollectionService @Inject() (
11161116
Collection.find(MongoDBObject("trash" -> false)).toIterator
11171117
}
11181118

1119+
def isInTrash(id: UUID): Boolean = {
1120+
Collection.findOne(MongoDBObject("trash" -> true, "_id" -> new ObjectId(id.stringify))).isDefined
1121+
}
1122+
11191123
private def isSubCollectionIdInCollection(subCollectionId: UUID, collection: Collection) : Boolean = {
11201124
if (collection.child_collection_ids.contains(subCollectionId)){
11211125
return true

app/services/mongodb/MongoDBDatasetService.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,10 @@ class MongoDBDatasetService @Inject() (
16861686
trashedIds.toList
16871687
}
16881688

1689+
def isInTrash(id: UUID): Boolean = {
1690+
Dataset.findOne(MongoDBObject("trash" -> true, "_id" -> new ObjectId(id.stringify))).isDefined
1691+
}
1692+
16891693
/**
16901694
* Recursively submit requests to archive or unarchive the contents of the given dataset.
16911695
* NOTE: "parameters" includes "operation", which supports both archiving and unarchiving

0 commit comments

Comments
 (0)