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 @@ |
| 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 @@ |
| 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
app/mailers/notify.rb
| ... | ... | @@ -3,6 +3,8 @@ class Notify < ActionMailer::Base |
| 3 | 3 | include Emails::MergeRequests |
| 4 | 4 | include Emails::Notes |
| 5 | 5 | include Emails::Projects |
| 6 | + include Emails::Profile | |
| 7 | + include Emails::Groups | |
| 6 | 8 | |
| 7 | 9 | add_template_helper ApplicationHelper |
| 8 | 10 | add_template_helper GitlabMarkdownHelper |
| ... | ... | @@ -20,18 +22,6 @@ class Notify < ActionMailer::Base |
| 20 | 22 | delay_for(2.seconds) |
| 21 | 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 | 25 | private |
| 36 | 26 | |
| 37 | 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 | 148 | mailer.project_access_granted_email(users_project.id) |
| 149 | 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 | 159 | protected |
| 152 | 160 | |
| 153 | 161 | # Get project users with WATCH notification level | ... | ... |
config/application.rb
spec/mailers/notify_spec.rb
| ... | ... | @@ -347,4 +347,24 @@ describe Notify do |
| 347 | 347 | end |
| 348 | 348 | end |
| 349 | 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 | 370 | end | ... | ... |
| ... | ... | @@ -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 | ... | ... |