summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 18:08:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 18:08:19 +0000
commita8de96bff51846e160b76506dc0ca0fe6f767f64 (patch)
tree1036f1ca75aba492eaaa3439c84a3109b4684896 /app/services
parentafe2b984524ae4b0c8a0636db7ec5b2c452f0734 (diff)
downloadgitlab-ce-a8de96bff51846e160b76506dc0ca0fe6f767f64.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/groups/import_export/export_service.rb14
-rw-r--r--app/services/groups/import_export/import_service.rb43
-rw-r--r--app/services/merge_requests/merge_to_ref_service.rb2
-rw-r--r--app/services/metrics/dashboard/clone_dashboard_service.rb2
-rw-r--r--app/services/metrics/dashboard/update_dashboard_service.rb2
-rw-r--r--app/services/projects/import_export/export_service.rb4
6 files changed, 46 insertions, 21 deletions
diff --git a/app/services/groups/import_export/export_service.rb b/app/services/groups/import_export/export_service.rb
index aa484e7203c..0bf54844430 100644
--- a/app/services/groups/import_export/export_service.rb
+++ b/app/services/groups/import_export/export_service.rb
@@ -11,11 +11,7 @@ module Groups
end
def execute
- unless @current_user.can?(:admin_group, @group)
- raise ::Gitlab::ImportExport::Error.new(
- "User with ID: %s does not have permission to Group %s with ID: %s." %
- [@current_user.id, @group.name, @group.id])
- end
+ validate_user_permissions
save!
ensure
@@ -26,6 +22,14 @@ module Groups
attr_accessor :shared
+ def validate_user_permissions
+ unless @current_user.can?(:admin_group, @group)
+ @shared.error(::Gitlab::ImportExport::Error.permission_error(@current_user, @group))
+
+ notify_error!
+ end
+ end
+
def save!
if savers.all?(&:save)
notify_success
diff --git a/app/services/groups/import_export/import_service.rb b/app/services/groups/import_export/import_service.rb
index 57d2d9855d1..548a4a98dc1 100644
--- a/app/services/groups/import_export/import_service.rb
+++ b/app/services/groups/import_export/import_service.rb
@@ -12,15 +12,14 @@ module Groups
end
def execute
- validate_user_permissions
+ if valid_user_permissions? && import_file && restorer.restore
+ notify_success
- if import_file && restorer.restore
@group
else
- raise StandardError.new(@shared.errors.to_sentence)
+ notify_error!
end
- rescue => e
- raise StandardError.new(e.message)
+
ensure
remove_import_file
end
@@ -49,13 +48,37 @@ module Groups
upload.save!
end
- def validate_user_permissions
- unless current_user.can?(:admin_group, group)
- raise ::Gitlab::ImportExport::Error.new(
- "User with ID: %s does not have permission to Group %s with ID: %s." %
- [current_user.id, group.name, group.id])
+ def valid_user_permissions?
+ if current_user.can?(:admin_group, group)
+ true
+ else
+ @shared.error(::Gitlab::ImportExport::Error.permission_error(current_user, group))
+
+ false
end
end
+
+ def notify_success
+ @shared.logger.info(
+ group_id: @group.id,
+ group_name: @group.name,
+ message: 'Group Import/Export: Import succeeded'
+ )
+ end
+
+ def notify_error
+ @shared.logger.error(
+ group_id: @group.id,
+ group_name: @group.name,
+ message: "Group Import/Export: Errors occurred, see '#{Gitlab::ErrorTracking::Logger.file_name}' for details"
+ )
+ end
+
+ def notify_error!
+ notify_error
+
+ raise Gitlab::ImportExport::Error.new(@shared.errors.to_sentence)
+ end
end
end
end
diff --git a/app/services/merge_requests/merge_to_ref_service.rb b/app/services/merge_requests/merge_to_ref_service.rb
index 37b5805ae7e..1876b1096fe 100644
--- a/app/services/merge_requests/merge_to_ref_service.rb
+++ b/app/services/merge_requests/merge_to_ref_service.rb
@@ -60,7 +60,7 @@ module MergeRequests
def commit
repository.merge_to_ref(current_user, source, merge_request, target_ref, commit_message, first_parent_ref)
- rescue Gitlab::Git::PreReceiveError => error
+ rescue Gitlab::Git::PreReceiveError, Gitlab::Git::CommandError => error
raise MergeError, error.message
end
end
diff --git a/app/services/metrics/dashboard/clone_dashboard_service.rb b/app/services/metrics/dashboard/clone_dashboard_service.rb
index 990dc462432..2720bfdafcd 100644
--- a/app/services/metrics/dashboard/clone_dashboard_service.rb
+++ b/app/services/metrics/dashboard/clone_dashboard_service.rb
@@ -24,7 +24,7 @@ module Metrics
def execute
catch(:error) do
- throw(:error, error(_(%q(You can't commit to this project)), :forbidden)) unless push_authorized?
+ throw(:error, error(_(%q(You are not allowed to push into this branch. Create another branch or open a merge request.)), :forbidden)) unless push_authorized?
result = ::Files::CreateService.new(project, current_user, dashboard_attrs).execute
throw(:error, wrap_error(result)) unless result[:status] == :success
diff --git a/app/services/metrics/dashboard/update_dashboard_service.rb b/app/services/metrics/dashboard/update_dashboard_service.rb
index 316563ecbe7..e29fc47678f 100644
--- a/app/services/metrics/dashboard/update_dashboard_service.rb
+++ b/app/services/metrics/dashboard/update_dashboard_service.rb
@@ -9,7 +9,7 @@ module Metrics
def execute
catch(:error) do
- throw(:error, error(_(%q(You can't commit to this project)), :forbidden)) unless push_authorized?
+ throw(:error, error(_(%q(You are not allowed to push into this branch. Create another branch or open a merge request.)), :forbidden)) unless push_authorized?
result = ::Files::UpdateService.new(project, current_user, dashboard_attrs).execute
throw(:error, result.merge(http_status: :bad_request)) unless result[:status] == :success
diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb
index 77fddc44085..5a3eb4c2156 100644
--- a/app/services/projects/import_export/export_service.rb
+++ b/app/services/projects/import_export/export_service.rb
@@ -5,9 +5,7 @@ module Projects
class ExportService < BaseService
def execute(after_export_strategy = nil, options = {})
unless project.template_source? || can?(current_user, :admin_project, project)
- raise ::Gitlab::ImportExport::Error.new(
- "User with ID: %s does not have permission to Project %s with ID: %s." %
- [current_user.id, project.name, project.id])
+ raise ::Gitlab::ImportExport::Error.permission_error(current_user, project)
end
@shared = project.import_export_shared