[issue #620] Changed maintainer assignment.

*  Added `project:maintainer:set_to_owner` task to set projects maintainer
     to its owner
  *  Removed callbacks and methods to find maintainer 'on-the-fly'
This commit is contained in:
George Vinogradov 2012-08-28 01:12:53 +04:00
parent 7572562cad
commit f688985814
9 changed files with 81 additions and 29 deletions

View File

@ -5,7 +5,9 @@ class Platforms::MaintainersController < ApplicationController
load_and_authorize_resource :platform
def index
@maintainers = BuildList::Package.actual.by_platform(@platform).order('lower(name) ASC')
@maintainers = BuildList::Package.actual.by_platform(@platform)
.order('lower(name) ASC')
.order('length(name) ASC')
.includes(:project)
@maintainers = @maintainers.find_by_name(params[:q]) if params[:q].present?
@maintainers = @maintainers.paginate(:page => params[:page])

View File

@ -24,6 +24,7 @@ class Project < ActiveRecord::Base
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^#{NAME_REGEXP}$/, :message => I18n.t("activerecord.errors.project.uname")}
validates :owner, :presence => true
validates :maintainer_id, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
@ -36,9 +37,9 @@ class Project < ActiveRecord::Base
scope :by_name, lambda {|name| where('projects.name ILIKE ?', name)}
scope :by_visibilities, lambda {|v| where(:visibility => v)}
scope :opened, where(:visibility => 'open')
scope :package, where(:is_package => true)
scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id = #{ repository_id }))") }
before_validation :set_maintainer
after_create :attach_to_personal_repository
has_ancestry :orphan_strategy => :rootify #:adopt not available yet
@ -60,6 +61,10 @@ class Project < ActiveRecord::Base
end
end
def project_maintainer
maintainer || owner.assignee
end
def to_param
name
end
@ -68,19 +73,6 @@ class Project < ActiveRecord::Base
collaborators + groups.map(&:members).flatten
end
def maintainer_id
self[:maintainer_id] || owner.assignee.id
end
alias_method :maintainer_original, :maintainer
def maintainer
maintainer_original || owner.assignee
end
def maintainer_name
maintainer.fullname
end
def platforms
@platforms ||= repositories.map(&:platform).uniq
end
@ -171,8 +163,4 @@ class Project < ActiveRecord::Base
repositories << self.owner.personal_repository if !repositories.exists?(:id => self.owner.personal_repository)
end
def set_maintainer
maintainer ||= owner.assignee
end
end

View File

@ -51,16 +51,16 @@
.both
.both
#maintainer_form{:class => @project.is_package ? '' : 'hidden'}
= f.hidden_field :maintainer_id, :value => @project.maintainer_id
= f.hidden_field :maintainer_id, :value => @project.project_maintainer.id
.leftlist
= t("activerecord.attributes.project.maintainer")
.rightlist
-# TODO: Maybe use something like Chosen with filter and prepopulated
-# list of potential maintainers?
= autocomplete_field_tag :maintainer_name, @project.maintainer_name,
project_autocomplete_maintainers_path(@project.owner, @project),
= autocomplete_field_tag :maintainer_name, @project.project_maintainer.fullname,
autocomplete_maintainers_path(@project.owner, @project),
:id_element => '#project_maintainer_id',
:placeholder => @project.maintainer_name
:placeholder => @project.project_maintainer.fullname
- if [:new, :create].include? act
.leftlist= f.label :srpm, t("activerecord.attributes.project.srpm"), :class => :label
.rightlist= f.file_field :srpm, :class => 'file_field'

View File

@ -101,3 +101,32 @@ namespace :rake_tasks do
mirror_rake_tasks 'db:seeds'
end
end
namespace :update do
desc "Copy remote production shared files to localhost"
task :shared do
run_locally "rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{user}@#{domain}:#{shared_path}/shared_contents/uploads public/uploads"
end
desc "Dump remote production postgresql database, rsync to localhost"
task :postgresql do
get("#{current_path}/config/database.yml", "tmp/database.yml")
remote_settings = YAML::load_file("tmp/database.yml")[rails_env]
local_settings = YAML::load_file("config/database.yml")["development"]
run "export PGPASSWORD=#{remote_settings["password"]} && pg_dump --host=#{remote_settings["host"]} --port=#{remote_settings["port"]} --username #{remote_settings["username"]} --file #{current_path}/tmp/#{remote_settings["database"]}_dump -Fc #{remote_settings["database"]}"
run_locally "rsync --recursive --times --rsh=ssh --compress --human-readable --progress #{user}@#{domain}:#{current_path}/tmp/#{remote_settings["database"]}_dump tmp/"
run_locally "dropdb -U #{local_settings["username"]} --host=#{local_settings["host"]} --port=#{local_settings["port"]} #{local_settings["database"]}"
run_locally "createdb -U #{local_settings["username"]} --host=#{local_settings["host"]} --port=#{local_settings["port"]} -T template0 #{local_settings["database"]}"
run_locally "pg_restore -U #{local_settings["username"]} --host=#{local_settings["host"]} --port=#{local_settings["port"]} -d #{local_settings["database"]} tmp/#{remote_settings["database"]}_dump"
end
desc "Dump all remote data to localhost"
task :all do
# update.shared
update.postgresql
end
end

View File

@ -94,6 +94,7 @@ en:
default_branch: Default branch
is_package: Project is a package
maintainer: Maintainer of project
maintainer_id: Maintainer of project
errors:
project:
uname: The name can only use lower case Latin letters (a-z), numbers (0-9) and underscore (_)

View File

@ -93,6 +93,7 @@ ru:
group: Группа
default_branch: Ветка по умолчанию
is_package: Проект является пакетом
maintainer_id: Майнтейнер проекта
maintainer: Майнтейнер проекта
errors:
project:

View File

@ -2,12 +2,13 @@ class AddActualToBuildListPackages < ActiveRecord::Migration
def self.up
add_column :build_list_packages, :actual, :boolean, :default => false
add_index :build_list_packages, [:actual, :platform_id], :name => :actual_platform_packages
add_index :build_list, [:project_id, :save_to_repository_id, :build_for_platform_id, :arch_id]
add_index :build_lists, [:project_id, :save_to_repository_id, :build_for_platform_id, :arch_id],
:name => :maintainer_search_index
end
def self.down
remove_column :build_list_packages, :actual
remove_index :build_list_packages, [:actual, :platform_id], :name => :actual_platform_packages
remove_index :build_list, [:project_id, :save_to_repository_id, :build_for_platform_id, :arch_id]
remove_index :build_lists, [:project_id, :save_to_repository_id, :build_for_platform_id, :arch_id]
end
end

View File

@ -17,8 +17,8 @@ ActiveRecord::Schema.define(:version => 20120822210712) do
t.integer "user_id", :null => false
t.string "kind"
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "advisories", :force => true do |t|
@ -134,6 +134,7 @@ ActiveRecord::Schema.define(:version => 20120822210712) do
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"
add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id"
add_index "build_lists", ["project_id", "save_to_repository_id", "build_for_platform_id", "arch_id"], :name => "maintainer_search_index"
add_index "build_lists", ["bs_id"], :name => "index_build_lists_on_bs_id", :unique => true
add_index "build_lists", ["project_id"], :name => "index_build_lists_on_project_id"
@ -326,11 +327,11 @@ ActiveRecord::Schema.define(:version => 20120822210712) do
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
t.boolean "has_wiki", :default => false
t.string "srpm_file_name"
t.string "srpm_content_type"
t.integer "srpm_file_size"
t.datetime "srpm_updated_at"
t.string "srpm_content_type"
t.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_package", :default => true, :null => false
t.integer "average_build_time", :default => 0, :null => false
@ -406,6 +407,7 @@ ActiveRecord::Schema.define(:version => 20120822210712) do
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.string "role"
t.string "language", :default => "en"

28
lib/tasks/projects.rake Normal file
View File

@ -0,0 +1,28 @@
namespace :project do
namespace :maintainer do
desc 'Set maintainer to owner (or to owners owner if owner is a group) to projects'
task :set_to_owner => :environment do
projects = Project.scoped
count = projects.count
say "Setting maintainer to all projects (#{count})"
percent_per_batch = 100 * 1000 / count
i = 1
projects.find_in_batches do |batch|
ActiveRecord::Base.transaction do
batch.each do |proj|
maintainer_id = (proj.owner_type == 'User') ? proj.owner_id : proj.owner.owner_id
proj.maintainer_id = maintainer_id
proj.save
end
end
say "#{percent_per_batch * i}% done."
i += 1
end
say "100% done"
end
end
task :maintainer => 'maintainer:set_to_owner'
end