diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-12 18:40:41 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-12 18:40:41 +0000 |
commit | 839c3b198e50ac38d1c647189927e18f36133518 (patch) | |
tree | 79041e4c3b20fabe57d79c9486456b2664e2febe | |
parent | 069a6dfa9152dc61042bc3385651e9a81c8d3392 (diff) | |
parent | c1dd31cf8bd98ec1a8d951fa6211bfa799233650 (diff) | |
download | gitlab-ce-839c3b198e50ac38d1c647189927e18f36133518.tar.gz |
Merge branch 'feature/email_when_added_to_group' of /home/git/repositories/gitlab/gitlabhq
-rw-r--r-- | app/mailers/emails/groups.rb | 11 | ||||
-rw-r--r-- | app/mailers/emails/profile.rb | 15 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 1 | ||||
-rw-r--r-- | app/mailers/notify.rb | 14 | ||||
-rw-r--r-- | app/observers/users_group_observer.rb | 9 | ||||
-rw-r--r-- | app/services/notification_service.rb | 8 | ||||
-rw-r--r-- | app/views/notify/group_access_granted_email.html.haml | 5 | ||||
-rw-r--r-- | app/views/notify/group_access_granted_email.text.erb | 4 | ||||
-rw-r--r-- | config/application.rb | 1 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 20 | ||||
-rw-r--r-- | spec/observers/users_group_observer_spec.rb | 27 |
11 files changed, 102 insertions, 13 deletions
diff --git a/app/mailers/emails/groups.rb b/app/mailers/emails/groups.rb new file mode 100644 index 00000000000..2e9d28981e3 --- /dev/null +++ b/app/mailers/emails/groups.rb @@ -0,0 +1,11 @@ +module Emails + module Groups + def group_access_granted_email(user_group_id) + @membership = UsersGroup.find(user_group_id) + @group = @membership.group + + mail(to: @membership.user.email, + subject: subject("access to group was granted")) + end + end +end diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb new file mode 100644 index 00000000000..bcd44f9476c --- /dev/null +++ b/app/mailers/emails/profile.rb @@ -0,0 +1,15 @@ +module Emails + module Profile + def new_user_email(user_id, password) + @user = User.find(user_id) + @password = password + mail(to: @user.email, subject: subject("Account was created for you")) + end + + def new_ssh_key_email(key_id) + @key = Key.find(key_id) + @user = @key.user + mail(to: @user.email, subject: subject("SSH key was added to your account")) + end + end +end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 1ad7ca588bd..4d5fe9ef614 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -7,7 +7,6 @@ module Emails subject: subject("access to project was granted")) end - def project_was_moved_email(project_id, user_id) @user = User.find user_id @project = Project.find project_id diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 7890ca7793b..2f7be00c33e 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -3,6 +3,8 @@ class Notify < ActionMailer::Base include Emails::MergeRequests include Emails::Notes include Emails::Projects + include Emails::Profile + include Emails::Groups add_template_helper ApplicationHelper add_template_helper GitlabMarkdownHelper @@ -20,18 +22,6 @@ class Notify < ActionMailer::Base delay_for(2.seconds) end - def new_user_email(user_id, password) - @user = User.find(user_id) - @password = password - mail(to: @user.email, subject: subject("Account was created for you")) - end - - def new_ssh_key_email(key_id) - @key = Key.find(key_id) - @user = @key.user - mail(to: @user.email, subject: subject("SSH key was added to your account")) - end - private # Look up a User by their ID and return their email address diff --git a/app/observers/users_group_observer.rb b/app/observers/users_group_observer.rb new file mode 100644 index 00000000000..ecdbede89d9 --- /dev/null +++ b/app/observers/users_group_observer.rb @@ -0,0 +1,9 @@ +class UsersGroupObserver < BaseObserver + def after_create(membership) + notification.new_group_member(membership) + end + + def after_update(membership) + notification.update_group_member(membership) + end +end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index c20b07e69f0..71c25dc1b70 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -148,6 +148,14 @@ class NotificationService mailer.project_access_granted_email(users_project.id) end + def new_group_member(users_group) + mailer.group_access_granted_email(users_group.id) + end + + def update_group_member(users_group) + mailer.group_access_granted_email(users_group.id) + end + protected # Get project users with WATCH notification level diff --git a/app/views/notify/group_access_granted_email.html.haml b/app/views/notify/group_access_granted_email.html.haml new file mode 100644 index 00000000000..5023ec737a5 --- /dev/null +++ b/app/views/notify/group_access_granted_email.html.haml @@ -0,0 +1,5 @@ +%p + = "You have been granted #{@membership.human_access} access to group" +%p + = link_to group_url(@group) do + = @group.name diff --git a/app/views/notify/group_access_granted_email.text.erb b/app/views/notify/group_access_granted_email.text.erb new file mode 100644 index 00000000000..331bb98d5c9 --- /dev/null +++ b/app/views/notify/group_access_granted_email.text.erb @@ -0,0 +1,4 @@ + +You have been granted <%= @membership.human_access %> access to group <%= @group.name %> + +<%= url_for(group_url(@group)) %> diff --git a/config/application.rb b/config/application.rb index f7349fa009b..8ac07ef337a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -32,6 +32,7 @@ module Gitlab :project_observer, :system_hook_observer, :user_observer, + :users_group_observer, :users_project_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 2f0475e5f02..0787bdbea6f 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -347,4 +347,24 @@ describe Notify do end end end + + describe 'group access changed' do + let(:group) { create(:group) } + let(:user) { create(:user) } + let(:membership) { create(:users_group, group: group, user: user) } + + subject { Notify.group_access_granted_email(membership.id) } + + it 'has the correct subject' do + should have_subject /access to group was granted/ + end + + it 'contains name of project' do + should have_body_text /#{group.name}/ + end + + it 'contains new user role' do + should have_body_text /#{membership.human_access}/ + end + end end diff --git a/spec/observers/users_group_observer_spec.rb b/spec/observers/users_group_observer_spec.rb new file mode 100644 index 00000000000..3bf562edbb7 --- /dev/null +++ b/spec/observers/users_group_observer_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe UsersGroupObserver do + before(:each) { enable_observers } + after(:each) { disable_observers } + + subject { UsersGroupObserver.instance } + before { subject.stub(notification: mock('NotificationService').as_null_object) } + + describe "#after_create" do + it "should send email to user" do + subject.should_receive(:notification) + create(:users_group) + end + end + + describe "#after_update" do + before do + @membership = create :users_group + end + + it "should send email to user" do + subject.should_receive(:notification) + @membership.update_attribute(:group_access, UsersGroup::MASTER) + end + end +end |