[refs #441] Refactring: part 2. Fix integration with kernel, change view for keys list

This commit is contained in:
Vladimir Sharshov 2012-07-31 01:24:31 +04:00
parent 89d67f9ea6
commit 73a369ba49
4 changed files with 16 additions and 12 deletions

View File

@ -8,7 +8,7 @@ class KeyPair < ActiveRecord::Base
validates :repository_id, :public, :user_id, :presence => true
validates :secret, :presence => true, :on => :create
validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pairs.repo_key_exists")}
validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pair.repo_key_exists")}
before_create :key_create_call
before_destroy :rm_key_call
@ -17,17 +17,19 @@ class KeyPair < ActiveRecord::Base
def key_create_call
result, self.key_id = BuildServer.import_gpg_key_pair(public, secret)
raise "Failed to create key_pairs for repository #{repository_id} with code #{result}." unless result == 4
raise "Failed to create key_pairs for repository #{repository_id} with code #{result}." if result == 4
if result != 0 || key_id.nil?
errors.add(:public, I18n.t("activerecord.errors.key_pairs.#{result}"))
errors.add(:public, I18n.t("activerecord.errors.key_pair.#{result}"))
return false
end
result = BuildServer.set_repository_key(repository_id, repository.platform_id, key_id)
raise "Failed to sign repository key #{repository_id} with code #{set_code}." unless result.zero?
result = BuildServer.set_repository_key(repository.platform.name, repository.name, key_id)
raise "Failed to sign repository #{repository.name} in platform #{repository.platform.name}
using key_id #{key_id} with code #{result}." unless result.zero?
end
def rm_key_call
result = BuildServer.rm_repository_key(repository.platform_id, repository_id)
raise "Failed to desroy repository key #{repository_id} with code #{result}." unless result.zero?
result = BuildServer.rm_repository_key(repository.platform.name, repository.name)
raise "Failed to desroy repository key #{repository.name} in platform
#{repository.platform.name} with code #{result}." unless result.zero?
end
end

View File

@ -2,7 +2,7 @@
%thead
%tr
%th.th1= t("activerecord.attributes.key_pair.repository_id")
%th.th2= t("activerecord.attributes.key_pair.public")
%th.th2= t("activerecord.attributes.key_pair.key_id")
%th.th3= t("activerecord.attributes.key_pair.user_id")
%th= t("layout.delete")
%tbody
@ -10,8 +10,8 @@
- if repository.key_pair
%tr{:class => cycle("odd", "even")}
%td= repository.name
%td= repository.key_pair.public
%td= repository.key_pair.user.name
%td= repository.key_pair.key_id
%td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user)
%td.buttons
- if can? :destroy, repository.key_pair
= link_to platform_key_pair_path(@platform, repository.key_pair), :method => :delete, :confirm => t("layout.key_pairs.confirm_delete") do

View File

@ -31,3 +31,4 @@ en:
repository_id: Repository
public: Public key
secret: Secret key
key_id: Signature

View File

@ -11,7 +11,7 @@ ru:
key_pairs:
saved: Репозиторий успешно подписан
save_error: Ошибка создания подписи
destroyed: Подпись удалена успешно
destroyed: Подпись успешно удалена
destroy_error: Ошибка удаления подписи
activerecord:
errors:
@ -30,4 +30,5 @@ ru:
user_id: Пользователь
repository_id: Репозиторий
public: Публичный ключ
secret: Секретный ключ
secret: Секретный ключ
key_id: Подпись