Add events logging for platform change_visibility action. Improve autobuild events logging. Add events log for private access to hidden repositories. Change owner assign for platform and repository. Improve gitolite doc. Refactor. Refs #2162

This commit is contained in:
Pavel Chipiga 2011-10-31 02:11:49 +02:00
parent 4b0f23cfa3
commit afc1d492a8
10 changed files with 43 additions and 34 deletions

View File

@ -3,9 +3,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery protect_from_forgery
layout :layout_by_resource layout :layout_by_resource
before_filter lambda { EventLog.current_controller = self }, before_filter lambda { EventLog.current_controller = self },
:only => [:create, :destroy, :open_id, :auto_build, :process_build, :cancel, :publish] # :update :only => [:create, :destroy, :open_id, :auto_build, :process_build, :cancel, :publish, :change_visibility] # :update
after_filter lambda { EventLog.current_controller = nil } after_filter lambda { EventLog.current_controller = nil }
helper_method :get_owner helper_method :get_owner

View File

@ -50,14 +50,14 @@ class ProjectsController < ApplicationController
end end
def auto_build def auto_build
p = params.delete_if{|k,v| k == 'controller' or k == 'action'}
ActiveSupport::Notifications.instrument("event_log.observer", :message => p.inspect) # TODO find :object ?
# logger.info "Git hook recieved from #{params[:git_user]} to #{params[:git_repo]}"
unixname = params[:git_repo].split('/')[1] unixname = params[:git_repo].split('/')[1]
project = Project.find_by_unixname(unixname) project = Project.find_by_unixname(unixname)
auto_build_list = AutoBuildList.find_by_project_id(project.id) auto_build_list = AutoBuildList.find_by_project_id(project.id)
p = params.delete_if{|k,v| k == 'controller' or k == 'action'}
ActiveSupport::Notifications.instrument("event_log.observer", :object => project, :message => p.inspect)
# logger.info "Git hook recieved from #{params[:git_user]} to #{params[:git_repo]}"
BuildList.create!( BuildList.create!(
:project_id => project.id, :project_id => project.id,
:pl_id => auto_build_list.pl_id, :pl_id => auto_build_list.pl_id,

View File

@ -123,7 +123,7 @@ class BuildList < ActiveRecord::Base
end end
def event_log_message def event_log_message
{:project => project.name, :version => project_version, :arch => arch.name}.inspect {:project => project.unixname, :version => project_version, :arch => arch.name}.inspect
end end
private private

View File

@ -1,5 +1,5 @@
class EventLogObserver < ActiveRecord::Observer class EventLogObserver < ActiveRecord::Observer
observe :user, :platform, :repository, :project, :product, :build_list, :auto_build_list observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :auto_build_list
def after_create(record) def after_create(record)
ActiveSupport::Notifications.instrument("event_log.observer", :object => record) ActiveSupport::Notifications.instrument("event_log.observer", :object => record)
@ -11,6 +11,11 @@ class EventLogObserver < ActiveRecord::Observer
if record.status_changed? and record.status == BUILD_CANCELED if record.status_changed? and record.status == BUILD_CANCELED
ActiveSupport::Notifications.instrument("event_log.observer", :object => record) ActiveSupport::Notifications.instrument("event_log.observer", :object => record)
end end
# when Platform
# if record.visibility_changed?
# ActiveSupport::Notifications.instrument "event_log.observer", :object => record,
# :message => I18n.t("activerecord.attributes.platform.visibility_types.#{record.visibility}")
# end
end end
end end

View File

@ -20,12 +20,13 @@ class Platform < ActiveRecord::Base
validates :distrib_type, :presence => true, :allow_nil => :false, :allow_blank => false, :inclusion => {:in => APP_CONFIG['distr_types']} validates :distrib_type, :presence => true, :allow_nil => :false, :allow_blank => false, :inclusion => {:in => APP_CONFIG['distr_types']}
after_create :make_owner_rel after_create :make_owner_rel
# before_save :create_directory
before_save :check_owner_rel before_save :check_owner_rel
# before_save :create_directory
# after_destroy :remove_directory # after_destroy :remove_directory
before_create :xml_rpc_create before_create :xml_rpc_create
before_destroy :xml_rpc_destroy before_destroy :xml_rpc_destroy
# before_update :check_freezing # before_update :check_freezing
after_create lambda { add_downloads_symlink unless self.hidden? }
scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}} scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}}
scope :main, where(:platform_type => 'main') scope :main, where(:platform_type => 'main')
@ -33,10 +34,6 @@ class Platform < ActiveRecord::Base
#attr_accessible :visibility #attr_accessible :visibility
after_create lambda {
add_downloads_symlink unless self.hidden?
}
def path def path
build_path(unixname) build_path(unixname)
end end
@ -85,6 +82,9 @@ class Platform < ActiveRecord::Base
self.update_attribute(:visibility, 'open') self.update_attribute(:visibility, 'open')
add_downloads_symlink add_downloads_symlink
end end
# Because observer is not invoked...
ActiveSupport::Notifications.instrument "event_log.observer", :object => self,
:message => I18n.t("activerecord.attributes.platform.visibility_types.#{visibility}")
end end
protected protected
@ -113,16 +113,6 @@ class Platform < ActiveRecord::Base
FileUtils.rm_rf(path) FileUtils.rm_rf(path)
end end
def add_owner_rel
if new_record? and owner
add_owner owner
elsif owner_id_changed?
remove_owner owner_type_was.classify.find(owner_id_was)
add_owner owner
end
end
def xml_rpc_create def xml_rpc_create
# return true # return true
result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] + '/platforms' , distrib_type result = BuildServer.add_platform unixname, APP_CONFIG['root_path'] + '/platforms' , distrib_type

