Commit 75dd7042940cc6fe7532d42612e1b0db0729a86d
1 parent
d188adfd
Exists in
master
and in
4 other branches
Send update instructions after project namespace id changed or namespace path changed
Showing
5 changed files
with
47 additions
and
2 deletions
Show diff stats
app/mailers/notify.rb
@@ -102,6 +102,12 @@ class Notify < ActionMailer::Base | @@ -102,6 +102,12 @@ class Notify < ActionMailer::Base | ||
102 | end | 102 | end |
103 | 103 | ||
104 | 104 | ||
105 | + def project_was_moved_email(user_project_id) | ||
106 | + @users_project = UsersProject.find user_project_id | ||
107 | + @project = @users_project.project | ||
108 | + mail(to: @users_project.user.email, | ||
109 | + subject: subject("project was moved")) | ||
110 | + end | ||
105 | 111 | ||
106 | # | 112 | # |
107 | # User | 113 | # User |
app/models/namespace.rb
@@ -59,7 +59,10 @@ class Namespace < ActiveRecord::Base | @@ -59,7 +59,10 @@ class Namespace < ActiveRecord::Base | ||
59 | if File.exists?(new_path) | 59 | if File.exists?(new_path) |
60 | raise "Already exists" | 60 | raise "Already exists" |
61 | end | 61 | end |
62 | - system("mv #{old_path} #{new_path}") | 62 | + |
63 | + if system("mv #{old_path} #{new_path}") | ||
64 | + send_update_instructions | ||
65 | + end | ||
63 | end | 66 | end |
64 | end | 67 | end |
65 | 68 | ||
@@ -67,4 +70,8 @@ class Namespace < ActiveRecord::Base | @@ -67,4 +70,8 @@ class Namespace < ActiveRecord::Base | ||
67 | dir_path = File.join(Gitlab.config.gitolite.repos_path, path) | 70 | dir_path = File.join(Gitlab.config.gitolite.repos_path, path) |
68 | system("rm -rf #{dir_path}") | 71 | system("rm -rf #{dir_path}") |
69 | end | 72 | end |
73 | + | ||
74 | + def send_update_instructions | ||
75 | + projects.each(&:send_move_instructions) | ||
76 | + end | ||
70 | end | 77 | end |
app/models/project.rb
@@ -259,4 +259,10 @@ class Project < ActiveRecord::Base | @@ -259,4 +259,10 @@ class Project < ActiveRecord::Base | ||
259 | merge_requests | 259 | merge_requests |
260 | end | 260 | end |
261 | end | 261 | end |
262 | + | ||
263 | + def send_move_instructions | ||
264 | + self.users_projects.each do |member| | ||
265 | + Notify.project_was_moved_email(member.id).deliver | ||
266 | + end | ||
267 | + end | ||
262 | end | 268 | end |
app/observers/project_observer.rb
@@ -3,7 +3,8 @@ class ProjectObserver < ActiveRecord::Observer | @@ -3,7 +3,8 @@ class ProjectObserver < ActiveRecord::Observer | ||
3 | project.update_repository | 3 | project.update_repository |
4 | end | 4 | end |
5 | 5 | ||
6 | - def after_save(project) | 6 | + def after_update(project) |
7 | + project.send_move_instructions if project.namespace_id_changed? | ||
7 | end | 8 | end |
8 | 9 | ||
9 | def after_destroy(project) | 10 | def after_destroy(project) |
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +%td.content{align: "left", style: "font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;", valign: "top", width: "600"} | ||
2 | + %table{border: "0", cellpadding: "0", cellspacing: "0", style: "color: #555; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;", width: "600"} | ||
3 | + %tr | ||
4 | + %td{width: "21"} | ||
5 | + %td | ||
6 | + %h3 | ||
7 | + = "Project was moved in another location" | ||
8 | + %td{width: "21"} | ||
9 | + %tr | ||
10 | + %td{width: "21"} | ||
11 | + %td | ||
12 | + %p | ||
13 | + Project is now accessible via next link | ||
14 | + = link_to project_url(@project) do | ||
15 | + = @project.name_with_namespace | ||
16 | + %p | ||
17 | + You may want to update your local repository with new remote: | ||
18 | + %br | ||
19 | + %table{border: "0", cellpadding: "0", cellspacing: "0", width: "558"} | ||
20 | + %tr | ||
21 | + %td{valign: "top"} | ||
22 | + %p{ style: "background:#f5f5f5; padding:10px; border:1px solid #ddd" } | ||
23 | + git remote set-url origin #{@project.ssh_url_to_repo} | ||
24 | + %br | ||
25 | + %td{ width: "21"} |