summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-13 12:05:17 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-13 12:05:17 +0000
commit8ad91d58405296a6d0b4cec7b2f18b2a2728c717 (patch)
tree97af74c181955b5523c251c3e929400b28b57643 /lib
parent5dcbe6f4baa0298a14592ad06763e26e12399e64 (diff)
parentc5e4b443ffdc1c094450d08d29bd96e43376d6d7 (diff)
downloadgitlab-ce-8ad91d58405296a6d0b4cec7b2f18b2a2728c717.tar.gz
Merge branch 'text-batch-1' into 'master'
Batch 1 of text improvements Batch 1 of changes from my effort at !635 to walk through every piece of text in GitLab and see if it can be improved. This batch includes: - Improve text on error pages. - Improve Git access error messages. - Improve description of branch protection levels. - Improve OAuth signup error message. - Improve OAuth application flash messages. cc @rspeicher See merge request !642
Diffstat (limited to 'lib')
-rw-r--r--lib/api/internal.rb26
-rw-r--r--lib/gitlab/access.rb6
-rw-r--r--lib/gitlab/git_access.rb62
-rw-r--r--lib/gitlab/git_access_wiki.rb2
-rw-r--r--lib/gitlab/o_auth/user.rb4
5 files changed, 50 insertions, 50 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index f98a17773e7..e38736fc28b 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -24,10 +24,6 @@ module API
User.find_by(id: params[:user_id])
end
- unless actor
- return Gitlab::GitAccessStatus.new(false, 'No such user or key')
- end
-
project_path = params[:project]
# Check for *.wiki repositories.
@@ -39,22 +35,14 @@ module API
project = Project.find_with_namespace(project_path)
- if project
- access =
- if wiki
- Gitlab::GitAccessWiki.new(actor, project)
- else
- Gitlab::GitAccess.new(actor, project)
- end
-
- status = access.check(params[:action], params[:changes])
- end
+ access =
+ if wiki
+ Gitlab::GitAccessWiki.new(actor, project)
+ else
+ Gitlab::GitAccess.new(actor, project)
+ end
- if project && access.can_read_project?
- status
- else
- Gitlab::GitAccessStatus.new(false, 'No such project')
- end
+ access.check(params[:action], params[:changes])
end
#
diff --git a/lib/gitlab/access.rb b/lib/gitlab/access.rb
index 424541b4a04..6d0e30e916f 100644
--- a/lib/gitlab/access.rb
+++ b/lib/gitlab/access.rb
@@ -51,9 +51,9 @@ module Gitlab
def protection_options
{
- "Not protected, developers and masters can (force) push and delete the branch" => PROTECTION_NONE,
- "Partially protected, developers can also push but prevent all force pushes and deletion" => PROTECTION_DEV_CAN_PUSH,
- "Fully protected, only masters can push and prevent all force pushes and deletion" => PROTECTION_FULL,
+ "Not protected: Both developers and masters can push new commits, force push, or delete the branch." => PROTECTION_NONE,
+ "Partially protected: Developers can push new commits, but cannot force push or delete the branch. Masters can do all of those." => PROTECTION_DEV_CAN_PUSH,
+ "Fully protected: Developers cannot push new commits, force push, or delete the branch. Only masters can do any of those." => PROTECTION_FULL,
}
end
diff --git a/lib/gitlab/git_access.rb b/lib/gitlab/git_access.rb
index bc72b7528d5..c90184d31cf 100644
--- a/lib/gitlab/git_access.rb
+++ b/lib/gitlab/git_access.rb
@@ -31,8 +31,7 @@ module Gitlab
def can_push_to_branch?(ref)
return false unless user
- if project.protected_branch?(ref) &&
- !(project.developers_can_push_to_protected_branch?(ref) && project.team.developer?(user))
+ if project.protected_branch?(ref) && !project.developers_can_push_to_protected_branch?(ref)
user.can?(:push_code_to_protected_branches, project)
else
user.can?(:push_code, project)
@@ -50,13 +49,25 @@ module Gitlab
end
def check(cmd, changes = nil)
+ unless actor
+ return build_status_object(false, "No user or key was provided.")
+ end
+
+ if user && !user_allowed?
+ return build_status_object(false, "Your account has been blocked.")
+ end
+
+ unless project && can_read_project?
+ return build_status_object(false, 'The project you were looking for could not be found.')
+ end
+
case cmd
when *DOWNLOAD_COMMANDS
download_access_check
when *PUSH_COMMANDS
push_access_check(changes)
else
- build_status_object(false, "Wrong command")
+ build_status_object(false, "The command you're trying to execute is not allowed.")
end
end
@@ -64,7 +75,7 @@ module Gitlab
if user
user_download_access_check
elsif deploy_key
- deploy_key_download_access_check
+ build_status_object(true)
else
raise 'Wrong actor'
end
@@ -74,39 +85,27 @@ module Gitlab
if user
user_push_access_check(changes)
elsif deploy_key
- build_status_object(false, "Deploy key not allowed to push")
+ build_status_object(false, "Deploy keys are not allowed to push code.")
else
raise 'Wrong actor'
end
end
def user_download_access_check
- if user && user_allowed? && user.can?(:download_code, project)
- build_status_object(true)
- else
- build_status_object(false, "You don't have access")
+ unless user.can?(:download_code, project)
+ return build_status_object(false, "You are not allowed to download code from this project.")
end
- end
- def deploy_key_download_access_check
- if can_read_project?
- build_status_object(true)
- else
- build_status_object(false, "Deploy key not allowed to access this project")
- end
+ build_status_object(true)
end
def user_push_access_check(changes)
- unless user && user_allowed?
- return build_status_object(false, "You don't have access")
- end
-
if changes.blank?
return build_status_object(true)
end
unless project.repository.exists?
- return build_status_object(false, "Repository does not exist")
+ return build_status_object(false, "A repository for this project does not exist yet.")
end
changes = changes.lines if changes.kind_of?(String)
@@ -136,11 +135,24 @@ module Gitlab
:push_code
end
- if user.can?(action, project)
- build_status_object(true)
- else
- build_status_object(false, "You don't have permission")
+ unless user.can?(action, project)
+ status =
+ case action
+ when :force_push_code_to_protected_branches
+ build_status_object(false, "You are not allowed to force push code to a protected branch on this project.")
+ when :remove_protected_branches
+ build_status_object(false, "You are not allowed to deleted protected branches from this project.")
+ when :push_code_to_protected_branches
+ build_status_object(false, "You are not allowed to push code to protected branches on this project.")
+ when :admin_project
+ build_status_object(false, "You are not allowed to change existing tags on this project.")
+ else # :push_code
+ build_status_object(false, "You are not allowed to push code to this project.")
+ end
+ return status
end
+
+ build_status_object(true)
end
def forced_push?(oldrev, newrev)
diff --git a/lib/gitlab/git_access_wiki.rb b/lib/gitlab/git_access_wiki.rb
index 73d99b96202..8ba97184e69 100644
--- a/lib/gitlab/git_access_wiki.rb
+++ b/lib/gitlab/git_access_wiki.rb
@@ -4,7 +4,7 @@ module Gitlab
if user.can?(:write_wiki, project)
build_status_object(true)
else
- build_status_object(false, "You don't have access")
+ build_status_object(false, "You are not allowed to write to this project's wiki.")
end
end
end
diff --git a/lib/gitlab/o_auth/user.rb b/lib/gitlab/o_auth/user.rb
index 2f5c217d764..ba5caed6131 100644
--- a/lib/gitlab/o_auth/user.rb
+++ b/lib/gitlab/o_auth/user.rb
@@ -5,7 +5,7 @@
#
module Gitlab
module OAuth
- class ForbiddenAction < StandardError; end
+ class SignupDisabledError < StandardError; end
class User
attr_accessor :auth_hash, :gl_user
@@ -99,7 +99,7 @@ module Gitlab
end
def unauthorized_to_create
- raise ForbiddenAction.new("Unauthorized to create user, signup disabled for #{auth_hash.provider}")
+ raise SignupDisabledError
end
end
end