]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3287 Add "modifiable_history" property on ResourceType
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 30 Mar 2012 13:47:42 +0000 (15:47 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Fri, 30 Mar 2012 13:54:28 +0000 (15:54 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/history.html.erb

index c03e994f470a4dc33b7c444de10bf0a1d88b766c..bf2632f271fed7b644c9cfd17cb514477945c770 100644 (file)
@@ -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())
index 28ea72edd236b740427f4dfa1a186648e35e5fe2..47692382715cf3004b8810d5a3972d17e6cd2f25 100644 (file)
@@ -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
index 9249f275cad30cbcda058b48eda0b3d7ace650c3..29cbb2287dde229305a140d712c6d36716031cd5 100644 (file)
@@ -41,6 +41,7 @@ import com.google.common.collect.Maps;
  * <ul>
  *   <li>"deletable": if set to "true", then this resource can be deleted/purged.</li>
  *   <li>"availableForFilters": if set to "true", then this resource can be displayed in the filters results</li>
+ *   <li>"modifiable_history": if set to "true", then the history of this resource may be modified (deletion of snapshots, modification of events, ...)</li>
  * </ul>
  *
  * @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<String, String> 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) {
index b6f6d7917ffe2556159b8cb781231b1f0f711b8e..69d70119bf6fde8f706d56694fa37bfaf70475eb 100644 (file)
@@ -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
 
index 6c185e58ea85a3fd9994a09904adde0218541e46..45cb68609fdae0be3153285c62030774ec0c06a9 100644 (file)
               <% if (@project.project? || @project.view? || @project.subview?) %>
                 <li class="<%= 'selected' if request.request_uri.include?('/project_roles') -%>">
                   <a href="<%= ApplicationController.root_context -%>/project_roles/index?resource=<%= @project.id -%>"><%= message('project_roles.page') -%></a></li>
+              <% 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?) 
+              %>
                 <li class="<%= 'selected' if request.request_uri.include?('/project/history') -%>">
                   <a href="<%= ApplicationController.root_context -%>/project/history/<%= @project.id -%>"><%= message('project_history.page') -%></a></li>
               <% end %>
index 5f019607b5505f674e93d122f2a499a60b9b9b23..0099ef7c69d8f12f9240ec0858772caa62c183bd 100644 (file)
@@ -16,7 +16,7 @@
 }
 </style>
 
-<h1><%= message('project_history.page_title') -%></h1>
+<h1><%= message('project_history.top_title') -%></h1>
 <br/>
 
 <table id="project-history" class="data" style="width:1%">