#73: add owner_uname into Project
This commit is contained in:
parent
62ff6312b4
commit
9dcd08b868
|
@ -117,13 +117,9 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
def autocomplete_to_project
|
def autocomplete_to_project
|
||||||
items = []
|
items = []
|
||||||
term = params[:term].to_s.strip.downcase
|
term = params[:term].to_s.strip.downcase
|
||||||
condition = ["lower(concat(owners.uname, '/', projects.name)) ILIKE ?", "%#{term}%"]
|
condition = ["lower(concat(owner_uname, '/', name)) ILIKE ?", "%#{term}%"]
|
||||||
[Project.accessible_by(current_ability, :membered), @project.ancestors].each do |p|
|
[Project.accessible_by(current_ability, :membered), @project.ancestors].each do |p|
|
||||||
p = p.where(condition)
|
items.concat p.where(condition)
|
||||||
items.concat p.where(:owner_type => 'User').includes(:owner_user).
|
|
||||||
joins("INNER JOIN users as owners ON projects.owner_id = owners.id")
|
|
||||||
items.concat p.where(:owner_type => 'Group').includes(:owner_group).
|
|
||||||
joins("INNER JOIN groups as owners ON projects.owner_id = owners.id")
|
|
||||||
end
|
end
|
||||||
items = items.uniq{|i| i.id}.select{|e| e.repo.branches.count > 0}
|
items = items.uniq{|i| i.id}.select{|e| e.repo.branches.count > 0}
|
||||||
render :json => json_for_autocomplete_base(items)
|
render :json => json_for_autocomplete_base(items)
|
||||||
|
|
|
@ -19,7 +19,6 @@ class Platform < ActiveRecord::Base
|
||||||
has_many :mass_builds
|
has_many :mass_builds
|
||||||
|
|
||||||
validates :description, :presence => true
|
validates :description, :presence => true
|
||||||
validates :owner, :presence => true
|
|
||||||
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
||||||
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /\A[a-zA-Z0-9_\-\.]+\z/ }
|
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /\A[a-zA-Z0-9_\-\.]+\z/ }
|
||||||
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
|
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
|
||||||
|
|
|
@ -28,7 +28,6 @@ class Project < ActiveRecord::Base
|
||||||
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false},
|
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false},
|
||||||
:presence => true,
|
:presence => true,
|
||||||
:format => {:with => /\A#{NAME_REGEXP}\z/, :message => I18n.t("activerecord.errors.project.uname")}
|
:format => {:with => /\A#{NAME_REGEXP}\z/, :message => I18n.t("activerecord.errors.project.uname")}
|
||||||
validates :owner, :presence => true
|
|
||||||
validates :maintainer_id, :presence => true, :unless => :new_record?
|
validates :maintainer_id, :presence => true, :unless => :new_record?
|
||||||
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
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 }
|
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
|
||||||
|
@ -58,6 +57,7 @@ class Project < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
|
|
||||||
before_validation :truncate_name, :on => :create
|
before_validation :truncate_name, :on => :create
|
||||||
|
before_save lambda { self.owner_uname = owner.uname if owner_id_changed? || owner_type_changed? }
|
||||||
before_create :set_maintainer
|
before_create :set_maintainer
|
||||||
after_save :attach_to_personal_repository
|
after_save :attach_to_personal_repository
|
||||||
after_update :set_new_git_head
|
after_update :set_new_git_head
|
||||||
|
@ -81,6 +81,10 @@ class Project < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name_with_owner
|
||||||
|
"#{owner_uname}/#{name}"
|
||||||
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
class AddNameWithOwnerToProject < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :projects, :owner_uname, :string
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
UPDATE projects SET owner_uname = owners.uname
|
||||||
|
FROM users as owners
|
||||||
|
WHERE projects.owner_type = 'User' AND projects.owner_id = owners.id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
UPDATE projects SET owner_uname = owners.uname
|
||||||
|
FROM groups as owners
|
||||||
|
WHERE projects.owner_type = 'Group' AND projects.owner_id = owners.id
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
remove_column :projects, :owner_uname
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20130328112110) do
|
ActiveRecord::Schema.define(:version => 20130403202853) do
|
||||||
|
|
||||||
create_table "activity_feeds", :force => true do |t|
|
create_table "activity_feeds", :force => true do |t|
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
|
@ -387,6 +387,7 @@ ActiveRecord::Schema.define(:version => 20130328112110) do
|
||||||
t.integer "build_count", :default => 0, :null => false
|
t.integer "build_count", :default => 0, :null => false
|
||||||
t.integer "maintainer_id"
|
t.integer "maintainer_id"
|
||||||
t.boolean "publish_i686_into_x86_64", :default => false
|
t.boolean "publish_i686_into_x86_64", :default => false
|
||||||
|
t.string "owner_uname"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "projects", ["owner_id", "name", "owner_type"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
|
add_index "projects", ["owner_id", "name", "owner_type"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
|
||||||
|
|
|
@ -8,13 +8,10 @@ module Modules
|
||||||
belongs_to :owner_user, :class_name => 'User', :foreign_key => 'owner_id'
|
belongs_to :owner_user, :class_name => 'User', :foreign_key => 'owner_id'
|
||||||
belongs_to :owner_group, :class_name => 'Group', :foreign_key => 'owner_id'
|
belongs_to :owner_group, :class_name => 'Group', :foreign_key => 'owner_id'
|
||||||
|
|
||||||
|
validates :owner, :presence => true
|
||||||
after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' }
|
after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_with_owner
|
|
||||||
o = owner_type == 'User' ? owner_user : owner_group
|
|
||||||
"#{o.respond_to?(:uname) ? o.uname : o.name}/#{self.name}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue