From 200e64a11755433724aadcb8a8bd9aad38163b0b Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Fri, 30 Mar 2012 15:47:42 +0200 Subject: [PATCH] SONAR-3287 Add "modifiable_history" property on ResourceType --- .../plugins/core/DefaultResourceTypes.java | 5 ++- .../resources/org/sonar/l10n/core.properties | 2 +- .../org/sonar/api/resources/ResourceType.java | 42 ++++++++++++++++++- .../app/controllers/project_controller.rb | 3 +- .../app/views/layouts/_layout.html.erb | 5 +++ .../app/views/project/history.html.erb | 2 +- 6 files changed, 54 insertions(+), 5 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java index c03e994f470..bf2632f271f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java @@ -34,7 +34,10 @@ public final class DefaultResourceTypes extends ExtensionProvider implements Bat public ResourceTypeTree provide() { return ResourceTypeTree.builder() - .addType(ResourceType.builder(Qualifiers.PROJECT).setProperty("deletable", "true").build()) + .addType(ResourceType.builder(Qualifiers.PROJECT) + .setProperty("deletable", "true") + .setProperty("modifiable_history", "true") + .build()) .addType(ResourceType.builder(Qualifiers.MODULE).build()) .addType(ResourceType.builder(Qualifiers.DIRECTORY).build()) .addType(ResourceType.builder(Qualifiers.PACKAGE).build()) diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index 28ea72edd23..47692382715 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -884,7 +884,7 @@ manual_rules.should_provide_real_description=Rule created on the fly. A descript # #------------------------------------------------------------------------------ -project_history.page_title=Handle events and delete quality snapshots from project history +project_history.top_title=Handle events and delete quality snapshots from history project_history.col.year=Year project_history.col.month=Month project_history.col.day=Day diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java index 9249f275cad..29cbb2287dd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java @@ -41,6 +41,7 @@ import com.google.common.collect.Maps; * * * @since 2.14 @@ -49,17 +50,26 @@ import com.google.common.collect.Maps; @Immutable public final class ResourceType { + /** + * Builder used to create {@link ResourceType} objects. + */ public static class Builder { private String qualifier; private String iconPath; private boolean hasSourceCode = false; private Map properties = Maps.newHashMap(); + /** + * Creates a new {@link Builder} + * @param qualifier + */ public Builder(String qualifier) { this.qualifier = qualifier; } /** + * Relative path of the icon used to represent the resource type. + * * @param iconPath path to icon, relative to context of web-application (e.g. "/images/q/DIR.png") */ public Builder setIconPath(@Nullable String iconPath) { @@ -76,12 +86,17 @@ public final class ResourceType { return this; } + /** + * Tells that the resources of this type will have source code. + */ public Builder hasSourceCode() { this.hasSourceCode = true; return this; } /** + * Sets a property on the resource type. See the description of {@link ResourceType} class for more information. + * * @since 2.15 */ public Builder setProperty(String key, String value) { @@ -91,6 +106,9 @@ public final class ResourceType { return this; } + /** + * Creates an instance of {@link ResourceType} based on all information given to the builder. + */ public ResourceType build() { if (Strings.isNullOrEmpty(iconPath)) { iconPath = "/images/q/" + qualifier + ".png"; @@ -99,6 +117,10 @@ public final class ResourceType { } } + /** + * Creates a new {@link Builder} + * @param qualifier + */ public static Builder builder(String qualifier) { Preconditions.checkNotNull(qualifier); Preconditions.checkArgument(qualifier.length() <= 10, "Qualifier is limited to 10 characters"); @@ -118,12 +140,19 @@ public final class ResourceType { } /** - * Qualifier is the unique key + * Qualifier is the unique key. + * + * @return the qualifier */ public String getQualifier() { return qualifier; } + /** + * Returns the relative path of the icon used to represent the resource type + * + * @return the relative path. + */ public String getIconPath() { return iconPath; } @@ -137,11 +166,19 @@ public final class ResourceType { return availableForFilters == null ? false : availableForFilters.booleanValue(); } + /** + * Tells whether resources of this type has source code or not. + * + * @return true if the type has source code + */ public boolean hasSourceCode() { return hasSourceCode; } /** + * Returns the value of the property for this resource type. + * + * @return the String value of the property, or NULL if the property hasn't been set. * @since 2.15 */ public String getStringProperty(String key) { @@ -150,6 +187,9 @@ public final class ResourceType { } /** + * Returns the value of the property for this resource type. + * + * @return the Boolean value of the property. If the property hasn't been set, False is returned. * @since 2.15 */ public Boolean getBooleanProperty(String key) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index b6f6d7917ff..69d70119bf6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -54,7 +54,8 @@ class ProjectController < ApplicationController not_found("Project not found") unless @project access_denied unless is_admin?(@project) - if !(@project.project? || @project.view? || @project.subview?) + # NOTE: we keep "@project.view? || @project.subview?" in the test for backward compatibility with the Views plugin + unless java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'modifiable_history') || @project.view? || @project.subview? redirect_to :action => 'index', :id => params[:id] end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index 6c185e58ea8..45cb68609fd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -89,6 +89,11 @@ <% if (@project.project? || @project.view? || @project.subview?) %>
  • <%= message('project_roles.page') -%>
  • + <% end %> + <% + # NOTE: we keep "@project.view? || @project.subview?" in the test for backward compatibility with the Views plugin + if (controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'modifiable_history') || @project.view? || @project.subview?) + %>
  • <%= message('project_history.page') -%>
  • <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb index 5f019607b55..0099ef7c69d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb @@ -16,7 +16,7 @@ } -

    <%= message('project_history.page_title') -%>

    +

    <%= message('project_history.top_title') -%>


    -- 2.39.5