Skip to content

Commit

Permalink
Merge pull request #3155 from NationalSecurityAgency/t#3151/copy_enab…
Browse files Browse the repository at this point in the history
…le_uc

T#3151/copy enable uc
  • Loading branch information
sudo-may authored Feb 7, 2025
2 parents 68a53db + babd8f8 commit 59601b5
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Community Project Creation Tests', () => {
cy.get('[data-cy="projectCard_copy"] [data-cy="userCommunity"]').contains('For Divine Dragon Nation')
});

it('copy non-protected projects and make it protected during copy', () => {
it('copy a non-protected project and make it protected during copy', () => {
cy.createProject(1, {enableProtectedUserCommunity: false})

cy.visit('/administrator/')
Expand All @@ -84,10 +84,18 @@ describe('Community Project Creation Tests', () => {
cy.get('[data-cy="restrictCommunity"] [data-pc-section="input"]').click()
cy.get('[data-cy="restrictCommunityControls"]').contains(warningMsg)

cy.intercept('POST', '/api/validation/description*').as('validateDescription');
cy.get('[data-cy="markdownEditorInput"]').type('ldkj aljdl aj\n\njabberwocky');
cy.wait('@validateDescription');
cy.get('[data-cy="descriptionError"]').should('not.be.visible')
cy.get('[data-cy="saveDialogBtn"]').should('be.enabled')

cy.get('[data-cy="saveDialogBtn"]').click()
cy.get('[data-cy="allDoneBtn"]').click()
cy.get('[data-cy="projectCard_copy"] [data-cy="userCommunity"]').contains('For Divine Dragon Nation')
});

cy.reload()
cy.get('[data-cy="projectCard_copy"] [data-cy="userCommunity"]').contains('For Divine Dragon Nation')
});

});
61 changes: 61 additions & 0 deletions e2e-tests/cypress/e2e/community/community_quiz_creation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,5 +552,66 @@ describe('Community Quiz Creation Tests', () => {

cy.get('[data-p-index="1"] [data-cy="userCommunity"]').contains('For Divine Dragon Nation')

cy.reload()
cy.get('[data-p-index="1"] [data-cy="userCommunity"]').contains('For Divine Dragon Nation')
});

it('copy a non-protected quiz and make it protected during copy', () => {
cy.createQuizDef(1, { name: 'Quiz 1' });
cy.createSurveyDef(2, { name: 'Survey 1' });

cy.visit('/administrator/quizzes/')
cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Survey' }],
], 5);

cy.get('[data-cy="copyQuizButton_quiz1"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Quiz 1')

cy.get('[data-cy="restrictCommunityControls"]').contains('Access to Divine Dragon users only')
const warningMsg = 'Please note that once the restriction is enabled it cannot be lifted/disabled';
cy.get('[data-cy="restrictCommunityControls"]').contains(warningMsg).should('not.exist')
cy.get('[data-cy="restrictCommunity"] [data-pc-section="input"]').click()
cy.get('[data-cy="restrictCommunityControls"]').contains(warningMsg)

cy.intercept('POST', '/api/validation/description*').as('validateDescription');
cy.get('[data-cy="markdownEditorInput"]').type('ldkj aljdl aj\n\njabberwocky');
cy.wait('@validateDescription');
cy.get('[data-cy="descriptionError"]').should('not.be.visible')
cy.get('[data-cy="saveDialogBtn"]').should('be.enabled')

cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 0, value: 'For Divine Dragon Nation' }, { colIndex: 1, value: 'Quiz' }],
], 5);

cy.get('[data-cy="copyQuizButton_quiz2"]').click()
cy.get('[data-cy="quizName"]').should('have.value', 'Copy of Survey 1')

cy.get('[data-cy="restrictCommunityControls"]').contains('Access to Divine Dragon users only')
cy.get('[data-cy="restrictCommunityControls"]').contains(warningMsg).should('not.exist')
cy.get('[data-cy="restrictCommunity"] [data-pc-section="input"]').click()
cy.get('[data-cy="restrictCommunityControls"]').contains(warningMsg)

cy.get('[data-cy="saveDialogBtn"]').click()

cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 0, value: 'For Divine Dragon Nation' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Copy of Survey 1' }, { colIndex: 0, value: 'For Divine Dragon Nation' }, { colIndex: 1, value: 'Survey' }],
], 5);

