Skip to content

Commit

Permalink
set software trusted source to null if we delete the trusted source
Browse files Browse the repository at this point in the history
  • Loading branch information
lrollus committed Jul 14, 2021
1 parent fe96215 commit 4aa8811
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SoftwareUserRepositoryService extends ModelService {
def transactionService
def securityACLService
def amqpQueueService
def softwareService

@Override
def currentDomain() {
Expand Down Expand Up @@ -94,14 +95,10 @@ class SoftwareUserRepositoryService extends ModelService {
return executeCommand(c, domain, null)
}

// def deleteDependentSoftware(SoftwareUserRepository domain, Transaction transaction, Task task = null) {
//
//
// log.info("delteDependantSoftware ${Software.findAllBySoftwareRepository(domain).size()}")
// Software.findAllBySoftwareRepository(domain).each {
// softwareService.delete(it, transaction, null, false)
// }
// }
def deleteDependentSoftware(SoftwareUserRepository domain, Transaction transaction, Task task = null) {
log.info("deleteDependantSoftware ${Software.findAllBySoftwareUserRepository(domain).size()}")
Software.executeUpdate("update Software set softwareUserRepository = null where softwareUserRepository.id = ?", [domain.id])
}

@Override
def getStringParamsI18n(def domain) {
Expand All @@ -125,6 +122,20 @@ class SoftwareUserRepositoryService extends ModelService {
amqpQueueService.publishMessage(AmqpQueue.findByName("queueCommunication"), jsonBuilder.toString())
}

@Override
def afterDelete(Object domain, Object response) {
SoftwareUserRepository softwareUserRepository = domain as SoftwareUserRepository
def message = [requestType: "removeSoftwareUserRepository",
id: softwareUserRepository.id,
provider: softwareUserRepository.provider,
username: softwareUserRepository.username,
dockerUsername: softwareUserRepository.dockerUsername,
prefix: softwareUserRepository.prefix]
JsonBuilder jsonBuilder = new JsonBuilder()
jsonBuilder(message)
amqpQueueService.publishMessage(AmqpQueue.findByName("queueCommunication"), jsonBuilder.toString())
}

def refresh(def repo) {
def message = [requestType: "refreshRepository",
id: repo.id,
Expand Down
26 changes: 26 additions & 0 deletions test/functional/be/cytomine/SoftwareUserRepositoryTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package be.cytomine

import be.cytomine.test.BasicInstanceBuilder
import be.cytomine.test.Infos
import be.cytomine.test.http.SoftwareAPI
import be.cytomine.test.http.SoftwareUserRepositoryAPI
import be.cytomine.utils.UpdateData
import grails.converters.JSON
Expand Down Expand Up @@ -58,4 +59,29 @@ class SoftwareUserRepositoryTests {
def showResult = SoftwareUserRepositoryAPI.show(id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD)
assert 404 == showResult.code
}

void testDeleteSoftwareUserRepositoryWithSoftware() {
def repoToDelete = BasicInstanceBuilder.getSoftwareUserRepositoryNotExist(true)
def id = repoToDelete.id

def software = BasicInstanceBuilder.getSoftwareNotExist(true)
software.setSoftwareUserRepository(repoToDelete)
software = BasicInstanceBuilder.saveDomain(software)

def softwareResult = SoftwareAPI.show(software.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD)
assert 200 == softwareResult.code
def json = JSON.parse(softwareResult.data)
assert json.softwareUserRepository == repoToDelete.id

def result = SoftwareUserRepositoryAPI.delete(id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD)
assert 200 == result.code

def showResult = SoftwareUserRepositoryAPI.show(id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD)
assert 404 == showResult.code

softwareResult = SoftwareAPI.show(software.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD)
assert 200 == softwareResult.code
json = JSON.parse(softwareResult.data)
assert json.softwareUserRepository instanceof JSONObject.Null
}
}

0 comments on commit 4aa8811

Please sign in to comment.