summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb53
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb5
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_favourite.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb40
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb64
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb11
11 files changed, 127 insertions, 69 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java
index f81086d5c86..010ae4e9e8a 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java
@@ -58,13 +58,13 @@ public class MeasureFilterFactory implements ServerComponent {
filter.setResourceKeyRegexp((String) properties.get("keyRegexp"));
if (properties.containsKey("fromDate")) {
filter.setFromDate(toDate((String) properties.get("fromDate")));
- } else if (properties.containsKey("afterDays")) {
- filter.setFromDate(toDays((String) properties.get("afterDays")));
+ } else if (properties.containsKey("ageMaxDays")) {
+ filter.setFromDate(toDays((String) properties.get("ageMaxDays")));
}
if (properties.containsKey("toDate")) {
filter.setToDate(toDate((String) properties.get("toDate")));
- } else if (properties.containsKey("beforeDays")) {
- filter.setToDate(toDays((String) properties.get("beforeDays")));
+ } else if (properties.containsKey("ageMinDays")) {
+ filter.setToDate(toDays((String) properties.get("ageMinDays")));
}
if (properties.containsKey("onFavourites")) {
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
index ffe8afd23fd..19c5c8b8f1a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
@@ -93,7 +93,7 @@ class MeasuresController < ApplicationController
add_breadcrumbs(ROOT_BREADCRUMB, message('measure_filter.manage'))
@shared_filters = MeasureFilter.find(:all,
:include => :user,
- :conditions => ['shared=? and user_id<>?', true, current_user.id])
+ :conditions => ['shared=? and (user_id is null or user_id<>?)', true, current_user.id])
Api::Utils.insensitive_sort!(@shared_filters) { |elt| elt.name }
@fav_filter_ids = current_user.measure_filter_favourites.map { |fav| fav.measure_filter_id }
end
@@ -145,6 +145,7 @@ class MeasuresController < ApplicationController
@filter.data = to_clone.data
@filter.shared = false
if @filter.save
+ current_user.favourited_measure_filters << @filter
render :text => @filter.id.to_s, :status => 200
else
render :partial => 'measures/copy_form', :status => 400
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
index 9095a567eec..85ad47178fe 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
@@ -104,12 +104,26 @@ class MeasureFilter < ActiveRecord::Base
def criteria=(hash)
@criteria = {}
hash.each_pair do |k, v|
- if k && v && !v.empty? && v!=['']
- @criteria[k.to_s]=v
+ set_criteria_value(k, v)
+ end
+ end
+
+ # API used by Displays
+ def set_criteria_value(key, value)
+ if key
+ if value && !value.empty? && value!=['']
+ @criteria[key.to_s]=value
+ else
+ @criteria.delete(key)
end
end
end
+ # API used by Displays
+ def set_criteria_default_value(key, value)
+ set_criteria_value(key, value) unless criteria.has_key?(key)
+ end
+
def load_criteria_from_data
if self.data
@criteria = self.data.split(CRITERIA_SEPARATOR).inject({}) do |h, s|
@@ -140,6 +154,14 @@ class MeasureFilter < ActiveRecord::Base
set_criteria_default_value('display', 'list')
end
+ def base_resource
+ if criteria('base')
+ Project.find(:first, :conditions => ['kee=? and copy_resource_id is null and person_id is null', criteria('base')])
+ elsif criteria('baseId')
+ Project.find(criteria('baseId'))
+ end
+ end
+
# ==== Options
# :user : the authenticated user
def execute(controller, options={})
@@ -152,31 +174,6 @@ class MeasureFilter < ActiveRecord::Base
self
end
- # API used by Displays
- def set_criteria_value(key, value)
- if value
- @criteria[key.to_s]=value
- else
- @criteria.delete(key)
- end
- end
-
- # API used by Displays
- def set_criteria_default_value(key, value)
- set_criteria_value(key, value) unless criteria.has_key?(key)
- end
-
- def url_params
- criteria.merge({'id' => self.id})
- end
-
- def base_resource
- if criteria('base')
- Project.find(:first, :conditions => ['kee=? and copy_resource_id is null and person_id is null', criteria('base')])
- elsif criteria('baseId')
- Project.find(criteria('baseId'))
- end
- end
private
@@ -272,7 +269,5 @@ class MeasureFilter < ActiveRecord::Base
count = MeasureFilter.count('id', :conditions => ['name=? and shared=? and user_id!=?', name, true, user_id])
errors.add_to_base('Other users already shared filters with the same name') if count>0
end
-
- errors.add_to_base('Only shared filters can be flagged as system filter') if system && !shared
end
end \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb
index ed5c8f714be..62270fbfe0e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_display.rb
@@ -40,6 +40,11 @@ class MeasureFilterDisplay
def initialize(filter, options)
@filter = filter
@options = options
+
+ if filter.base_resource
+ qualifiers = filter.criteria('qualifiers')
+ filter.set_criteria_value('onBaseComponents', 'true') unless qualifiers && !qualifiers.empty?
+ end
end
# sorted array of parameters :
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_favourite.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_favourite.rb
index 8bfd80e9be1..0f7717e439e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_favourite.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter_favourite.rb
@@ -20,4 +20,6 @@
class MeasureFilterFavourite < ActiveRecord::Base
belongs_to :user
belongs_to :measure_filter
+
+ validates_uniqueness_of :measure_filter_id, :scope => :user_id
end \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb
index 85cc0ee3fbf..68eef6d414c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb
@@ -24,6 +24,8 @@
</fieldset>
</form>
<script>
- $j("#copy-filter-form").modalForm();
+ $j("#copy-filter-form").modalForm({success:function (data) {
+ window.location = baseUrl + '/measures/filter/' + data;
+ }});
$j('#name').select();
</script> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
index 01010c6562e..31f57645f72 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_display_list.html.erb
@@ -78,7 +78,7 @@
<% end %>
</select>
- <button id="add-metric">Add</button>
+ <button id="add-metric">Add Column</button>
</td>
<td class="right">
<a href="#" class="button" id="exit-edit">Done</a>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb
index 373ddf45969..f3f23198291 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb
@@ -23,7 +23,7 @@
</script>
<% end %>
-<h2>My Measure Filters</h2>
+<h2>My Filters</h2>
<table class="data marginbottom10" id="my-filters">
<thead>
<tr>
@@ -78,7 +78,7 @@
<br/>
-<h2>Shared Measure Filters</h2>
+<h2>Shared Filters</h2>
<table class="data" id="shared-filters">
<thead>
<tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
index eb0ab93c6a6..919befc0e86 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
@@ -56,9 +56,7 @@
if (e.val == 'lang') {
$j("#select-" + e.val).select2("enable");
$j("#select-" + e.val).select2("focus");
- }
- $j("#more-criteria").select2("val", "");
- if (e.val == 'metric') {
+ } else if (e.val == 'metric') {
if (hiddenConditionIndexes.length > 0) {
var index = hiddenConditionIndexes.pop();
$j("#criteria-metric-" + index).insertBefore($j("#more-td")).show();
@@ -70,6 +68,7 @@
} else {
$j("#more-criteria option[value='" + e.val + "']").remove();
}
+ $j("#more-criteria").select2("val", "");
});
});
</script>
@@ -117,9 +116,9 @@
<tr>
<td>
<%
- qualifiers = [['Components', 'components']].concat(Api::Utils.java_facade.getResourceTypesForFilter().map do |resource_type|
+ qualifiers = Api::Utils.java_facade.getResourceTypesForFilter().map do |resource_type|
[message("qualifiers.#{resource_type.getQualifier()}"), resource_type.getQualifier()]
- end)
+ end
%>
<%= select_tag 'qualifiers[]', options_for_select(qualifiers, @filter.criteria['qualifiers']||''), :multiple => true, :id => 'select-qualifiers' -%>
</td>
@@ -169,12 +168,12 @@
<span class="note">year-month-day (2012-01-31)</span>
</td>
</tr>
- <tr id="criteria-age" <%= "style='display:none'" unless @filter.criteria('beforeDays') || @filter.criteria('afterDays') -%>>
+ <tr id="criteria-age" <%= "style='display:none'" unless @filter.criteria('ageMinDays') || @filter.criteria('ageMaxDays') -%>>
<td>
More than
- <input type="text" name="beforeDays" value="<%= @filter.criteria['beforeDays'] -%>" size="3"> days ago
+ <input type="text" name="ageMinDays" value="<%= @filter.criteria['ageMinDays'] -%>" size="3"> days ago
<br>Within the last
- <input type="text" name="afterDays" value="<%= @filter.criteria['afterDays'] -%>" size="3"> days
+ <input type="text" name="ageMaxDays" value="<%= @filter.criteria['ageMaxDays'] -%>" size="3"> days
</td>
</tr>
<tr id="more-td">
@@ -195,7 +194,19 @@
<tr>
<td>
<input type="button" name="search" value="<%= message('search_verb') -%>" onclick="submitSearch()">
- <a href="<%= ApplicationController.root_context -%>/measures">New search</a>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <a href="<%= ApplicationController.root_context -%>/measures" class="link-action">New search</a>
+ <% if logged_in? %>
+ <% if @filter.id==nil || @filter.user_id==current_user.id %>
+ - <a id="save" href="<%= url_for params.merge({:action => 'save_form', :id => @filter.id}) -%>" class="link-action open-modal"><%= message('save') -%></a>
+ <% end %>
+ <% if @filter.id %>
+ - <a id="copy" href="<%= url_for params.merge({:action => 'copy_form', :id => @filter.id}) -%>" class="link-action open-modal"><%= message('copy') -%></a>
+ <% end %>
+ <% end %>
</td>
</tr>
</tbody>
@@ -229,15 +240,8 @@
<% end %>
<td class="right">
<a id="edit" href="<%= url_for params.merge({:edit => true, :id => @filter.id}) -%>" class="button"><%= message('configure') -%></a>
- <% if logged_in? %>
- <% if @filter.id==nil || @filter.user_id==current_user.id %>
- <a id="save" href="<%= url_for params.merge({:action => 'save_form', :id => @filter.id}) -%>" class="button open-modal"><%= message('save') -%></a>
- <% end %>
- <% if @filter.id %>
- <a id="copy" href="<%= url_for params.merge({:action => 'copy_form', :id => @filter.id}) -%>" class="button open-modal"><%= message('copy') -%></a>
- <% end %>
- <% end %>
- </tr>
+ </td>
+ </tr>
</table>
<% end %>
<% if @filter.security_exclusions %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb
index de458816e19..6296e5a4dc9 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb
@@ -64,15 +64,26 @@ class MoveExistingMeasureFilters < ActiveRecord::Migration
data << "pageSize=#{old_filter.page_size}" if old_filter.page_size
data << "display=#{old_filter.default_view || 'list'}"
+ move_columns(old_filter, data)
+ move_criteria(old_filter, data)
+
+ new_filter.data = data.join('|') unless data.empty?
+ new_filter.save
+ # TODO Filter.delete(old_filter.id)
+ end
+
+ def self.move_columns(old_filter, data)
columns = []
asc = nil
sort = nil
old_columns = FilterColumn.find(:all, :conditions => ['filter_id=?', old_filter.id], :order => 'order_index')
old_columns.each do |old_column|
column_key = old_column.family
- column_key += ":#{old_column.kee}" if old_column.kee
- columns << column_key
- # TODO old_column.variation
+ if old_column.kee
+ column_key += ":#{old_column.kee}"
+ column_key += ":#{old_filter.period_index}" if old_column.variation && old_filter.period_index
+ columns << column_key
+ end
if old_column.sort_direction=='ASC'
asc = true
sort = column_key
@@ -86,11 +97,50 @@ class MoveExistingMeasureFilters < ActiveRecord::Migration
data << "sort=#{sort}"
data << "asc=#{asc}"
end
+ end
- # TODO move criteria
+ def self.move_criteria(old_filter, data)
+ old_criteria = Criteria.find(:all, :conditions => ['filter_id=?', old_filter.id])
+ metric_criteria_id=1
- new_filter.data = data.join('|') unless data.empty?
- new_filter.save
- # TODO Filter.delete(old_filter.id)
+ old_criteria.each do |old|
+ if old.family=='qualifier' && old.text_value
+ data << "qualifiers=#{old.text_value}"
+ elsif old.family=='name' && old.text_value
+ data << "nameSearch=#{old.text_value}"
+ elsif old.family=='key' && old.text_value
+ data << "keyRegexp=#{old.text_value}"
+ elsif old.family=='language' && old.text_value
+ data << "languages=#{old.text_value}"
+ elsif old.family=='date' && old.value && old.operator
+ data << "ageMaxDays=#{old.value}" if old.operator=='<'
+ data << "ageMinDays=#{old.value}" if old.operator=='>'
+ elsif old.family=='metric' && old.kee && old.operator && old.value
+ data << "c#{metric_criteria_id}_metric=#{old.kee}"
+ data << "c#{metric_criteria_id}_op=#{operator_code(old.operator)}"
+ data << "c#{metric_criteria_id}_val=#{old.value}"
+ data << "c#{metric_criteria_id}_period=#{old.period}" if old.period
+ metric_criteria_id += 1
+ elsif old.family=='direct-children' && op.text_value=='true'
+ data << "onBaseComponents=true"
+ end
+ end
+ end
+
+ def self.operator_code(old_operator)
+ case old_operator
+ when '='
+ 'eq'
+ when '<'
+ 'lt'
+ when '<='
+ 'lte'
+ when '>'
+ 'gt'
+ when '>='
+ 'gte'
+ else
+ 'eq'
+ end
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb b/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb
index 7e3ffd3a7e0..49a54905598 100644
--- a/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb
@@ -45,7 +45,7 @@ class PluginRealm
@java_authenticator = java_realm.doGetAuthenticator()
@java_users_provider = java_realm.getUsersProvider()
@java_groups_provider = java_realm.getGroupsProvider()
- @save_password = Java::OrgSonarServerUi::JRubyFacade.new.getSettings().getBoolean('sonar.security.savePassword')
+ @save_password = Api::Utils.java_facade.new.getSettings().getBoolean('sonar.security.savePassword')
end
def authenticate?(username, password, servlet_request)
@@ -113,11 +113,10 @@ class PluginRealm
user = User.find_by_login(username)
if !user
# No such user in Sonar database
- java_facade = Java::OrgSonarServerUi::JRubyFacade.new
- return nil if !java_facade.getSettings().getBoolean('sonar.authenticator.createUsers')
+ return nil if !Api::Utils.java_facade.getSettings().getBoolean('sonar.authenticator.createUsers')
# Automatically create a user in the sonar db if authentication has been successfully done
user = User.new(:login => username, :name => username, :email => '')
- default_group_name = java_facade.getSettings().getString('sonar.defaultGroup')
+ default_group_name = Api::Utils.java_facade.getSettings().getString('sonar.defaultGroup')
default_group = Group.find_by_name(default_group_name)
if default_group
user.groups << default_group
@@ -174,7 +173,7 @@ class RealmFactory
def self.realm
if @@realm.nil?
- realm_factory = Java::OrgSonarServerUi::JRubyFacade.new.getCoreComponentByClassname('org.sonar.server.ui.SecurityRealmFactory')
+ realm_factory = Api::Utils.java_facade.getCoreComponentByClassname('org.sonar.server.ui.SecurityRealmFactory')
component = realm_factory.getRealm()
@@realm = component ? PluginRealm.new(component) : DefaultRealm.new
end
@@ -203,7 +202,7 @@ module NeedAuthentication
def authenticate(login, password, servlet_request)
# Downcase login (typically for Active Directory)
# Note that login in Sonar DB is case-sensitive, however in this case authentication and automatic user creation will always happen with downcase login
- downcase = Java::OrgSonarServerUi::JRubyFacade.new.getSettings().getBoolean('sonar.authenticator.downcase')
+ downcase = Api::Utils.java_facade.getSettings().getBoolean('sonar.authenticator.downcase')
if login && downcase
login = login.downcase
end