cy.reload()
cy.validateTable(quizTableSelector, [
[{ colIndex: 0, value: 'Quiz 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Survey 1' }, { colIndex: 0, value: 'For All Dragons Nation' }, { colIndex: 1, value: 'Survey' }],
[{ colIndex: 0, value: 'Copy of Quiz 1' }, { colIndex: 0, value: 'For Divine Dragon Nation' }, { colIndex: 1, value: 'Quiz' }],
[{ colIndex: 0, value: 'Copy of Survey 1' }, { colIndex: 0, value: 'For Divine Dragon Nation' }, { colIndex: 1, value: 'Survey' }],
], 5);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ class ProjectCopyService {
ProjDef toProj = saveToProject(projectRequest)
saveProjectSettings(fromProject, toProj)

CustomValidationResult customValidationResult = customValidator.validate(projectRequest)
if (!customValidationResult.valid) {
throw new SkillException(customValidationResult.msg)
}

pinProjectForRootUser(toProj)

List<SkillInfo> allCollectedSkills = []
Expand Down Expand Up @@ -719,10 +724,6 @@ class ProjectCopyService {

@Profile
private void validate(ProjectRequest projectRequest) {
CustomValidationResult customValidationResult = customValidator.validate(projectRequest)
if (!customValidationResult.valid) {
throw new SkillException(customValidationResult.msg)
}
if (!userInfoService.isCurrentUserASuperDuperUser()){
createdResourceLimitsValidator.validateNumProjectsCreated(userInfoService.getCurrentUserId())
}
Expand Down
14 changes: 8 additions & 6 deletions service/src/main/java/skills/services/quiz/QuizDefService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import skills.auth.UserInfoService
import skills.controller.PublicPropsBasedValidator
import skills.controller.exceptions.ErrorCode
import skills.controller.exceptions.QuizValidator
import skills.controller.exceptions.SkillException
import skills.controller.exceptions.SkillQuizException
import skills.controller.request.model.ActionPatchRequest
import skills.controller.request.model.QuizAnswerDefRequest
import skills.controller.request.model.QuizDefRequest
import skills.controller.request.model.QuizQuestionDefRequest
import skills.controller.request.model.QuizSettingsRequest
import skills.controller.request.model.*
import skills.controller.result.model.*
import skills.quizLoading.QuizSettings
import skills.services.*
Expand Down Expand Up @@ -211,9 +208,14 @@ class QuizDefService {
))

copyQuestions(originalQuizId, newQuizId)
quizSettingsService.copySettings(originalQuizId, newQuizId)
quizSettingsService.copySettings(originalQuizId, newQuizId, quizDefRequest.enableProtectedUserCommunity)
accessSettingsStorageService.addQuizDefUserRoleForUser(userId, newQuizId, RoleName.ROLE_QUIZ_ADMIN)

CustomValidationResult customValidationResult = customValidator.validate(quizDefRequest)
if (!customValidationResult.valid) {
throw new SkillException(customValidationResult.msg)
}

QuizDef updatedDef = quizDefRepo.findByQuizIdIgnoreCase(quizDefWithDescription.quizId)
return convert(updatedDef)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import skills.auth.UserInfoService
import skills.controller.exceptions.ErrorCode
import skills.controller.exceptions.QuizValidator
import skills.controller.exceptions.SkillQuizException
import skills.controller.request.model.QuizDefRequest
import skills.controller.request.model.QuizPreference
import skills.controller.request.model.QuizSettingsRequest
import skills.controller.result.model.QuizPreferenceRes
Expand Down Expand Up @@ -69,10 +70,14 @@ class QuizSettingsService {
UserAttrsRepo userAttrsRepo

@Transactional
void copySettings(String fromQuizId, String toQuizId) {
void copySettings(String fromQuizId, String toQuizId, boolean enableProtectedUserCommunity) {
List<QuizSettingsRes> fromSettings = getSettings(fromQuizId)
List<QuizSettingsRequest> toSettings = new ArrayList<QuizSettingsRequest>()

if (enableProtectedUserCommunity) {
fromSettings = fromSettings.findAll { it.setting != QuizSettings.UserCommunityOnlyQuiz.setting }
toSettings.add(new QuizSettingsRequest(value: Boolean.TRUE.toString(), setting: QuizSettings.UserCommunityOnlyQuiz.setting))
}
fromSettings.forEach( setting -> {
QuizSettingsRequest request = new QuizSettingsRequest(value: setting.value, setting: setting.setting)
toSettings.add(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package skills.intTests.community

import skills.intTests.utils.DefaultIntSpec
import skills.intTests.utils.SkillsClientException
import skills.intTests.utils.SkillsFactory
import skills.intTests.utils.SkillsService

Expand Down Expand Up @@ -108,6 +109,105 @@ class CommunityAndProjectCopySpecs extends DefaultIntSpec {
originalProject.userCommunity == 'All Dragons'
}

def "enable protected community during copy and description has jabberwocky that's not allowed in non-uc projects"() {
List<String> users = getRandomUsers(2)

SkillsService pristineDragonsUser = createService(users[1])
SkillsService rootUser = createRootSkillService()
rootUser.saveUserTag(pristineDragonsUser.userName, 'dragons', ['DivineDragon'])

def p1 = createProject(1)
p1.description = "divinedragon is not allowed in uc projects"
def p1subj1 = createSubject(1, 1)
def p1Skills = createSkills(3, 1, 1, 100, 5)
pristineDragonsUser.createProjectAndSubjectAndSkills(p1, p1subj1, p1Skills)

def p2 = createProject(2)
def p2subj1 = createSubject(2, 1)
def p2Skills = createSkills(3, 2, 1, 100, 5)
pristineDragonsUser.createProjectAndSubjectAndSkills(p2, p2subj1, p2Skills)

when:
def newProj = SkillsFactory.createProject(50)
newProj.enableProtectedUserCommunity = true
newProj.description = "This is a jabberwocky description that is not allowed in non-uc projects"
pristineDragonsUser.copyProject(p1.projectId, newProj)
def copiedProject = pristineDragonsUser.getProject(newProj.projectId)
def originalProject = pristineDragonsUser.getProject(p1.projectId)
def copiedProjectDesc = pristineDragonsUser.getProjectDescription(newProj.projectId)
def origProjectDesc = pristineDragonsUser.getProjectDescription(p1.projectId)
then:
copiedProject.projectId == newProj.projectId
copiedProject.userCommunity == 'Divine Dragon'
copiedProjectDesc.description == "This is a jabberwocky description that is not allowed in non-uc projects"

originalProject.userCommunity == 'All Dragons'
origProjectDesc.description == "divinedragon is not allowed in uc projects"
}

def "enable protected community during copy and description has divinedragon that's not allowed in uc projects"() {
List<String> users = getRandomUsers(2)

SkillsService pristineDragonsUser = createService(users[1])
SkillsService rootUser = createRootSkillService()
rootUser.saveUserTag(pristineDragonsUser.userName, 'dragons', ['DivineDragon'])

def p1 = createProject(1)
p1.description = "divinedragon is not allowed in uc projects"
def p1subj1 = createSubject(1, 1)
def p1Skills = createSkills(3, 1, 1, 100, 5)
pristineDragonsUser.createProjectAndSubjectAndSkills(p1, p1subj1, p1Skills)

def p2 = createProject(2)
def p2subj1 = createSubject(2, 1)
def p2Skills = createSkills(3, 2, 1, 100, 5)
pristineDragonsUser.createProjectAndSubjectAndSkills(p2, p2subj1, p2Skills)

when:
def newProj = SkillsFactory.createProject(50)
newProj.enableProtectedUserCommunity = true
newProj.description = "divinedragon is not allowed in uc projects"
pristineDragonsUser.copyProject(p1.projectId, newProj)
then:
def exception = thrown(SkillsClientException)
exception.message.contains("May not contain divinedragon word")
}

def "keeping community disabled during copy and description has divinedragon that's not allowed in uc projects"() {
List<String> users = getRandomUsers(2)

SkillsService pristineDragonsUser = createService(users[1])
SkillsService rootUser = createRootSkillService()
rootUser.saveUserTag(pristineDragonsUser.userName, 'dragons', ['DivineDragon'])

def p1 = createProject(1)
p1.description = "divinedragon is not allowed in uc projects"
def p1subj1 = createSubject(1, 1)
def p1Skills = createSkills(3, 1, 1, 100, 5)
pristineDragonsUser.createProjectAndSubjectAndSkills(p1, p1subj1, p1Skills)

def p2 = createProject(2)
def p2subj1 = createSubject(2, 1)
def p2Skills = createSkills(3, 2, 1, 100, 5)
pristineDragonsUser.createProjectAndSubjectAndSkills(p2, p2subj1, p2Skills)

when:
def newProj = SkillsFactory.createProject(50)
newProj.description = "divinedragon is not allowed in uc projects"
pristineDragonsUser.copyProject(p1.projectId, newProj)
def copiedProject = pristineDragonsUser.getProject(newProj.projectId)
def originalProject = pristineDragonsUser.getProject(p1.projectId)
def copiedProjectDesc = pristineDragonsUser.getProjectDescription(newProj.projectId)
def origProjectDesc = pristineDragonsUser.getProjectDescription(p1.projectId)
then:
copiedProject.projectId == newProj.projectId
copiedProject.userCommunity == 'All Dragons'
copiedProjectDesc.description == "divinedragon is not allowed in uc projects"

originalProject.userCommunity == 'All Dragons'
origProjectDesc.description == "divinedragon is not allowed in uc projects"
}

def "copy non-protected community project"() {
List<String> users = getRandomUsers(2)

Expand Down
Loading

0 comments on commit 59601b5

Please sign in to comment.