diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-11-05 14:22:11 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-11-05 14:23:47 +0100 |
commit | 3df00fb97661f12dabe98cd9a279080e586e9c0d (patch) | |
tree | 2c0285918454c3a3bbd734b5c54a2d3e1dde5f5f /sonar-server | |
parent | 81b76d8b6cbc8cc685c57e42d7a9c5a8dfac2ab6 (diff) | |
download | sonarqube-3df00fb97661f12dabe98cd9a279080e586e9c0d.tar.gz sonarqube-3df00fb97661f12dabe98cd9a279080e586e9c0d.zip |
SONAR-3895 load settings from web service
Diffstat (limited to 'sonar-server')
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb | 40 | ||||
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/models/project.rb | 2 |
2 files changed, 31 insertions, 11 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb index 05bc74c95a3..a2b9885aaf2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb @@ -17,25 +17,45 @@ # License along with Sonar; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # - -require "json" - class Api::PropertiesController < Api::ApiController before_filter :admin_required, :only => [:create, :update, :destroy] - # curl http://localhost:9000/api/properties -v + # GET /api/properties/index?[resource=<resource id or key>] + # Does NOT manage default values. def index - properties = Property.find(:all, :conditions => ['resource_id is null and user_id is null']).select do |property| - viewable?(property.key) + keys=Set.new + properties=[] + + # project properties + if params[:resource] + resource=Project.by_key(params[:resource]) + if resource + # bottom-up projects + projects=[resource].concat(resource.ancestor_projects) + projects.each do |project| + Property.find(:all, :conditions => ['resource_id=? and user_id is null', project.id]).each do |prop| + properties<<prop if keys.add? prop.key + end + end + end end + + # global properties + Property.find(:all, :conditions => 'resource_id is null and user_id is null').each do |prop| + properties<<prop if keys.add? prop.key + end + + # apply security + properties = properties.select{|prop| allowed?(prop.key)} + respond_to do |format| format.json { render :json => jsonp(to_json(properties)) } format.xml { render :xml => to_xml(properties) } end end - # curl http://localhost:9000/api/properties/<key>[?resource=<resource>] -v + # GET /api/properties/<key>[?resource=<resource>] def show key = params[:id] resource_id_or_key = params[:resource] @@ -55,7 +75,7 @@ class Api::PropertiesController < Api::ApiController format.text { render :text => message, :status => 200 } end end - access_denied unless viewable?(key) + access_denied unless allowed?(key) respond_to do |format| format.json { render :json => jsonp(to_json([prop])) } format.xml { render :xml => to_xml([prop]) } @@ -122,8 +142,8 @@ class Api::PropertiesController < Api::ApiController end end - def viewable?(property_key) - !property_key.to_s.index('.secured') || is_admin? + def allowed?(property_key) + !property_key.end_with?('.secured') || is_admin? end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb index 4acf953c17c..902ad57de75 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb @@ -131,7 +131,7 @@ class Project < ActiveRecord::Base ' from project_measures m, snapshots s ' + ' where s.id=m.snapshot_id and ' + " s.status='%s' and " + - ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id]) + + ' s.project_id=%s and m.metric_id=%s ', 'P', self.id, metric_id]) + ' and m.rule_id IS NULL and m.rule_priority IS NULL' + ' and m.person_id IS NULL' + ' order by s.created_at' |