Commit 839c3b198e50ac38d1c647189927e18f36133518
Exists in
master
and in
4 other branches
Merge branch 'feature/email_when_added_to_group' of /home/git/repositories/gitlab/gitlabhq
Showing
11 changed files
with
102 additions
and
13 deletions
Show diff stats
| @@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
| 1 | +module Emails | ||
| 2 | + module Groups | ||
| 3 | + def group_access_granted_email(user_group_id) | ||
| 4 | + @membership = UsersGroup.find(user_group_id) | ||
| 5 | + @group = @membership.group | ||
| 6 | + | ||
| 7 | + mail(to: @membership.user.email, | ||
| 8 | + subject: subject("access to group was granted")) | ||
| 9 | + end | ||
| 10 | + end | ||
| 11 | +end |
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +module Emails | ||
| 2 | + module Profile | ||
| 3 | + def new_user_email(user_id, password) | ||
| 4 | + @user = User.find(user_id) | ||
| 5 | + @password = password | ||
| 6 | + mail(to: @user.email, subject: subject("Account was created for you")) | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + def new_ssh_key_email(key_id) | ||
| 10 | + @key = Key.find(key_id) | ||
| 11 | + @user = @key.user | ||
| 12 | + mail(to: @user.email, subject: subject("SSH key was added to your account")) | ||
| 13 | + end | ||
| 14 | + end | ||
| 15 | +end |
app/mailers/emails/projects.rb
| @@ -7,7 +7,6 @@ module Emails | @@ -7,7 +7,6 @@ module Emails | ||
| 7 | subject: subject("access to project was granted")) | 7 | subject: subject("access to project was granted")) |
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | - | ||
| 11 | def project_was_moved_email(project_id, user_id) | 10 | def project_was_moved_email(project_id, user_id) |
| 12 | @user = User.find user_id | 11 | @user = User.find user_id |
| 13 | @project = Project.find project_id | 12 | @project = Project.find project_id |
app/mailers/notify.rb
| @@ -3,6 +3,8 @@ class Notify < ActionMailer::Base | @@ -3,6 +3,8 @@ class Notify < ActionMailer::Base | ||
| 3 | include Emails::MergeRequests | 3 | include Emails::MergeRequests |
| 4 | include Emails::Notes | 4 | include Emails::Notes |
| 5 | include Emails::Projects | 5 | include Emails::Projects |
| 6 | + include Emails::Profile | ||
| 7 | + include Emails::Groups | ||
| 6 | 8 | ||
| 7 | add_template_helper ApplicationHelper | 9 | add_template_helper ApplicationHelper |
| 8 | add_template_helper GitlabMarkdownHelper | 10 | add_template_helper GitlabMarkdownHelper |
| @@ -20,18 +22,6 @@ class Notify < ActionMailer::Base | @@ -20,18 +22,6 @@ class Notify < ActionMailer::Base | ||
| 20 | delay_for(2.seconds) | 22 | delay_for(2.seconds) |
| 21 | end | 23 | end |
| 22 | 24 | ||
| 23 | - def new_user_email(user_id, password) | ||
| 24 | - @user = User.find(user_id) | ||
| 25 | - @password = password | ||
| 26 | - mail(to: @user.email, subject: subject("Account was created for you")) | ||
| 27 | - end | ||
| 28 | - | ||
| 29 | - def new_ssh_key_email(key_id) | ||
| 30 | - @key = Key.find(key_id) | ||
| 31 | - @user = @key.user | ||
| 32 | - mail(to: @user.email, subject: subject("SSH key was added to your account")) | ||
| 33 | - end | ||
| 34 | - | ||
| 35 | private | 25 | private |
| 36 | 26 | ||
| 37 | # Look up a User by their ID and return their email address | 27 | # Look up a User by their ID and return their email address |
app/services/notification_service.rb
| @@ -148,6 +148,14 @@ class NotificationService | @@ -148,6 +148,14 @@ class NotificationService | ||
| 148 | mailer.project_access_granted_email(users_project.id) | 148 | mailer.project_access_granted_email(users_project.id) |
| 149 | end | 149 | end |
| 150 | 150 | ||
| 151 | + def new_group_member(users_group) | ||
| 152 | + mailer.group_access_granted_email(users_group.id) | ||
| 153 | + end | ||
| 154 | + | ||
| 155 | + def update_group_member(users_group) | ||
| 156 | + mailer.group_access_granted_email(users_group.id) | ||
| 157 | + end | ||
| 158 | + | ||
| 151 | protected | 159 | protected |
| 152 | 160 | ||
| 153 | # Get project users with WATCH notification level | 161 | # Get project users with WATCH notification level |
config/application.rb
| @@ -32,6 +32,7 @@ module Gitlab | @@ -32,6 +32,7 @@ module Gitlab | ||
| 32 | :project_observer, | 32 | :project_observer, |
| 33 | :system_hook_observer, | 33 | :system_hook_observer, |
| 34 | :user_observer, | 34 | :user_observer, |
| 35 | + :users_group_observer, | ||
| 35 | :users_project_observer | 36 | :users_project_observer |
| 36 | 37 | ||
| 37 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. | 38 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. |
spec/mailers/notify_spec.rb
| @@ -347,4 +347,24 @@ describe Notify do | @@ -347,4 +347,24 @@ describe Notify do | ||
| 347 | end | 347 | end |
| 348 | end | 348 | end |
| 349 | end | 349 | end |
| 350 | + | ||
| 351 | + describe 'group access changed' do | ||
| 352 | + let(:group) { create(:group) } | ||
| 353 | + let(:user) { create(:user) } | ||
| 354 | + let(:membership) { create(:users_group, group: group, user: user) } | ||
| 355 | + | ||
| 356 | + subject { Notify.group_access_granted_email(membership.id) } | ||
| 357 | + | ||
| 358 | + it 'has the correct subject' do | ||
| 359 | + should have_subject /access to group was granted/ | ||
| 360 | + end | ||
| 361 | + | ||
| 362 | + it 'contains name of project' do | ||
| 363 | + should have_body_text /#{group.name}/ | ||
| 364 | + end | ||
| 365 | + | ||
| 366 | + it 'contains new user role' do | ||
| 367 | + should have_body_text /#{membership.human_access}/ | ||
| 368 | + end | ||
| 369 | + end | ||
| 350 | end | 370 | end |
| @@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe UsersGroupObserver do | ||
| 4 | + before(:each) { enable_observers } | ||
| 5 | + after(:each) { disable_observers } | ||
| 6 | + | ||
| 7 | + subject { UsersGroupObserver.instance } | ||
| 8 | + before { subject.stub(notification: mock('NotificationService').as_null_object) } | ||
| 9 | + | ||
| 10 | + describe "#after_create" do | ||
| 11 | + it "should send email to user" do | ||
| 12 | + subject.should_receive(:notification) | ||
| 13 | + create(:users_group) | ||
| 14 | + end | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + describe "#after_update" do | ||
| 18 | + before do | ||
| 19 | + @membership = create :users_group | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + it "should send email to user" do | ||
| 23 | + subject.should_receive(:notification) | ||
| 24 | + @membership.update_attribute(:group_access, UsersGroup::MASTER) | ||
| 25 | + end | ||
| 26 | + end | ||
| 27 | +end |