[refs #232] Remove name field

This commit is contained in:
konstantin.grabar 2012-03-02 14:39:48 +04:00
parent 3369953b4c
commit 8677fa7493
5 changed files with 21 additions and 8 deletions

View File

@ -41,7 +41,7 @@ class GroupsController < ApplicationController
current_user
end
if @group.save
if @group.save!
flash[:notice] = t('flash.group.saved')
redirect_to group_path(@group)
else

View File

@ -13,14 +13,14 @@ class Group < ActiveRecord::Base
has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy
validates :name, :owner, :presence => true
validates :owner, :presence => true
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ }
validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? }
scope :by_owner, lambda { |owner| where(:owner_id => owner.id) }
scope :by_admin, lambda { |admin| joins(:relations).where(:'relations.role' => 'admin', :'relations.target_id' => admin.id, :'relations.target_type' => 'User') }
attr_readonly :uname, :own_projects_count
attr_readonly :own_projects_count
delegate :ssh_key, :email, :to => :owner
@ -33,6 +33,10 @@ class Group < ActiveRecord::Base
(by_owner(user) | by_admin(user)).collect { |el| [el.name, el.id] }
end
def name
uname
end
protected
def add_owner_to_members

View File

@ -1,9 +1,9 @@
- act = controller.action_name.to_sym
- if [:new, :create].include? act
.leftlist
= f.label :name, t("activerecord.attributes.group.name"), :class => :label
= f.label :uname, t("activerecord.attributes.group.uname"), :class => :label
.rightlist.nomargin
= f.text_field :name
= f.text_field :uname
.both
%br
.leftlist

View File

@ -0,0 +1,9 @@
class RemoveNameFromGroups < ActiveRecord::Migration
def up
remove_column :groups, :name
end
def down
add_column :groups, :name, :string
end
end

View File

@ -11,7 +11,8 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120229182356) do
ActiveRecord::Schema.define(:version => 20120302102734) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
t.string "kind"
@ -156,7 +157,6 @@ ActiveRecord::Schema.define(:version => 20120229182356) do
end
create_table "groups", :force => true do |t|
t.string "name"
t.integer "owner_id"
t.datetime "created_at"
t.datetime "updated_at"
@ -284,11 +284,11 @@ ActiveRecord::Schema.define(:version => 20120229182356) 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.boolean "has_wiki", :default => false
t.string "default_branch", :default => "master"
t.boolean "is_rpm", :default => true
end