public void setConfigAttributes(Object attributes) { Map attributeMap = (Map) attributes; if (attributeMap.containsKey(NAME)) { String strName = (String) attributeMap.get(NAME); name = new CaseInsensitiveString(strName); } if (attributeMap.containsKey(AUTHORIZATION)) { this.authorization = new Authorization(); this.authorization.setConfigAttributes(attributeMap.get(AUTHORIZATION)); } else { this.authorization = new Authorization(); } if (attributeMap.containsKey(ALLOW_GROUP_ADMINS)) { this.authorization.setAllowGroupAdmins("true".equals(attributeMap.get(ALLOW_GROUP_ADMINS))); } }
@Test public void shouldReturnFalseIfGroupAdminCanViewTemplate() { CaseInsensitiveString templateViewUser = new CaseInsensitiveString("view"); String templateName = "template"; PipelineTemplateConfig template = PipelineTemplateConfigMother.createTemplate(templateName, StageConfigMother.manualStage("stage")); template.getAuthorization().setAllowGroupAdmins(false); TemplatesConfig templates = new TemplatesConfig(template); assertThat(templates.hasViewAccessToTemplate(template, templateViewUser, null, true), is(false)); }
@Test public void shouldDisplayTheFlagInXmlIfTemplateAuthorizationDoesNotAllowGroupAdmins() throws Exception { CruiseConfig cruiseConfig = new BasicCruiseConfig(); PipelineTemplateConfig template = com.thoughtworks.go.helper.PipelineTemplateConfigMother.createTemplate("template-name", new Authorization(new AdminsConfig()), com.thoughtworks.go.helper.StageConfigMother.manualStage("stage-name")); template.getAuthorization().setAllowGroupAdmins(false); cruiseConfig.addTemplate(template); xmlWriter.write(cruiseConfig, output, false); String writtenConfigXml = this.output.toString(); assertThat(writtenConfigXml, containsString("allGroupAdminsAreViewers")); }