Commit 1f240b09ed5f9f5476a863dd2f906398e5a9f0d4
1 parent
a86bd87a
Exists in
master
and in
4 other branches
User left project event added
Showing
11 changed files
with
83 additions
and
18 deletions
Show diff stats
app/decorators/event_decorator.rb
| ... | ... | @@ -8,9 +8,8 @@ class EventDecorator < ApplicationDecorator |
| 8 | 8 | "#{self.author_name} #{self.action_name} MR ##{self.target_id}:" + self.merge_request_title |
| 9 | 9 | elsif self.push? |
| 10 | 10 | "#{self.author_name} #{self.push_action_name} #{self.ref_type} " + self.ref_name |
| 11 | - elsif self.joined? | |
| 11 | + elsif self.membership_changed? | |
| 12 | 12 | "#{self.author_name} #{self.action_name} #{self.project.name}" |
| 13 | - | |
| 14 | 13 | else |
| 15 | 14 | "" |
| 16 | 15 | end | ... | ... |
app/models/event.rb
| ... | ... | @@ -11,6 +11,7 @@ class Event < ActiveRecord::Base |
| 11 | 11 | Commented = 6 |
| 12 | 12 | Merged = 7 |
| 13 | 13 | Joined = 8 # User joined project |
| 14 | + Left = 9 # User left project | |
| 14 | 15 | |
| 15 | 16 | belongs_to :project |
| 16 | 17 | belongs_to :target, polymorphic: true |
| ... | ... | @@ -38,7 +39,7 @@ class Event < ActiveRecord::Base |
| 38 | 39 | # - new issue |
| 39 | 40 | # - merge request |
| 40 | 41 | def allowed? |
| 41 | - push? || issue? || merge_request? || joined? | |
| 42 | + push? || issue? || merge_request? || membership_changed? | |
| 42 | 43 | end |
| 43 | 44 | |
| 44 | 45 | def push? |
| ... | ... | @@ -86,7 +87,15 @@ class Event < ActiveRecord::Base |
| 86 | 87 | end |
| 87 | 88 | |
| 88 | 89 | def joined? |
| 89 | - action == self.class::Joined | |
| 90 | + action == Joined | |
| 91 | + end | |
| 92 | + | |
| 93 | + def left? | |
| 94 | + action == Left | |
| 95 | + end | |
| 96 | + | |
| 97 | + def membership_changed? | |
| 98 | + joined? || left? | |
| 90 | 99 | end |
| 91 | 100 | |
| 92 | 101 | def issue |
| ... | ... | @@ -108,6 +117,8 @@ class Event < ActiveRecord::Base |
| 108 | 117 | "merged" |
| 109 | 118 | elsif joined? |
| 110 | 119 | 'joined' |
| 120 | + elsif left? | |
| 121 | + 'left' | |
| 111 | 122 | else |
| 112 | 123 | "opened" |
| 113 | 124 | end | ... | ... |
app/models/users_project.rb
| ... | ... | @@ -23,7 +23,7 @@ class UsersProject < ActiveRecord::Base |
| 23 | 23 | def self.bulk_delete(project, user_ids) |
| 24 | 24 | UsersProject.transaction do |
| 25 | 25 | UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project| |
| 26 | - users_project.delete | |
| 26 | + users_project.destroy | |
| 27 | 27 | end |
| 28 | 28 | end |
| 29 | 29 | end | ... | ... |
app/observers/users_project_observer.rb
| ... | ... | @@ -12,4 +12,13 @@ class UsersProjectObserver < ActiveRecord::Observer |
| 12 | 12 | def after_update(users_project) |
| 13 | 13 | Notify.project_access_granted_email(users_project.id).deliver |
| 14 | 14 | end |
| 15 | + | |
| 16 | + def after_destroy(users_project) | |
| 17 | + Event.create( | |
| 18 | + project_id: users_project.project.id, | |
| 19 | + action: Event::Left, | |
| 20 | + author_id: users_project.user.id | |
| 21 | + ) | |
| 22 | + end | |
| 23 | + | |
| 15 | 24 | end | ... | ... |
app/views/events/_event.html.haml
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | .event_feed |
| 12 | 12 | = render "events/event_push", event: event |
| 13 | 13 | |
| 14 | - - elsif event.joined? | |
| 14 | + - elsif event.membership_changed? | |
| 15 | 15 | .event_feed |
| 16 | - = render "events/event_joined", event: event | |
| 16 | + = render "events/event_membership_changed", event: event | |
| 17 | 17 | ... | ... |
app/views/events/_event_joined.html.haml
| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | -= image_tag gravatar_icon(event.author_email), class: "avatar" | |
| 2 | -%strong #{event.author_name} | |
| 3 | -%span.event_label{class: event.action_name}= event.action_name | |
| 4 | -%strong= link_to event.project.name, event.project | |
| 5 | -%span.cgray | |
| 6 | - = time_ago_in_words(event.created_at) | |
| 7 | - ago. | |
| 8 | - |
| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | += image_tag gravatar_icon(event.author_email), class: "avatar" | |
| 2 | +%strong #{event.author_name} | |
| 3 | +%span.event_label{class: event.action_name}= event.action_name | |
| 4 | +project | |
| 5 | +%strong= link_to event.project.name, event.project | |
| 6 | +%span.cgray | |
| 7 | + = time_ago_in_words(event.created_at) | |
| 8 | + ago. | |
| 9 | + | ... | ... |
features/dashboard/dashboard.feature
| ... | ... | @@ -15,9 +15,14 @@ Feature: Dashboard |
| 15 | 15 | And I click "Create Merge Request" link |
| 16 | 16 | Then I see prefilled new Merge Request page |
| 17 | 17 | |
| 18 | - @current | |
| 19 | 18 | Scenario: I should see User joined Project event |
| 20 | 19 | Given user with name "John Doe" joined project "Shop" |
| 21 | 20 | When I visit dashboard page |
| 22 | - Then I should see "John Doe joined Shop" event | |
| 21 | + Then I should see "John Doe joined project Shop" event | |
| 22 | + | |
| 23 | + Scenario: I should see User left Project event | |
| 24 | + Given user with name "John Doe" joined project "Shop" | |
| 25 | + And user with name "John Doe" left project "Shop" | |
| 26 | + When I visit dashboard page | |
| 27 | + Then I should see "John Doe left project Shop" event | |
| 23 | 28 | ... | ... |
features/step_definitions/dashboard_steps.rb
| ... | ... | @@ -120,6 +120,16 @@ Given /^user with name "(.*?)" joined project "(.*?)"$/ do |user_name, project_n |
| 120 | 120 | ) |
| 121 | 121 | end |
| 122 | 122 | |
| 123 | +Given /^user with name "(.*?)" left project "(.*?)"$/ do |user_name, project_name| | |
| 124 | + user = User.find_by_name user_name | |
| 125 | + project = Project.find_by_name project_name | |
| 126 | + Event.create( | |
| 127 | + project: project, | |
| 128 | + author_id: user.id, | |
| 129 | + action: Event::Left | |
| 130 | + ) | |
| 131 | +end | |
| 132 | + | |
| 123 | 133 | Then /^I should see "(.*?)" event$/ do |event_text| |
| 124 | 134 | page.should have_content(event_text) |
| 125 | 135 | end | ... | ... |
spec/models/event_spec.rb
| ... | ... | @@ -50,7 +50,7 @@ describe Event do |
| 50 | 50 | it { @event.author.should == @user } |
| 51 | 51 | end |
| 52 | 52 | |
| 53 | - describe "New team mamber" do | |
| 53 | + describe "Joined project team" do | |
| 54 | 54 | let(:project) {Factory.create :project} |
| 55 | 55 | let(:new_user) {Factory.create :user} |
| 56 | 56 | it "should create event" do |
| ... | ... | @@ -60,4 +60,15 @@ describe Event do |
| 60 | 60 | }.to change{Event.count}.by(1) |
| 61 | 61 | end |
| 62 | 62 | end |
| 63 | + describe "Left project team" do | |
| 64 | + let(:project) {Factory.create :project} | |
| 65 | + let(:new_user) {Factory.create :user} | |
| 66 | + it "should create event" do | |
| 67 | + UsersProject.bulk_import(project, [new_user.id], UsersProject::DEVELOPER) | |
| 68 | + UsersProject.observers.enable :users_project_observer | |
| 69 | + expect{ | |
| 70 | + UsersProject.bulk_delete(project, [new_user.id]) | |
| 71 | + }.to change{Event.count}.by(1) | |
| 72 | + end | |
| 73 | + end | |
| 63 | 74 | end | ... | ... |
spec/observers/users_project_observer_spec.rb
| ... | ... | @@ -45,4 +45,23 @@ describe UsersProjectObserver do |
| 45 | 45 | subject.after_update(users_project) |
| 46 | 46 | end |
| 47 | 47 | end |
| 48 | + describe "#after_destroy" do | |
| 49 | + it "should called when UsersProject destroyed" do | |
| 50 | + subject.should_receive(:after_destroy) | |
| 51 | + UsersProject.observers.enable :users_project_observer do | |
| 52 | + UsersProject.bulk_delete( | |
| 53 | + users_project.project, | |
| 54 | + [users_project.user.id] | |
| 55 | + ) | |
| 56 | + end | |
| 57 | + end | |
| 58 | + it "should create new event" do | |
| 59 | + Event.should_receive(:create).with( | |
| 60 | + project_id: users_project.project.id, | |
| 61 | + action: Event::Left, | |
| 62 | + author_id: users_project.user.id | |
| 63 | + ) | |
| 64 | + subject.after_destroy(users_project) | |
| 65 | + end | |
| 66 | + end | |
| 48 | 67 | end | ... | ... |