From: Julien Lancelot Date: Mon, 22 Dec 2014 14:10:51 +0000 (+0100) Subject: Revert "SSF-25 SMTP configuration password" X-Git-Tag: 5.0-RC4~22 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5398d3b52002a9285b2fc6e5588036aae7d228fa;p=sonarqube.git Revert "SSF-25 SMTP configuration password" This reverts commit 181538a6d0884e74beec8ad6aa3dcf460baec5ea. --- 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 9fb6c4d8f4b..33b8600e4c5 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,30 +23,27 @@ 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]) - # Password can only be set when empty, the update will be done by the edit modal window - if !params[:smtp_password].blank? - Property.set(configuration::SMTP_PASSWORD, params[:smtp_password]) - end - 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]) + 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' end def send_test_email @@ -69,7 +66,7 @@ class EmailConfigurationController < ApplicationController private def configuration - java_facade.getComponentByClassname('emailnotifications', 'org.sonar.api.config.EmailSettings').class + java_facade.getComponentByClassname('emailnotifications', 'org.sonar.api.config.EmailSettings').class end def properties 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 b6879063884..5a48b659558 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 @@ -44,32 +44,6 @@ class SettingsController < ApplicationController render :partial => 'settings/properties' end - def update_password_form - @key = params[:key] - @component_id = params[:component_id] - render :partial => 'settings/update_password_form' - end - - def update_password - property_key = params[:key] - component_id = params[:component_id] - not_found('Property key should be set') unless property_key - component_id = !component_id.blank? ? component_id : nil - password = params[:password] - - property = Property.by_key(property_key, component_id) - if property - if !password.blank? - property.text_value = password - property.save - else - property.delete - end - end - Property.setGlobalProperty(property_key, password, component_id, nil) - render :text => 'ok', :status => 200 - end - private def update_properties(resource_id) @@ -89,7 +63,7 @@ class SettingsController < ApplicationController max = (Time.now.to_f * 100000).to_i set_keys.each_with_index do |v, index| if v.blank? - max += 1 + max += 1; set_keys[index] = max.to_s end end @@ -106,15 +80,7 @@ class SettingsController < ApplicationController set_keys.reject! { |set_key| set_key.blank? || (auto_generate && set_key_values[set_key].values.all?(&:blank?)) } Property.transaction do - # Delete only property sets that are no more existing - condition = '' - 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) + Property.with_key_prefix(key + '.').with_resource(resource_id).delete_all 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 1c96bbbfe25..97744feb51c 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 @@ -94,11 +94,7 @@ 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) - - # Dot not delete password properties - if text_value.blank? && property_def.type().to_s != PropertyType::TYPE_PASSWORD + if text_value.blank? return Property.clear(key, resource_id) end @@ -107,11 +103,8 @@ class Property < ActiveRecord::Base return prop end - if !prop + unless prop prop = Property.new(:prop_key => key, :resource_id => resource_id, :user_id => user_id) - # Existing password should not be touched - elsif property_def.type().to_s == PropertyType::TYPE_PASSWORD && !prop.text_value.blank? - text_value = prop.text_value end prop.text_value = text_value @@ -146,11 +139,22 @@ class Property < ActiveRecord::Base end def java_definition - @java_definition ||= Property.property_def(key) + @java_definition ||= + begin + Api::Utils.java_facade.propertyDefinitions.get(key) + end end def java_field_definition - @java_field_definition ||= Property.field_property_def(key) + @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 end def validation_error_message @@ -169,12 +173,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 @@ -201,22 +205,4 @@ 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 1e1f11bf2f4..bea86751e41 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,13 +32,7 @@ - <% if @smtp_password.blank? %> - - <% else %> - ********** - Edit - <% end %> + <%= password_field_tag 'smtp_password', @smtp_password, {:autocomplete => 'off'} %>

<%= message('email_configuration.smtp_password.description') -%>

diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb index ee764458289..9b965ee07b7 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb @@ -5,7 +5,7 @@ $j('#loading_settings').show(); $j.ajax({ url:'<%= url_for :controller => 'settings', :action => 'update', :category => @category.key, :subcategory => @subcategory.key, :resource_id => (@resource && @resource.id) -%>', type:'post', - success:function(responseHTML){$j('#properties').html($j(responseHTML));$j('#loading_settings').hide();$j('#submit_settings').show();$j('#properties').find('.open-modal').modal()}, + success:function(responseHTML){$j('#properties').html($j(responseHTML));$j('#loading_settings').hide();$j('#submit_settings').show()}, data:$j(this).serialize()}); return false;" method='post' @@ -174,14 +174,14 @@ - <% else + <% else help = category_help(@category) unless help.blank? -%>
<%= help -%>
- <% end + <% end end -%> @@ -189,22 +189,24 @@ <% end -%> + + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb index c198581ba7a..57d5a57d7c7 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_set_instance.html.erb @@ -12,9 +12,12 @@ <% value = Property.value(key, resource_id) -%> <% errors << (render "settings/error", :key => key) -%> <% end -%> - <% name = field == key_field ? "property_sets[#{property.key}][]" : "#{property.key}[#{field.key}][]" %> - <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => name, :property_key => key, - :id => "input_#{h field.key}", :size => field.indicativeSize -%> + + <% if field == key_field -%> + <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "property_sets[#{property.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%> + <% else -%> + <%= render "settings/type_#{field.type}", :property => field, :field => field, :value => value, :name => "#{property.key}[#{field.key}][]", :id => "input_#{h field.key}", :size => field.indicativeSize -%> + <% end -%> <% end -%> 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 66a1ded8ae7..68bc7edb71a 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,13 +2,4 @@ options = {:id => id} options[:size] = (defined? size) ? size : nil %> - -<% if value.blank? %> - <%= property_input_field(name, PropertyType::TYPE_PASSWORD, value, PropertiesHelper::SCREEN_SETTINGS, options) %> -<% else %> - <% key = (defined? property_key) ? property_key : property.key %> - ********** - Edit - -<% end %> +<%= property_input_field(name, PropertyType::TYPE_PASSWORD, value, PropertiesHelper::SCREEN_SETTINGS, options) %> \ No newline at end of file diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_update_password_form.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_update_password_form.html.erb deleted file mode 100644 index 0d3d738e55e..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/settings/_update_password_form.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -
-
- - - -
-
- -