View File

@ -7,6 +7,10 @@ class PrivateUser < ActiveRecord::Base
validate :login, :uniqueness => true validate :login, :uniqueness => true
def event_log_message
{:platform => platform.unixname, :user => user.uname}.inspect
end
class << self class << self
def can_generate_more?(user_id) def can_generate_more?(user_id)
!PrivateUser.exists?(:user_id => user_id) !PrivateUser.exists?(:user_id => user_id)

View File

@ -17,10 +17,10 @@ class Repository < ActiveRecord::Base
scope :recent, order("name ASC") scope :recent, order("name ASC")
after_create :make_owner_rel
before_save :check_owner_rel
#before_save :create_directory #before_save :create_directory
before_save :add_owner_rel
#after_destroy :remove_directory #after_destroy :remove_directory
before_create :xml_rpc_create before_create :xml_rpc_create
before_destroy :xml_rpc_destroy before_destroy :xml_rpc_destroy
@ -79,12 +79,14 @@ class Repository < ActiveRecord::Base
end end
end end
def add_owner_rel def make_owner_rel
if new_record? and owner add_owner owner
add_owner owner end
elsif owner_id_changed?
remove_owner owner_type_was.classify.find(owner_id_was) def check_owner_rel
add_owner owner if !new_record? and owner_id_changed?
remove_owner owner_type_was.classify.find(owner_id_was) if owner_type_was
add_owner owner if owner
end end
end end

View File

@ -10,7 +10,9 @@ ru:
'devise/sessions_controller': 'Аутентификация пользователей' 'devise/sessions_controller': 'Аутентификация пользователей'
'devise/passwords_controller': 'Восстановление пароля' 'devise/passwords_controller': 'Восстановление пароля'
'users/omniauth_callbacks_controller': 'Внешняя аутентификация пользователей' 'users/omniauth_callbacks_controller': 'Внешняя аутентификация пользователей'
rpc_controller: XML RPC rpc_controller: 'XML RPC'
private_users_controller: 'Доступ к приватным репозиториям'
personal_repositories_controller: 'Управление персональными репозиториями'
actions: actions:
'devise/sessions_controller': 'devise/sessions_controller':
create: 'вход' create: 'вход'
@ -25,6 +27,11 @@ ru:
publish: 'сборка опубликована' publish: 'сборка опубликована'
rpc_controller: rpc_controller:
xe_index: запрос xe_index: запрос
private_users_controller:
create: 'предоставлен'
destroy: 'удален'
personal_repositories_controller:
change_visibility: 'смена статуса'
create: 'создано' create: 'создано'
update: 'обновлено' update: 'обновлено'
destroy: 'удалено' destroy: 'удалено'

View File

@ -377,6 +377,7 @@ ru:
project: Проект project: Проект
rpm: RPM rpm: RPM
user: Пользователь user: Пользователь
private_user: Приватный пользователь
product: Продукт product: Продукт
build_list: Сборочный лист build_list: Сборочный лист
build_list_item: Элемент сборочного листа build_list_item: Элемент сборочного листа

View File

@ -38,6 +38,7 @@
* mkdir update.secondary.d * mkdir update.secondary.d
* touch update.secondary.d/update.auto-build * touch update.secondary.d/update.auto-build
* chmod +x update.secondary update.secondary.d/update.auto-build * chmod +x update.secondary update.secondary.d/update.auto-build
* gl-setup
--------------- Code for update.auto-build --------------- Code for update.auto-build