From 5c97e898290ce4cbe352df49a38ccd31689d747a Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 1 Nov 2011 02:52:24 +0200 Subject: [PATCH] Fix gitolito update_key bug. Push project colaborators git. Fix key update. Hide colaborators groups. Improve RPC XML tests. Refactor and code cleanup. Refs #2162 --- Gemfile.lock | 2 +- app/models/project.rb | 2 +- app/models/relation.rb | 17 +++++++++++++++++ app/models/user.rb | 8 ++------ app/views/projects/_sidebar.html.haml | 22 +++++++++++----------- app/views/projects/show.html.haml | 2 +- bin/xml-client-demo.rb | 4 ++-- config/locales/ru.yml | 2 +- config/routes.rb | 3 --- 9 files changed, 36 insertions(+), 26 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2e7293c13..ba14de838 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,7 +6,7 @@ GIT GIT remote: git@github.com:warpc/gitolito.git - revision: 8608b9bdfd33e961d9f9d71dd594e62780c074f6 + revision: 120992e79d079800f6efb07f100ab80437b20b43 specs: gitolito (0.0.1) grit diff --git a/app/models/project.rb b/app/models/project.rb index 925dbeea8..983d266ae 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -36,7 +36,7 @@ class Project < ActiveRecord::Base before_save :check_owner_rel after_create :attach_to_personal_repository - after_create :create_git_repo + after_create :create_git_repo before_update :update_git_repo after_destroy :destroy_git_repo after_rollback lambda { destroy_git_repo rescue true if new_record? } diff --git a/app/models/relation.rb b/app/models/relation.rb index 81f9a8f1e..f8d4a35b2 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -5,6 +5,23 @@ class Relation < ActiveRecord::Base has_many :role_lines has_many :roles, :autosave => true, :through => :role_lines + after_create { + with_ga do |ga| + if repo = ga.find_repo(target.git_repo_name) and key = object.ssh_key and key.present? + repo.add_key(key, 'RW', :force => true) + ga.save_and_release + end + end if target_type == 'Project' and object_type == 'User' + } + after_destroy { + with_ga do |ga| + if repo = ga.find_repo(target.git_repo_name) and key = object.ssh_key and key.present? + repo.rm_key(key) + ga.save_and_release + end + end if target_type == 'Project' and object_type == 'User' + } + scope :by_object, lambda {|obj| {:conditions => ['object_id = ? AND object_type = ?', obj.id, obj.class.to_s]}} scope :by_target, lambda {|tar| {:conditions => ['target_id = ? AND target_type = ?', tar.id, tar.class.to_s]}} end diff --git a/app/models/user.rb b/app/models/user.rb index ac7a909f6..04056f709 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -87,7 +87,7 @@ class User < ActiveRecord::Base def create_ssh_key(key) with_ga do |ga| ga.store_key! key - own_projects.each do |project| + projects.each do |project| repo = ga.find_repo(project.git_repo_name) repo.add_key(key, 'RW') if repo end @@ -97,12 +97,8 @@ class User < ActiveRecord::Base def update_ssh_key(old_key, new_key) with_ga do |ga| + ga.repos.replace_key old_key, new_key #, options = {} ga.replace_key! old_key, new_key - begin - ga.repos.replace_key old_key, new_key #, options = {} - rescue Gitolito::GitoliteAdmin::Repo::KeyDoesntExistsError - nil - end ga.save_and_release end end diff --git a/app/views/projects/_sidebar.html.haml b/app/views/projects/_sidebar.html.haml index 43ef8b1b1..3cff00e01 100644 --- a/app/views/projects/_sidebar.html.haml +++ b/app/views/projects/_sidebar.html.haml @@ -17,17 +17,17 @@ - if current_user.can_perform? 'collaborators', 'edit', @project = link_to t("layout.projects.edit_collaborators"), edit_project_collaborators_path(@project) - %p - %b - = "#{t("layout.projects.groups")}:" - %ul - - @project.groups.each do |group| - %li - = link_to group.name, group_path(group) - - if (@project.owner == group) - = '(' + t("layout.owner") + ')' - %br - = link_to t("layout.projects.add_groups"), '#' #add_collaborators_project_path(@project) + / %p + / %b + / = "#{t("layout.projects.groups")}:" + / %ul + / - @project.groups.each do |group| + / %li + / = link_to group.name, group_path(group) + / - if (@project.owner == group) + / = '(' + t("layout.owner") + ')' + / %br + / = link_to t("layout.projects.add_groups"), '#' #add_collaborators_project_path(@project) / .block.notice / %h3= t("layout.platforms.current_platform_header") diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index d63347855..64578a91d 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -4,7 +4,7 @@ %li.first= link_to t("layout.projects.list"), projects_path %li= link_to t("layout.projects.new"), new_project_path %li.active= link_to t("layout.projects.show"), project_path(@project) - %li= link_to "git-repo", project_repo_path(@project) + %li= link_to t("layout.git.repositories.source"), project_repo_path(@project) %li= link_to t("layout.projects.build"), build_project_path(@project) .content diff --git a/bin/xml-client-demo.rb b/bin/xml-client-demo.rb index 056f2a9a4..baa02045b 100644 --- a/bin/xml-client-demo.rb +++ b/bin/xml-client-demo.rb @@ -5,8 +5,8 @@ require 'xmlrpc/client' require 'pp' # Please correctly fill following vars -@host = 'localhost' -@port = 3000 +@host = 'npp-build.rosalab.ru' +@port = 80 @user = 'pchipiga@ya.ru' @password = '123456' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 31ab65407..70e73c0d6 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -295,7 +295,7 @@ ru: statistics_refreshed: Статистика обновлена collaborators: - successfuly_changed: Список коллабораторов успешно изменен + successfully_changed: Список коллабораторов успешно изменен error_in_changing: Ошибка изменения списка коллабораторов auto_build_list: diff --git a/config/routes.rb b/config/routes.rb index f96dc3ac3..1351cffe0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,9 +83,6 @@ Rosa::Application.routes.draw do resources :collaborators, :only => [:index, :edit, :update] do collection do - get :add - post :add - get :edit post :update end