Skip to content

Commit c86b665

Browse files
author
root
committed
Fix #288 in devel branch
1 parent 1bb483c commit c86b665

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Diff for: app/models/gitolite_public_key.rb

+22-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,28 @@ def set_identifier_for_user_key
168168

169169

170170
def set_identifier_for_deploy_key
171-
key_count = user.gitolite_public_keys.deploy_key.length + 1
172-
self.identifier ||= [ user.gitolite_identifier, '_', DEPLOY_PSEUDO_USER, '_', key_count, '@', 'redmine_', DEPLOY_PSEUDO_USER, '_', key_count ].join
171+
self.identifier ||= deploy_key_identifier
172+
end
173+
174+
175+
# Fix https://github.com/jbox-web/redmine_git_hosting/issues/288
176+
# Getting user deployment keys count is not sufficient to assure uniqueness of
177+
# deployment key identifier. So we need an 'external' counter to increment the global count
178+
# while a key with this identifier exists.
179+
#
180+
def deploy_key_identifier
181+
count = 0
182+
begin
183+
key_id = generate_deploy_key_identifier(count)
184+
count += 1
185+
end while user.gitolite_public_keys.deploy_key.map(&:owner).include?(key_id.split('@')[0])
186+
key_id
187+
end
188+
189+
190+
def generate_deploy_key_identifier(count)
191+
key_count = user.gitolite_public_keys.deploy_key.length + 1 + count
192+
[ user.gitolite_identifier, '_', DEPLOY_PSEUDO_USER, '_', key_count, '@', 'redmine_', DEPLOY_PSEUDO_USER, '_', key_count ].join
173193
end
174194

175195

0 commit comments

Comments
 (0)