summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-06-14 16:31:03 +0200
committerJames Lopez <james@jameslopez.es>2016-06-14 16:31:03 +0200
commit9ecebaaea16d206ed20a2f4fc0021a2145c873f5 (patch)
tree346f9df3661e5cd0e31116fa19270c8e0f3fc032
parentfe370b1c396cb3c290fcdb1d716a79ffe5c29169 (diff)
downloadgitlab-ce-9ecebaaea16d206ed20a2f4fc0021a2145c873f5.tar.gz
adding notifications stuff and more refactoring for exporting projects
-rw-r--r--app/controllers/import/gitlab_projects_controller.rb2
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/mailers/emails/projects.rb13
-rw-r--r--app/services/notification_service.rb8
-rw-r--r--app/services/projects/create_service.rb2
-rw-r--r--app/services/projects/import_export/export_service.rb15
-rw-r--r--app/views/notify/project_was_exported_email.html.haml8
-rw-r--r--app/views/notify/project_was_exported_email.text.erb6
-rw-r--r--app/views/notify/project_was_not_exported_email.html.haml7
-rw-r--r--app/views/notify/project_was_not_exported_email.text.erb5
-rw-r--r--app/workers/project_export_worker.rb1
-rw-r--r--lib/gitlab/gitlab_import/project_creator.rb21
-rw-r--r--lib/gitlab/import_export/project_creator.rb23
13 files changed, 84 insertions, 29 deletions
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb
index 98a9b5f1018..d4063747da4 100644
--- a/app/controllers/import/gitlab_projects_controller.rb
+++ b/app/controllers/import/gitlab_projects_controller.rb
@@ -12,7 +12,7 @@ class Import::GitlabProjectsController < Import::BaseController
return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
end
- @project = Gitlab::GitlabImport::ProjectCreator.new(Namespace.find(project_params[:namespace_id]),
+ @project = Gitlab::ImportExport::ProjectCreator.new(Namespace.find(project_params[:namespace_id]),
current_user,
File.expand_path(params[:file].path),
project_params[:path]).execute
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index a1d58144399..9a6d4be2fc8 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -190,7 +190,7 @@ class ProjectsController < Projects::ApplicationController
redirect_to(
edit_project_path(@project),
- notice: "Project export successfully started."
+ notice: "Project export started."
)
end
diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb
index fdf1e9f5afc..0d9558db68c 100644
--- a/app/mailers/emails/projects.rb
+++ b/app/mailers/emails/projects.rb
@@ -50,6 +50,19 @@ module Emails
subject: subject("Invitation declined"))
end
+ def project_was_exported_email(current_user, project)
+ @project = project
+ mail(to: current_user.notification_email,
+ subject: subject("Project was exported"))
+ end
+
+ def project_was_not_exported_email(current_user, project, errors)
+ @project = project
+ @errors = errors
+ mail(to: current_user.notification_email,
+ subject: subject("Project export error"))
+ end
+
def project_was_moved_email(project_id, user_id, old_path_with_namespace)
@current_user = @user = User.find user_id
@project = Project.find project_id
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index 91ca82ed3b7..79534a06a1d 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -246,6 +246,14 @@ class NotificationService
end
end
+ def project_exported(project, current_user)
+ mailer.project_was_exported_email(current_user, project).deliver_later
+ end
+
+ def project_not_exported(project, current_user, errors)
+ mailer.project_was_not_exported_email(current_user, project, errors).deliver_later
+ end
+
protected
# Get project users with WATCH notification level
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb
index 7e467541539..ffac357e91d 100644
--- a/app/services/projects/create_service.rb
+++ b/app/services/projects/create_service.rb
@@ -52,8 +52,6 @@ module Projects
save_project_and_import_data(import_data)
- @project.import_url = download_export_namespace_project_path(@project.namespace, @project) if @project.gitlab_project_import?
-
@project.import_start if @project.import?
after_create_actions if @project.persisted? && !@project.gitlab_project_import?
diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb
index 25524c1c060..d6752377ce5 100644
--- a/app/services/projects/import_export/export_service.rb
+++ b/app/services/projects/import_export/export_service.rb
@@ -12,8 +12,9 @@ module Projects
def save_all
if [version_saver, project_tree_saver, uploads_saver, repo_saver, wiki_repo_saver].all?(&:save)
Gitlab::ImportExport::Saver.save(shared: @shared)
+ notify_success
else
- cleanup_and_notify_worker
+ cleanup_and_notify
end
end
@@ -37,10 +38,20 @@ module Projects
Gitlab::ImportExport::WikiRepoSaver.new(project: project, shared: @shared)
end
- def cleanup_and_notify_worker
+ def cleanup_and_notify
FileUtils.rm_rf(@shared.export_path)
+
+ notify_error
raise Gitlab::ImportExport::Error.new(@shared.errors.join(', '))
end
+
+ def notify_success
+ notification_service.project_exported(@project, @current_user)
+ end
+
+ def notify_error
+ notification_service.project_not_exported(@project, @current_user, @shared.errors.join(', '))
+ end
end
end
end
diff --git a/app/views/notify/project_was_exported_email.html.haml b/app/views/notify/project_was_exported_email.html.haml
new file mode 100644
index 00000000000..fb6f4ac3efc
--- /dev/null
+++ b/app/views/notify/project_was_exported_email.html.haml
@@ -0,0 +1,8 @@
+%p
+ Project #{@project.name} was exported succesfully
+%p
+ The project export can be downloaded from:
+ = link_to download_export_namespace_project_url(@project.namespace, @project) do
+ = @project.name_with_namespace + " export"
+%p
+ The download link will expire in 24 hours.
diff --git a/app/views/notify/project_was_exported_email.text.erb b/app/views/notify/project_was_exported_email.text.erb
new file mode 100644
index 00000000000..fcd801c237c
--- /dev/null
+++ b/app/views/notify/project_was_exported_email.text.erb
@@ -0,0 +1,6 @@
+Project <%= @project.name %> was exported succesfully
+
+The project export can be downloaded from:
+<%= download_export_namespace_project_url(@project.namespace, @project) %>
+
+The download link will expire in 24 hours.
diff --git a/app/views/notify/project_was_not_exported_email.html.haml b/app/views/notify/project_was_not_exported_email.html.haml
new file mode 100644
index 00000000000..78d4751b64a
--- /dev/null
+++ b/app/views/notify/project_was_not_exported_email.html.haml
@@ -0,0 +1,7 @@
+%p
+ Project #{@project.name} couldn't be exported.
+%p
+ The errors we encountered were:
+
+ %h3{style: "background: black; color: red;"}
+ #{@errors}
diff --git a/app/views/notify/project_was_not_exported_email.text.erb b/app/views/notify/project_was_not_exported_email.text.erb
new file mode 100644
index 00000000000..ad730d2162b
--- /dev/null
+++ b/app/views/notify/project_was_not_exported_email.text.erb
@@ -0,0 +1,5 @@
+Project <%= @project.name %> couldn't be exported.
+
+The errors we encountered were:
+
+<%= @errors %>
diff --git a/app/workers/project_export_worker.rb b/app/workers/project_export_worker.rb
index 3616b37d2ad..d2dcdb46219 100644
--- a/app/workers/project_export_worker.rb
+++ b/app/workers/project_export_worker.rb
@@ -7,6 +7,7 @@ class ProjectExportWorker
def perform(current_user_id, project_id)
current_user = User.find(current_user_id)
project = Project.find(project_id)
+
::Projects::ImportExport::ExportService.new(project, current_user).execute
end
end
diff --git a/lib/gitlab/gitlab_import/project_creator.rb b/lib/gitlab/gitlab_import/project_creator.rb
index 72b10f536ec..3d0418261bb 100644
--- a/lib/gitlab/gitlab_import/project_creator.rb
+++ b/lib/gitlab/gitlab_import/project_creator.rb
@@ -3,21 +3,24 @@ module Gitlab
class ProjectCreator
attr_reader :repo, :namespace, :current_user, :session_data
- def initialize(namespace_id, current_user, file, project_path)
- @namespace_id = namespace_id
+ def initialize(repo, namespace, current_user, session_data)
+ @repo = repo
+ @namespace = namespace
@current_user = current_user
- @file = file
- @project_path = project_path
+ @session_data = session_data
end
def execute
::Projects::CreateService.new(
current_user,
- name: @project_path,
- path: @project_path,
- namespace_id: namespace_id,
- import_type: "gitlab_project",
- import_source: @file
+ name: repo["name"],
+ path: repo["path"],
+ description: repo["description"],
+ namespace_id: namespace.id,
+ visibility_level: repo["visibility_level"],
+ import_type: "gitlab",
+ import_source: repo["path_with_namespace"],
+ import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
).execute
end
end
diff --git a/lib/gitlab/import_export/project_creator.rb b/lib/gitlab/import_export/project_creator.rb
index 801d4b4f43a..6f1e3867efb 100644
--- a/lib/gitlab/import_export/project_creator.rb
+++ b/lib/gitlab/import_export/project_creator.rb
@@ -2,26 +2,21 @@ module Gitlab
module ImportExport
class ProjectCreator
- def initialize(namespace_id, current_user)
- @repo = repo
- @namespace = Namespace.find_by_id(namespace_id)
+ def initialize(namespace_id, current_user, file, project_path)
+ @namespace_id = namespace_id
@current_user = current_user
- @user_map = user_map
+ @file = file
+ @project_path = project_path
end
def execute
::Projects::CreateService.new(
current_user,
- name: repo.name,
- path: repo.name,
- description: repo.summary,
- namespace: namespace,
- creator: current_user,
- visibility_level: Gitlab::VisibilityLevel::PUBLIC,
- import_type: "google_code",
- import_source: repo.name,
- import_url: repo.import_url,
- import_data: { data: { 'repo' => repo.raw_data, 'user_map' => user_map } }
+ name: @project_path,
+ path: @project_path,
+ namespace_id: namespace_id,
+ import_type: "gitlab_project",
+ import_source: @file
).execute
end
end