diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-10-12 14:30:22 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-10-12 14:30:22 +0000 |
commit | c8d01fa82ab66a14f47d4ae5163df762c60df7c8 (patch) | |
tree | 805cf91ad2a7d856b77c2fced4b2d919055cccfd /app | |
parent | 4624e9e72883142bcd909cd15a794f6327316f1b (diff) | |
parent | 07f60552728db7276ad24dafd1ff601ae49442d2 (diff) | |
download | gitlab-ce-c8d01fa82ab66a14f47d4ae5163df762c60df7c8.tar.gz |
Merge branch 'reset_service_password' into 'master'
Invalidate stored service password if the endpoint URL is changed
See merge request !1558
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project_services/bamboo_service.rb | 7 | ||||
-rw-r--r-- | app/models/project_services/teamcity_service.rb | 7 | ||||
-rw-r--r-- | app/models/service.rb | 9 |
3 files changed, 23 insertions, 0 deletions
diff --git a/app/models/project_services/bamboo_service.rb b/app/models/project_services/bamboo_service.rb index d8aedbd2ab4..5f5255ab487 100644 --- a/app/models/project_services/bamboo_service.rb +++ b/app/models/project_services/bamboo_service.rb @@ -40,12 +40,19 @@ class BambooService < CiService attr_accessor :response after_save :compose_service_hook, if: :activated? + before_update :reset_password def compose_service_hook hook = service_hook || build_service_hook hook.save end + def reset_password + if prop_updated?(:bamboo_url) + self.password = nil + end + end + def title 'Atlassian Bamboo CI' end diff --git a/app/models/project_services/teamcity_service.rb b/app/models/project_services/teamcity_service.rb index 3c002a1634b..fb11cad352e 100644 --- a/app/models/project_services/teamcity_service.rb +++ b/app/models/project_services/teamcity_service.rb @@ -37,12 +37,19 @@ class TeamcityService < CiService attr_accessor :response after_save :compose_service_hook, if: :activated? + before_update :reset_password def compose_service_hook hook = service_hook || build_service_hook hook.save end + def reset_password + if prop_updated?(:teamcity_url) + self.password = nil + end + end + def title 'JetBrains TeamCity CI' end diff --git a/app/models/service.rb b/app/models/service.rb index 60fcc9d2857..7e845d565b1 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -117,6 +117,15 @@ class Service < ActiveRecord::Base end end + # ActiveRecord does not provide a mechanism to track changes in serialized keys. + # This is why we need to perform extra query to do it mannually. + def prop_updated?(prop_name) + relation_name = self.type.underscore + previous_value = project.send(relation_name).send(prop_name) + return false if previous_value.nil? + previous_value != send(prop_name) + end + def async_execute(data) return unless supported_events.include?(data[:object_kind]) |