Merge branch 'feature/merge_requests'

This commit is contained in:
Dmitriy Zaporozhets 2011-11-28 22:43:42 +02:00
commit 22ac0cc7eb
29 changed files with 531 additions and 42 deletions

View file

@ -17,6 +17,7 @@ class Ability
:read_issue,
:read_snippet,
:read_team_member,
:read_merge_request,
:read_note
] if project.readers.include?(user)
@ -24,6 +25,7 @@ class Ability
:write_project,
:write_issue,
:write_snippet,
:write_merge_request,
:write_note
] if project.writers.include?(user)
@ -32,6 +34,7 @@ class Ability
:admin_issue,
:admin_snippet,
:admin_team_member,
:admin_merge_request,
:admin_note
] if project.admins.include?(user)
@ -39,7 +42,7 @@ class Ability
end
class << self
[:issue, :note, :snippet].each do |name|
[:issue, :note, :snippet, :merge_request].each do |name|
define_method "#{name}_abilities" do |user, subject|
if subject.author == user
[

View file

@ -0,0 +1,36 @@
class MergeRequest < ActiveRecord::Base
belongs_to :project
belongs_to :author, :class_name => "User"
belongs_to :assignee, :class_name => "User"
has_many :notes, :as => :noteable
attr_protected :author, :author_id, :project, :project_id
validates_presence_of :project_id
validates_presence_of :assignee_id
validates_presence_of :author_id
validates_presence_of :source_branch
validates_presence_of :target_branch
delegate :name,
:email,
:to => :author,
:prefix => true
delegate :name,
:email,
:to => :assignee,
:prefix => true
validates :title,
:presence => true,
:length => { :within => 0..255 }
scope :opened, where(:closed => false)
scope :closed, where(:closed => true)
scope :assigned, lambda { |u| where(:assignee_id => u.id)}
def new?
today? && created_at == updated_at
end
end

View file

@ -3,6 +3,7 @@ require "grit"
class Project < ActiveRecord::Base
belongs_to :owner, :class_name => "User"
has_many :merge_requests, :dependent => :destroy
has_many :issues, :dependent => :destroy, :order => "position"
has_many :users_projects, :dependent => :destroy
has_many :users, :through => :users_projects