Commit a86bd87a authored by Alex Denisov's avatar Alex Denisov

User joined project event added

parent a56cec11
...@@ -179,6 +179,14 @@ span.update-author { ...@@ -179,6 +179,14 @@ span.update-author {
&.merged { &.merged {
background-color: #2A2; background-color: #2A2;
} }
&.joined {
background-color: #1cb9ff;
}
&.left {
background-color: #ff5057;
}
} }
form { form {
......
...@@ -8,7 +8,10 @@ class EventDecorator < ApplicationDecorator ...@@ -8,7 +8,10 @@ class EventDecorator < ApplicationDecorator
"#{self.author_name} #{self.action_name} MR ##{self.target_id}:" + self.merge_request_title "#{self.author_name} #{self.action_name} MR ##{self.target_id}:" + self.merge_request_title
elsif self.push? elsif self.push?
"#{self.author_name} #{self.push_action_name} #{self.ref_type} " + self.ref_name "#{self.author_name} #{self.push_action_name} #{self.ref_type} " + self.ref_name
else elsif self.joined?
"#{self.author_name} #{self.action_name} #{self.project.name}"
else
"" ""
end end
end end
......
...@@ -10,6 +10,7 @@ class Event < ActiveRecord::Base ...@@ -10,6 +10,7 @@ class Event < ActiveRecord::Base
Pushed = 5 Pushed = 5
Commented = 6 Commented = 6
Merged = 7 Merged = 7
Joined = 8 # User joined project
belongs_to :project belongs_to :project
belongs_to :target, polymorphic: true belongs_to :target, polymorphic: true
...@@ -37,7 +38,7 @@ class Event < ActiveRecord::Base ...@@ -37,7 +38,7 @@ class Event < ActiveRecord::Base
# - new issue # - new issue
# - merge request # - merge request
def allowed? def allowed?
push? || issue? || merge_request? push? || issue? || merge_request? || joined?
end end
def push? def push?
...@@ -84,6 +85,10 @@ class Event < ActiveRecord::Base ...@@ -84,6 +85,10 @@ class Event < ActiveRecord::Base
[Closed, Reopened].include?(action) [Closed, Reopened].include?(action)
end end
def joined?
action == self.class::Joined
end
def issue def issue
target if target_type == "Issue" target if target_type == "Issue"
end end
...@@ -101,6 +106,8 @@ class Event < ActiveRecord::Base ...@@ -101,6 +106,8 @@ class Event < ActiveRecord::Base
"closed" "closed"
elsif merged? elsif merged?
"merged" "merged"
elsif joined?
'joined'
else else
"opened" "opened"
end end
......
class UsersProjectObserver < ActiveRecord::Observer class UsersProjectObserver < ActiveRecord::Observer
def after_create(users_project) def after_create(users_project)
Notify.project_access_granted_email(users_project.id).deliver Notify.project_access_granted_email(users_project.id).deliver
Event.create(
project_id: users_project.project.id,
action: Event::Joined,
author_id: users_project.user.id
)
end end
def after_update(users_project) def after_update(users_project)
......
...@@ -11,3 +11,7 @@ ...@@ -11,3 +11,7 @@
.event_feed .event_feed
= render "events/event_push", event: event = render "events/event_push", event: event
- elsif event.joined?
.event_feed
= render "events/event_joined", event: event
= image_tag gravatar_icon(event.author_email), class: "avatar"
%strong #{event.author_name}
%span.event_label{class: event.action_name}= event.action_name
%strong= link_to event.project.name, event.project
%span.cgray
= time_ago_in_words(event.created_at)
ago.
...@@ -15,4 +15,9 @@ Feature: Dashboard ...@@ -15,4 +15,9 @@ Feature: Dashboard
And I click "Create Merge Request" link And I click "Create Merge Request" link
Then I see prefilled new Merge Request page 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
...@@ -109,3 +109,18 @@ Given /^I have authored merge requests$/ do ...@@ -109,3 +109,18 @@ Given /^I have authored merge requests$/ do
:author => @user, :author => @user,
:project => project2 :project => project2
end end
Given /^user with name "(.*?)" joined project "(.*?)"$/ do |user_name, project_name|
user = Factory.create(:user, {name: user_name})
project = Project.find_by_name project_name
Event.create(
project: project,
author_id: user.id,
action: Event::Joined
)
end
Then /^I should see "(.*?)" event$/ do |event_text|
page.should have_content(event_text)
end
...@@ -49,4 +49,15 @@ describe Event do ...@@ -49,4 +49,15 @@ describe Event do
it { @event.branch_name.should == "master" } it { @event.branch_name.should == "master" }
it { @event.author.should == @user } it { @event.author.should == @user }
end end
describe "New team mamber" do
let(:project) {Factory.create :project}
let(:new_user) {Factory.create :user}
it "should create event" do
UsersProject.observers.enable :users_project_observer
expect{
UsersProject.bulk_import(project, [new_user.id], UsersProject::DEVELOPER)
}.to change{Event.count}.by(1)
end
end
end end
...@@ -23,6 +23,14 @@ describe UsersProjectObserver do ...@@ -23,6 +23,14 @@ describe UsersProjectObserver do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true)) Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
subject.after_create(users_project) subject.after_create(users_project)
end end
it "should create new event" do
Event.should_receive(:create).with(
project_id: users_project.project.id,
action: Event::Joined,
author_id: users_project.user.id
)
subject.after_create(users_project)
end
end end
describe "#after_update" do describe "#after_update" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment