User left project event added
This commit is contained in:
parent
a86bd87afc
commit
1f240b09ed
|
@ -8,9 +8,8 @@ class EventDecorator < ApplicationDecorator
|
|||
"#{self.author_name} #{self.action_name} MR ##{self.target_id}:" + self.merge_request_title
|
||||
elsif self.push?
|
||||
"#{self.author_name} #{self.push_action_name} #{self.ref_type} " + self.ref_name
|
||||
elsif self.joined?
|
||||
elsif self.membership_changed?
|
||||
"#{self.author_name} #{self.action_name} #{self.project.name}"
|
||||
|
||||
else
|
||||
""
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@ class Event < ActiveRecord::Base
|
|||
Commented = 6
|
||||
Merged = 7
|
||||
Joined = 8 # User joined project
|
||||
Left = 9 # User left project
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :target, polymorphic: true
|
||||
|
@ -38,7 +39,7 @@ class Event < ActiveRecord::Base
|
|||
# - new issue
|
||||
# - merge request
|
||||
def allowed?
|
||||
push? || issue? || merge_request? || joined?
|
||||
push? || issue? || merge_request? || membership_changed?
|
||||
end
|
||||
|
||||
def push?
|
||||
|
@ -86,7 +87,15 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def joined?
|
||||
action == self.class::Joined
|
||||
action == Joined
|
||||
end
|
||||
|
||||
def left?
|
||||
action == Left
|
||||
end
|
||||
|
||||
def membership_changed?
|
||||
joined? || left?
|
||||
end
|
||||
|
||||
def issue
|
||||
|
@ -108,6 +117,8 @@ class Event < ActiveRecord::Base
|
|||
"merged"
|
||||
elsif joined?
|
||||
'joined'
|
||||
elsif left?
|
||||
'left'
|
||||
else
|
||||
"opened"
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class UsersProject < ActiveRecord::Base
|
|||
def self.bulk_delete(project, user_ids)
|
||||
UsersProject.transaction do
|
||||
UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project|
|
||||
users_project.delete
|
||||
users_project.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,4 +12,13 @@ class UsersProjectObserver < ActiveRecord::Observer
|
|||
def after_update(users_project)
|
||||
Notify.project_access_granted_email(users_project.id).deliver
|
||||
end
|
||||
|
||||
def after_destroy(users_project)
|
||||
Event.create(
|
||||
project_id: users_project.project.id,
|
||||
action: Event::Left,
|
||||
author_id: users_project.user.id
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
.event_feed
|
||||
= render "events/event_push", event: event
|
||||
|
||||
- elsif event.joined?
|
||||
- elsif event.membership_changed?
|
||||
.event_feed
|
||||
= render "events/event_joined", event: event
|
||||
= render "events/event_membership_changed", event: event
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
= image_tag gravatar_icon(event.author_email), class: "avatar"
|
||||
%strong #{event.author_name}
|
||||
%span.event_label{class: event.action_name}= event.action_name
|
||||
project
|
||||
%strong= link_to event.project.name, event.project
|
||||
%span.cgray
|
||||
= time_ago_in_words(event.created_at)
|
|
@ -15,9 +15,14 @@ Feature: Dashboard
|
|||
And I click "Create Merge Request" link
|
||||
Then I see prefilled new Merge Request page
|
||||
|
||||
@current
|
||||
Scenario: I should see User joined Project event
|
||||
Given user with name "John Doe" joined project "Shop"
|
||||
When I visit dashboard page
|
||||
Then I should see "John Doe joined Shop" event
|
||||
Then I should see "John Doe joined project Shop" event
|
||||
|
||||
Scenario: I should see User left Project event
|
||||
Given user with name "John Doe" joined project "Shop"
|
||||
And user with name "John Doe" left project "Shop"
|
||||
When I visit dashboard page
|
||||
Then I should see "John Doe left project Shop" event
|
||||
|
||||
|
|
|
@ -120,6 +120,16 @@ Given /^user with name "(.*?)" joined project "(.*?)"$/ do |user_name, project_n
|
|||
)
|
||||
end
|
||||
|
||||
Given /^user with name "(.*?)" left project "(.*?)"$/ do |user_name, project_name|
|
||||
user = User.find_by_name user_name
|
||||
project = Project.find_by_name project_name
|
||||
Event.create(
|
||||
project: project,
|
||||
author_id: user.id,
|
||||
action: Event::Left
|
||||
)
|
||||
end
|
||||
|
||||
Then /^I should see "(.*?)" event$/ do |event_text|
|
||||
page.should have_content(event_text)
|
||||
end
|
||||
|
|
|
@ -50,7 +50,7 @@ describe Event do
|
|||
it { @event.author.should == @user }
|
||||
end
|
||||
|
||||
describe "New team mamber" do
|
||||
describe "Joined project team" do
|
||||
let(:project) {Factory.create :project}
|
||||
let(:new_user) {Factory.create :user}
|
||||
it "should create event" do
|
||||
|
@ -60,4 +60,15 @@ describe Event do
|
|||
}.to change{Event.count}.by(1)
|
||||
end
|
||||
end
|
||||
describe "Left project team" do
|
||||
let(:project) {Factory.create :project}
|
||||
let(:new_user) {Factory.create :user}
|
||||
it "should create event" do
|
||||
UsersProject.bulk_import(project, [new_user.id], UsersProject::DEVELOPER)
|
||||
UsersProject.observers.enable :users_project_observer
|
||||
expect{
|
||||
UsersProject.bulk_delete(project, [new_user.id])
|
||||
}.to change{Event.count}.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,4 +45,23 @@ describe UsersProjectObserver do
|
|||
subject.after_update(users_project)
|
||||
end
|
||||
end
|
||||
describe "#after_destroy" do
|
||||
it "should called when UsersProject destroyed" do
|
||||
subject.should_receive(:after_destroy)
|
||||
UsersProject.observers.enable :users_project_observer do
|
||||
UsersProject.bulk_delete(
|
||||
users_project.project,
|
||||
[users_project.user.id]
|
||||
)
|
||||
end
|
||||
end
|
||||
it "should create new event" do
|
||||
Event.should_receive(:create).with(
|
||||
project_id: users_project.project.id,
|
||||
action: Event::Left,
|
||||
author_id: users_project.user.id
|
||||
)
|
||||
subject.after_destroy(users_project)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue