reset assignee after remove member
This commit is contained in:
parent
db89e39bf5
commit
8bae631218
|
@ -110,6 +110,7 @@ class Collaborator
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
relation.try(:destroy)
|
relation.try(:destroy)
|
||||||
|
@actor.check_assigned_issues @project
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes
|
def attributes
|
||||||
|
|
|
@ -35,6 +35,9 @@ class Relation < ActiveRecord::Base
|
||||||
def self.remove_member(member, target)
|
def self.remove_member(member, target)
|
||||||
return false if target.respond_to?(:owner) && target.owner == member
|
return false if target.respond_to?(:owner) && target.owner == member
|
||||||
Relation.by_actor(member).by_target(target).each{|r| r.destroy}
|
Relation.by_actor(member).by_target(target).each{|r| r.destroy}
|
||||||
|
if member.is_a?(User) && ['Project', 'Group'].include?(target.class.name)
|
||||||
|
member.check_assigned_issues target
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -28,6 +28,7 @@ class User < Avatar
|
||||||
has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy
|
has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy
|
||||||
has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy
|
has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy
|
||||||
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy
|
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy
|
||||||
|
has_many :assigned_issues, :foreign_key => :assignee_id, :class_name => 'Issue', :dependent => :nullify
|
||||||
|
|
||||||
has_many :key_pairs
|
has_many :key_pairs
|
||||||
has_many :ssh_keys, :dependent => :destroy
|
has_many :ssh_keys, :dependent => :destroy
|
||||||
|
@ -141,6 +142,19 @@ class User < Avatar
|
||||||
raise "unknown user #{self.uname} roles #{roles}"
|
raise "unknown user #{self.uname} roles #{roles}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_assigned_issues target
|
||||||
|
if target.is_a? Project
|
||||||
|
assigned_issues.where(:project_id => target.id).update_all(:assignee_id => nil)
|
||||||
|
else
|
||||||
|
ability = Ability.new self
|
||||||
|
project_ids = Project.accessible_by(ability, :membered).uniq.pluck(:id)
|
||||||
|
|
||||||
|
issues = assigned_issues
|
||||||
|
issues = issues.where('project_id not in (?)', project_ids) if project_ids.present?
|
||||||
|
issues.update_all(:assignee_id => nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def target_roles target
|
def target_roles target
|
||||||
|
|
|
@ -41,8 +41,8 @@ describe Issue do
|
||||||
@project = FactoryGirl.create(:project, :owner => @user)
|
@project = FactoryGirl.create(:project, :owner => @user)
|
||||||
|
|
||||||
@group = FactoryGirl.create(:group)
|
@group = FactoryGirl.create(:group)
|
||||||
reader = FactoryGirl.create :user
|
@reader = FactoryGirl.create :user
|
||||||
@group.actors.create(:actor_type => 'User', :actor_id => reader.id, :role => 'reader')
|
@group.actors.create(:actor_type => 'User', :actor_id => @reader.id, :role => 'reader')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send an e-mail to all members of the admin group' do
|
it 'should send an e-mail to all members of the admin group' do
|
||||||
|
@ -65,6 +65,32 @@ describe Issue do
|
||||||
create_issue(@stranger)
|
create_issue(@stranger)
|
||||||
ActionMailer::Base.deliveries.count.should == 1 # 1 project owner
|
ActionMailer::Base.deliveries.count.should == 1 # 1 project owner
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should reset issue assignee after remove him from group' do
|
||||||
|
@project.relations.create!(:actor_type => 'Group', :actor_id => @group.id, :role => 'reader')
|
||||||
|
create_issue(@group.owner)
|
||||||
|
@issue.update_column :assignee_id, @reader.id
|
||||||
|
@group.remove_member @reader
|
||||||
|
@issue.reload.assignee_id.should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not reset issue assignee' do
|
||||||
|
@project.relations.create!(:actor_type => 'Group', :actor_id => @group.id, :role => 'reader')
|
||||||
|
@project.relations.create!(:actor_type => 'User', :actor_id => @reader.id, :role => 'reader')
|
||||||
|
create_issue(@group.owner)
|
||||||
|
@issue.update_column :assignee_id, @reader.id
|
||||||
|
@group.remove_member @reader
|
||||||
|
@issue.reload.assignee_id.should == @reader.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should reset issue assignee after remove him from project' do
|
||||||
|
@project.relations.create!(:actor_type => 'User', :actor_id => @reader.id, :role => 'reader')
|
||||||
|
create_issue(@reader)
|
||||||
|
@issue.update_column :assignee_id, @reader.id
|
||||||
|
@project.remove_member @reader
|
||||||
|
@issue.reload.assignee_id.should == nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Group project' do
|
context 'Group project' do
|
||||||
|
|
Loading…
Reference in New Issue