aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-12-22 15:27:20 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-12-22 15:27:20 +0100
commit7ea21fd06a448b1a38a0f8b262b600e6f6fb29fa (patch)
tree5c101d9f2fa335ac9560486e1d27a1b9ad682bd3 /server/sonar-web/src
parent5398d3b52002a9285b2fc6e5588036aae7d228fa (diff)
downloadsonarqube-7ea21fd06a448b1a38a0f8b262b600e6f6fb29fa.tar.gz
sonarqube-7ea21fd06a448b1a38a0f8b262b600e6f6fb29fa.zip
SSF-25 SMTP configuration password
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb37
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb10
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb47
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb3
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb4
5 files changed, 64 insertions, 37 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb
index 33b8600e4c5..6f1f4ef36d6 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb
@@ -23,27 +23,28 @@ class EmailConfigurationController < ApplicationController
before_filter :admin_required
def index
- @smtp_host = Property.value(configuration::SMTP_HOST, nil, configuration::SMTP_HOST_DEFAULT)
- @smtp_port = Property.value(configuration::SMTP_PORT, nil, configuration::SMTP_PORT_DEFAULT)
- @smtp_secure_connection = Property.value(configuration::SMTP_SECURE_CONNECTION, nil, configuration::SMTP_SECURE_CONNECTION)
- @smtp_username = Property.value(configuration::SMTP_USERNAME, nil, configuration::SMTP_USERNAME_DEFAULT)
- @smtp_password = Property.value(configuration::SMTP_PASSWORD, nil, configuration::SMTP_PASSWORD_DEFAULT)
- @email_from = Property.value(configuration::FROM, nil, configuration::FROM_DEFAULT)
- @email_prefix = Property.value(configuration::PREFIX, nil, configuration::PREFIX_DEFAULT)
- @server_base_url = Property.value(properties::SERVER_BASE_URL, nil, properties::SERVER_BASE_URL_DEFAULT_VALUE)
- params[:layout]='false'
+ @smtp_host = Property.value(configuration::SMTP_HOST, nil, configuration::SMTP_HOST_DEFAULT)
+ @smtp_port = Property.value(configuration::SMTP_PORT, nil, configuration::SMTP_PORT_DEFAULT)
+ @smtp_secure_connection = Property.value(configuration::SMTP_SECURE_CONNECTION, nil, configuration::SMTP_SECURE_CONNECTION)
+ @smtp_username = Property.value(configuration::SMTP_USERNAME, nil, configuration::SMTP_USERNAME_DEFAULT)
+ @smtp_password = Property.value(configuration::SMTP_PASSWORD, nil, configuration::SMTP_PASSWORD_DEFAULT)
+ @email_from = Property.value(configuration::FROM, nil, configuration::FROM_DEFAULT)
+ @email_prefix = Property.value(configuration::PREFIX, nil, configuration::PREFIX_DEFAULT)
+ @server_base_url = Property.value(properties::SERVER_BASE_URL, nil, properties::SERVER_BASE_URL_DEFAULT_VALUE)
+ params[:layout]='false'
end
def save
- Property.set(configuration::SMTP_HOST, params[:smtp_host])
- Property.set(configuration::SMTP_PORT, params[:smtp_port])
- Property.set(configuration::SMTP_SECURE_CONNECTION, params[:smtp_secure_connection])
- Property.set(configuration::SMTP_USERNAME, params[:smtp_username])
- Property.set(configuration::SMTP_PASSWORD, params[:smtp_password])
- Property.set(configuration::FROM, params[:email_from])
- Property.set(configuration::PREFIX, params[:email_prefix])
- flash[:notice] = message('email_configuration.settings_saved')
- redirect_to :action => 'index'
+ Property.set(configuration::SMTP_HOST, params[:smtp_host])
+ Property.set(configuration::SMTP_PORT, params[:smtp_port])
+ Property.set(configuration::SMTP_SECURE_CONNECTION, params[:smtp_secure_connection])
+ Property.set(configuration::SMTP_USERNAME, params[:smtp_username])
+ # Do not update password that wasn't updated
+ Property.set(configuration::SMTP_PASSWORD, params[:smtp_password]) unless params[:smtp_password] == Property::EXISTING_PASSWORD
+ Property.set(configuration::FROM, params[:email_from])
+ Property.set(configuration::PREFIX, params[:email_prefix])
+ flash[:notice] = message('email_configuration.settings_saved')
+ redirect_to :action => 'index'
end
def send_test_email
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
index 5a48b659558..e5bdc3f0c4f 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
@@ -80,7 +80,15 @@ class SettingsController < ApplicationController
set_keys.reject! { |set_key| set_key.blank? || (auto_generate && set_key_values[set_key].values.all?(&:blank?)) }
Property.transaction do
- Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all
+ # Delete only property sets that are no more existing
+ condition = "prop_key LIKE '" + key + ".%' AND "
+ set_keys.each {|set_key| condition += "prop_key NOT LIKE ('#{key + '.' + set_key + '.%'}') AND "}
+ if resource_id
+ condition += 'resource_id=' + resource_id
+ else
+ condition += 'resource_id IS NULL'
+ end
+ Property.delete_all(condition)
update_property(key, set_keys, resource_id)
set_keys.each do |set_key|
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb
index 97744feb51c..a66e0e452d5 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb
@@ -29,6 +29,8 @@ class Property < ActiveRecord::Base
named_scope :with_resources, :conditions => 'resource_id is not null'
named_scope :with_users, :conditions => 'user_id is not null'
+ EXISTING_PASSWORD = '{{*******************}}'
+
def key
prop_key
end
@@ -94,6 +96,9 @@ class Property < ActiveRecord::Base
text_value = value.to_s if defined? value
text_value = nil if text_value.blank?
+ # Load Java property definition
+ property_def = field_property_def(key) || property_def(key)
+
if text_value.blank?
return Property.clear(key, resource_id)
end
@@ -103,8 +108,11 @@ class Property < ActiveRecord::Base
return prop
end
- unless prop
+ if !prop
prop = Property.new(:prop_key => key, :resource_id => resource_id, :user_id => user_id)
+ # Do not update password that wasn't updated
+ elsif property_def.type().to_s == PropertyType::TYPE_PASSWORD && text_value == EXISTING_PASSWORD
+ text_value = prop.text_value
end
prop.text_value = text_value
@@ -139,22 +147,11 @@ class Property < ActiveRecord::Base
end
def java_definition
- @java_definition ||=
- begin
- Api::Utils.java_facade.propertyDefinitions.get(key)
- end
+ @java_definition ||= Property.property_def(key)
end
def java_field_definition
- @java_field_definition ||=
- begin
- if /(.*)\..*\.(.*)/.match(key)
- property_definition = Api::Utils.java_facade.propertyDefinitions.get(Regexp.last_match(1))
- if property_definition
- property_definition.fields.find { |field| field.key == Regexp.last_match(2) }
- end
- end
- end
+ @java_field_definition ||= Property.field_property_def(key)
end
def validation_error_message
@@ -173,12 +170,12 @@ class Property < ActiveRecord::Base
array.map { |v| v.gsub(',', '%2C') }.join(',')
end
- private
-
def self.setGlobalProperty(key, value, resource_id, user_id)
Api::Utils.java_facade.setGlobalProperty(key, value) unless (resource_id || user_id)
end
+ private
+
def self.all(key, resource_id=nil, user_id=nil)
Property.with_key(key).with_resource(resource_id).with_user(user_id)
end
@@ -205,4 +202,22 @@ class Property < ActiveRecord::Base
errors.add_to_base(validation_result.errorKey) unless validation_result.isValid()
end
end
+
+ def self.property_def(key)
+ begin
+ Api::Utils.java_facade.propertyDefinitions.get(key)
+ end
+ end
+
+ def self.field_property_def(key)
+ begin
+ if /(.*)\..*\.(.*)/.match(key)
+ property_definition = Api::Utils.java_facade.propertyDefinitions.get(Regexp.last_match(1))
+ if property_definition
+ property_definition.fields.find { |field| field.key == Regexp.last_match(2) }
+ end
+ end
+ end
+ end
+
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb
index bea86751e41..76265ab1097 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/email_configuration/index.html.erb
@@ -32,7 +32,8 @@
<tr class="property">
<th><label for="smtp_password"><h3><%= message('email_configuration.smtp_password') -%></h3></label></th>
<td>
- <%= password_field_tag 'smtp_password', @smtp_password, {:autocomplete => 'off'} %>
+ <% value = Property::EXISTING_PASSWORD unless @smtp_password.blank? %>
+ <%= password_field_tag 'smtp_password', value, {:autocomplete => 'off'} %>
<p class="marginbottom10"><%= message('email_configuration.smtp_password.description') -%></p>
</td>
</tr>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb
index 68bc7edb71a..d8c1556936c 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb
@@ -2,4 +2,6 @@
options = {:id => id}
options[:size] = (defined? size) ? size : nil
%>
-<%= property_input_field(name, PropertyType::TYPE_PASSWORD, value, PropertiesHelper::SCREEN_SETTINGS, options) %> \ No newline at end of file
+
+<% value = Property::EXISTING_PASSWORD unless value.blank? %>
+<%= property_input_field(name, PropertyType::TYPE_PASSWORD, value, PropertiesHelper::SCREEN_SETTINGS, options) %>