From 746e294a77883f91431faf05625202cc52ad6123 Mon Sep 17 00:00:00 2001 From: rmmayo Date: Fri, 17 Jan 2025 20:08:11 +0000 Subject: [PATCH] #2548 - added userCommunity to QuizDefSummaryResult --- .../result/model/QuizDefSummaryResult.groovy | 3 +-- .../skills/services/quiz/QuizDefService.groovy | 5 ++++- .../quiz/ConfigureCommunityForQuizSpecs.groovy | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/skills/controller/result/model/QuizDefSummaryResult.groovy b/service/src/main/java/skills/controller/result/model/QuizDefSummaryResult.groovy index 93248ca89f..9f215f143f 100644 --- a/service/src/main/java/skills/controller/result/model/QuizDefSummaryResult.groovy +++ b/service/src/main/java/skills/controller/result/model/QuizDefSummaryResult.groovy @@ -21,8 +21,7 @@ class QuizDefSummaryResult { String quizId String name QuizDefParent.QuizType type - Date created - Integer numQuestions + String userCommunity } diff --git a/service/src/main/java/skills/services/quiz/QuizDefService.groovy b/service/src/main/java/skills/services/quiz/QuizDefService.groovy index 3010e0412b..186f6f892b 100644 --- a/service/src/main/java/skills/services/quiz/QuizDefService.groovy +++ b/service/src/main/java/skills/services/quiz/QuizDefService.groovy @@ -171,12 +171,15 @@ class QuizDefService { QuizDefSummaryResult getQuizDefSummary(String quizId) { assert quizId QuizDefRepo.QuizDefSummaryRes dbRes = quizDefRepo.getQuizDefSummary(quizId) + UserInfo userInfo = userInfoService.currentUser + Boolean isCommunityMember = userCommunityService.isUserCommunityMember(userInfo.username); return new QuizDefSummaryResult( quizId: quizId, name: dbRes.getName(), created: dbRes.getCreated(), type: QuizDefParent.QuizType.valueOf(dbRes.getQuizType()), - numQuestions: dbRes.getNumQuestions() + numQuestions: dbRes.getNumQuestions(), + userCommunity: isCommunityMember ? userCommunityService.getQuizUserCommunity(quizId) : null ) } diff --git a/service/src/test/java/skills/intTests/community/quiz/ConfigureCommunityForQuizSpecs.groovy b/service/src/test/java/skills/intTests/community/quiz/ConfigureCommunityForQuizSpecs.groovy index 1d3105d5da..246e23f193 100644 --- a/service/src/test/java/skills/intTests/community/quiz/ConfigureCommunityForQuizSpecs.groovy +++ b/service/src/test/java/skills/intTests/community/quiz/ConfigureCommunityForQuizSpecs.groovy @@ -63,18 +63,27 @@ class ConfigureCommunityForQuizSpecs extends DefaultIntSpec { def q1CreatedRes = pristineDragonsUser.createQuizDef(q1) def q2CreatedRes = pristineDragonsUser.createQuizDef(q2) def quizDefsRes = pristineDragonsUser.getQuizDefs() + def quizSummaryRes1 = pristineDragonsUser.getQuizDefSummary(q1.quizId) + def quizSummaryRes2 = pristineDragonsUser.getQuizDefSummary(q2.quizId) pristineDragonsUser.addQuizUserRole(q2.quizId, allDragonsUser.userName, RoleName.ROLE_QUIZ_ADMIN.toString()) def quizDefsRes_allDragonsUser = allDragonsUser.getQuizDefs() + def quizSummaryRes_allDragonsUser = allDragonsUser.getQuizDefSummary(q2.quizId) then: quizDefsRes.quizId == [q2.quizId, q1.quizId] quizDefsRes.userCommunity == ['All Dragons', 'Divine Dragon'] + quizSummaryRes1.quizId == q1.quizId + quizSummaryRes1.userCommunity == 'Divine Dragon' + quizSummaryRes2.quizId == q2.quizId + quizSummaryRes2.userCommunity == 'All Dragons' q1CreatedRes.body.userCommunity == 'Divine Dragon' q2CreatedRes.body.userCommunity == 'All Dragons' quizDefsRes_allDragonsUser.quizId == [q2.quizId] quizDefsRes_allDragonsUser.userCommunity == [null] + quizSummaryRes_allDragonsUser.quizId == q2.quizId + quizSummaryRes_allDragonsUser.userCommunity == null } def "community is null for a non-community user"() { @@ -85,11 +94,17 @@ class ConfigureCommunityForQuizSpecs extends DefaultIntSpec { def q1CreatedRes = skillsService.createQuizDef(q1) def q2CreatedRes = skillsService.createQuizDef(q2) def quizDefsRes = skillsService.getQuizDefs() + def quizSummaryRes1 = skillsService.getQuizDefSummary(q1.quizId) + def quizSummaryRes2 = skillsService.getQuizDefSummary(q2.quizId) then: quizDefsRes.quizId == [q2.quizId, q1.quizId] quizDefsRes.userCommunity == [null, null] q1CreatedRes.body.userCommunity == null q2CreatedRes.body.userCommunity == null + quizSummaryRes1.quizId == q1.quizId + quizSummaryRes1.userCommunity == null + quizSummaryRes2.quizId == q2.quizId + quizSummaryRes2.userCommunity == null } def "only member of the community can enable quiz "() {