Skip to content

Commit

Permalink
#3084: fixed ability to delete imported skill when the original was a…
Browse files Browse the repository at this point in the history
…ssigned to a global badge
  • Loading branch information
sudo-may committed Jan 14, 2025
1 parent 0bd89a3 commit 7c9e780
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class GlobalBadgesService {

@Transactional(readOnly = true)
boolean isSkillUsedInGlobalBadge(SkillDef skillDef) {
int numProjectSkillsUsedInGlobalBadge = skillRelDefRepo.getSkillUsedInGlobalBadgeCount(skillDef.skillId)
int numProjectSkillsUsedInGlobalBadge = skillRelDefRepo.getSkillUsedInGlobalBadgeCount(skillDef.id)
return numProjectSkillsUsedInGlobalBadge > 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ interface SkillRelDefRepo extends CrudRepository<SkillRelDef, Integer> {
and skill.skillId in (?2) ''')
List<SkillToSubjIds> findAllSubjectIdsByChildSkillId(String projectId, List<String> skillIds)

@Query(value = '''select count(srd.id) from SkillRelDef srd where srd.child.skillId=?1 and srd.type='BadgeRequirement' and srd.parent.type = 'GlobalBadge' ''')
Integer getSkillUsedInGlobalBadgeCount(String skillId)
@Query(value = '''select count(srd.id) from SkillRelDef srd where srd.child.id=?1 and srd.type='BadgeRequirement' and srd.parent.type = 'GlobalBadge' ''')
Integer getSkillUsedInGlobalBadgeCount(Integer skillRefId)

@Query(value = '''select srd.parent.id from SkillRelDef srd where srd.child.id=?1 and srd.type='BadgeRequirement' and srd.parent.type = 'GlobalBadge' ''')
List<Integer> getGlobalBadgeIdsForSkill(Integer id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import skills.intTests.utils.SkillsService
import skills.storage.model.UserAchievement
import skills.storage.repos.UserAchievedLevelRepo

import static skills.intTests.utils.SkillsFactory.*

class GlobalBadgeSpecs extends DefaultIntSpec {

@Autowired
Expand Down Expand Up @@ -370,4 +372,33 @@ class GlobalBadgeSpecs extends DefaultIntSpec {
!summary.badgeAchieved
}
def "removing imported skill when original is part of the global badge"() {
def project1 = createProject(1)
def p1subj1 = createSubject(1, 1)
def p1_skills = (1..3).collect {createSkill(1, 1, it, 0, 5, 0, 250) }
skillsService.createProjectAndSubjectAndSkills(project1, p1subj1, p1_skills)
p1_skills.each {
skillsService.exportSkillToCatalog(project1.projectId, it.skillId)
}
def badge = SkillsFactory.createBadge()
badge.enabled = 'true'
supervisorService.createGlobalBadge(badge)
supervisorService.assignSkillToGlobalBadge(projectId: project1.projectId, badgeId: badge.badgeId, skillId: p1_skills[0].skillId)
def project2 = createProject(2)
def p2subj1 = createSubject(2, 1)
skillsService.createProjectAndSubjectAndSkills(project2, p2subj1, [])
skillsService.importSkillFromCatalog(project2.projectId, p2subj1.subjectId, project1.projectId, p1_skills[0].skillId)
when:
skillsService.deleteSkill([projectId: project2.projectId, subjectId: p2subj1.subjectId, skillId: p1_skills[0].skillId])
def badgeSkills =supervisorService.getGlobalBadgeSkills(badge.badgeId)
then:
badgeSkills.size() == 1
badgeSkills.projectId == [project1.projectId]
badgeSkills.skillId == [p1_skills[0].skillId]
}
}

0 comments on commit 7c9e780

Please sign in to comment.