package org.sonar.server.ui.ws;
import com.google.common.base.Charsets;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import org.sonar.api.ServerComponent;
import org.sonar.api.i18n.I18n;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypes;
-import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.UserRole;
import org.sonar.core.component.ComponentDto;
import org.sonar.server.user.UserSession;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.util.Collection;
import java.util.List;
import java.util.Locale;
this.resourceTypes = resourceTypes;
}
- List<ConfigPage> getConfigPages(ComponentDto component, UserSession userSession) {
+ Collection<ConfigPage> getConfigPages(ComponentDto component, UserSession userSession) {
boolean isAdmin = userSession.hasProjectPermissionByUuid(UserRole.ADMIN, component.projectUuid());
boolean isProject = Qualifiers.PROJECT.equals(component.qualifier());
Locale locale = userSession.locale();
configPages.add(new ConfigPage(
isAdmin && isProject,
String.format("/project/links?id=%s", componentKey),
- i18n.message(locale, "action_plans.page", null)));
+ i18n.message(locale, "project_links.page", null)));
configPages.add(new ConfigPage(
componentTypeHasProperty(component, PROPERTY_HAS_ROLE_POLICY),
String.format("/project/deletion?id=%s", componentKey),
i18n.message(locale, "deletion.page", null)));
- return configPages;
+ return Collections2.filter(configPages, new Predicate<ConfigPage>() {
+ @Override
+ public boolean apply(ConfigPage input) {
+ return input.visible;
+ }
+ });
}
static String encodeComponentKey(ComponentDto component) {
this.name = name;
}
- void write(JsonWriter json) {
- if (visible) {
- json.beginObject()
- .prop("url", url)
- .prop("name", name)
- .endObject();
- }
+ String url() {
+ return url;
+ }
+
+ String name() {
+ return name;
}
}
import org.sonar.server.user.MockUserSession;
import org.sonar.server.user.UserSession;
-import java.util.List;
+import java.util.Collection;
import java.util.Locale;
import static org.assertj.core.api.Assertions.assertThat;
ComponentDto component = ComponentTesting.newProjectDto(uuid).setKey("org.codehaus.sonar:sonar");
UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.ADMIN, uuid);
- List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
- assertThat(pages).extracting("visible").containsExactly(
- false, true, true, true, true, true, false, false, false, false);
+ Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
+ assertThat(pages).extracting("name").containsExactly(
+ "project_quality_profiles.page",
+ "project_quality_gate.page",
+ "manual_measures.page",
+ "action_plans.page",
+ "project_links.page"
+ );
assertThat(pages).extracting("url").containsExactly(
- "/project/settings?id=org.codehaus.sonar%3Asonar",
"/project/profile?id=org.codehaus.sonar%3Asonar",
"/project/qualitygate?id=org.codehaus.sonar%3Asonar",
"/manual_measures/index?id=org.codehaus.sonar%3Asonar",
"/action_plans/index?id=org.codehaus.sonar%3Asonar",
- "/project/links?id=org.codehaus.sonar%3Asonar",
- "/project_roles/index?id=org.codehaus.sonar%3Asonar",
- "/project/history?id=org.codehaus.sonar%3Asonar",
- "/project/key?id=org.codehaus.sonar%3Asonar",
- "/project/deletion?id=org.codehaus.sonar%3Asonar"
+ "/project/links?id=org.codehaus.sonar%3Asonar"
);
}
when(resourceTypes.get(component.qualifier())).thenReturn(
ResourceType.builder(component.qualifier()).setProperty("configurable", true).build());
- List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
- assertThat(pages).extracting("visible").containsExactly(
- true, true, true, true, true, true, false, false, false, false);
+ Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
+ assertThat(pages).extracting("name").containsExactly(
+ "project_settings.page",
+ "project_quality_profiles.page",
+ "project_quality_gate.page",
+ "manual_measures.page",
+ "action_plans.page",
+ "project_links.page"
+ );
}
@Test
ComponentDto module = ComponentTesting.newModuleDto(project);
UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.ADMIN, uuid);
- List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(module, userSession);
- assertThat(pages).extracting("visible").containsExactly(
- false, false, false, true, false, false, false, false, false, false);
+ Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(module, userSession);
+ assertThat(pages).extracting("name").containsExactly("manual_measures.page");
}
@Test
ComponentDto project = ComponentTesting.newProjectDto(uuid);
UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.USER, uuid);
- List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(project, userSession);
- assertThat(pages).extracting("visible").containsExactly(
- false, true, true, false, false, false, false, false, false, false);
+ Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(project, userSession);
+ assertThat(pages).extracting("name").containsExactly(
+ "project_quality_profiles.page",
+ "project_quality_gate.page"
+ );
+ }
+
+ @Test
+ public void pages_for_project_with_all_resource_type_properties() throws Exception {
+ String uuid = "abcd";
+ ComponentDto component = ComponentTesting.newProjectDto(uuid);
+ UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.ADMIN, uuid);
+ when(resourceTypes.get(component.qualifier())).thenReturn(
+ ResourceType.builder(component.qualifier())
+ .setProperty("configurable", true)
+ .setProperty("hasRolePolicy", true)
+ .setProperty("modifiable_history", true)
+ .setProperty("updatable_key", true)
+ .setProperty("deletable", true)
+ .build());
+
+ Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
+ assertThat(pages).extracting("name").containsExactly(
+ "project_settings.page",
+ "project_quality_profiles.page",
+ "project_quality_gate.page",
+ "manual_measures.page",
+ "action_plans.page",
+ "project_links.page",
+ "permissions.page",
+ "project_history.page",
+ "update_key.page",
+ "deletion.page"
+ );
}
}