Commit 9840102651ac84d2eb7824113a544bf4992e0398
1 parent
819818ad
Exists in
master
and in
4 other branches
Issue #82 - Add owner to project
Showing
7 changed files
with
15 additions
and
3 deletions
Show diff stats
app/controllers/projects_controller.rb
| @@ -87,6 +87,7 @@ class ProjectsController < ApplicationController | @@ -87,6 +87,7 @@ class ProjectsController < ApplicationController | ||
| 87 | 87 | ||
| 88 | def create | 88 | def create |
| 89 | @project = Project.new(params[:project]) | 89 | @project = Project.new(params[:project]) |
| 90 | + @project.owner = current_user | ||
| 90 | 91 | ||
| 91 | Project.transaction do | 92 | Project.transaction do |
| 92 | @project.save! | 93 | @project.save! |
app/models/project.rb
| @@ -4,6 +4,7 @@ class Project < ActiveRecord::Base | @@ -4,6 +4,7 @@ class Project < ActiveRecord::Base | ||
| 4 | has_many :issues, :dependent => :destroy | 4 | has_many :issues, :dependent => :destroy |
| 5 | has_many :users_projects, :dependent => :destroy | 5 | has_many :users_projects, :dependent => :destroy |
| 6 | has_many :users, :through => :users_projects | 6 | has_many :users, :through => :users_projects |
| 7 | + belongs_to :owner, :class_name => "User" | ||
| 7 | has_many :notes, :dependent => :destroy | 8 | has_many :notes, :dependent => :destroy |
| 8 | 9 | ||
| 9 | validates :name, | 10 | validates :name, |
| @@ -28,7 +29,7 @@ class Project < ActiveRecord::Base | @@ -28,7 +29,7 @@ class Project < ActiveRecord::Base | ||
| 28 | after_destroy :destroy_gitosis_project | 29 | after_destroy :destroy_gitosis_project |
| 29 | after_save :update_gitosis_project | 30 | after_save :update_gitosis_project |
| 30 | 31 | ||
| 31 | - attr_protected :private_flag | 32 | + attr_protected :private_flag, :owner_id |
| 32 | 33 | ||
| 33 | scope :public_only, where(:private_flag => false) | 34 | scope :public_only, where(:private_flag => false) |
| 34 | 35 | ||
| @@ -44,7 +45,6 @@ class Project < ActiveRecord::Base | @@ -44,7 +45,6 @@ class Project < ActiveRecord::Base | ||
| 44 | read_attribute(:code).downcase.strip.gsub(' ', '') | 45 | read_attribute(:code).downcase.strip.gsub(' ', '') |
| 45 | end | 46 | end |
| 46 | 47 | ||
| 47 | - | ||
| 48 | def update_gitosis_project | 48 | def update_gitosis_project |
| 49 | Gitosis.new.configure do |c| | 49 | Gitosis.new.configure do |c| |
| 50 | c.update_project(path, gitosis_writers) | 50 | c.update_project(path, gitosis_writers) |
| @@ -145,5 +145,6 @@ end | @@ -145,5 +145,6 @@ end | ||
| 145 | # updated_at :datetime | 145 | # updated_at :datetime |
| 146 | # private_flag :boolean default(TRUE), not null | 146 | # private_flag :boolean default(TRUE), not null |
| 147 | # code :string(255) | 147 | # code :string(255) |
| 148 | +# owner_id :integer | ||
| 148 | # | 149 | # |
| 149 | 150 |
app/models/user.rb
| @@ -9,6 +9,7 @@ class User < ActiveRecord::Base | @@ -9,6 +9,7 @@ class User < ActiveRecord::Base | ||
| 9 | 9 | ||
| 10 | has_many :users_projects, :dependent => :destroy | 10 | has_many :users_projects, :dependent => :destroy |
| 11 | has_many :projects, :through => :users_projects | 11 | has_many :projects, :through => :users_projects |
| 12 | + has_many :my_own_projects, :class_name => "Project", :foreign_key => :owner_id | ||
| 12 | has_many :keys, :dependent => :destroy | 13 | has_many :keys, :dependent => :destroy |
| 13 | has_many :issues, | 14 | has_many :issues, |
| 14 | :foreign_key => :author_id, | 15 | :foreign_key => :author_id, |
| @@ -48,5 +49,6 @@ end | @@ -48,5 +49,6 @@ end | ||
| 48 | # updated_at :datetime | 49 | # updated_at :datetime |
| 49 | # name :string(255) | 50 | # name :string(255) |
| 50 | # admin :boolean default(FALSE), not null | 51 | # admin :boolean default(FALSE), not null |
| 52 | +# allowed_create_repo :boolean default(TRUE), not null | ||
| 51 | # | 53 | # |
| 52 | 54 |
db/schema.rb
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | # | 11 | # |
| 12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | ||
| 14 | -ActiveRecord::Schema.define(:version => 20111005193700) do | 14 | +ActiveRecord::Schema.define(:version => 20111009101738) do |
| 15 | 15 | ||
| 16 | create_table "issues", :force => true do |t| | 16 | create_table "issues", :force => true do |t| |
| 17 | t.string "title" | 17 | t.string "title" |
| @@ -52,6 +52,7 @@ ActiveRecord::Schema.define(:version => 20111005193700) do | @@ -52,6 +52,7 @@ ActiveRecord::Schema.define(:version => 20111005193700) do | ||
| 52 | t.datetime "updated_at" | 52 | t.datetime "updated_at" |
| 53 | t.boolean "private_flag", :default => true, :null => false | 53 | t.boolean "private_flag", :default => true, :null => false |
| 54 | t.string "code" | 54 | t.string "code" |
| 55 | + t.integer "owner_id" | ||
| 55 | end | 56 | end |
| 56 | 57 | ||
| 57 | create_table "users", :force => true do |t| | 58 | create_table "users", :force => true do |t| |
spec/models/project_spec.rb
spec/models/user_spec.rb
| @@ -38,5 +38,6 @@ end | @@ -38,5 +38,6 @@ end | ||
| 38 | # updated_at :datetime | 38 | # updated_at :datetime |
| 39 | # name :string(255) | 39 | # name :string(255) |
| 40 | # admin :boolean default(FALSE), not null | 40 | # admin :boolean default(FALSE), not null |
| 41 | +# allowed_create_repo :boolean default(TRUE), not null | ||
| 41 | # | 42 | # |
| 42 | 43 |