Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-05-08 16:07:55 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-05-10 18:02:27 +0300
commitf7f13f9db0da92c7b43481dfe5559f317711e533 (patch)
tree59359aecb555f844de1a81a0aebbd70336fbb8c1 /lib/gitlab/auth
parentf667bbceaba7556d5fb2adadce4b7d170b914e8a (diff)
Block access to API & git when terms are enforced
When terms are enforced, but the user has not accepted the terms access to the API & git is rejected with a message directing the user to the web app to accept the terms.
Diffstat (limited to 'lib/gitlab/auth')
-rw-r--r--lib/gitlab/auth/user_access_denied_reason.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/auth/user_access_denied_reason.rb b/lib/gitlab/auth/user_access_denied_reason.rb
new file mode 100644
index 00000000000..af310aa12fc
--- /dev/null
+++ b/lib/gitlab/auth/user_access_denied_reason.rb
@@ -0,0 +1,33 @@
+module Gitlab
+ module Auth
+ class UserAccessDeniedReason
+ def initialize(user)
+ @user = user
+ end
+
+ def rejection_message
+ case rejection_type
+ when :internal
+ 'This action cannot be performed by internal users'
+ when :terms_not_accepted
+ 'You must accept the Terms of Service in order to perform this action. '\
+ 'Please access GitLab from a web browser to accept these terms.'
+ else
+ 'Your account has been blocked.'
+ end
+ end
+
+ private
+
+ def rejection_type
+ if @user.internal?
+ :internal
+ elsif @user.required_terms_not_accepted?
+ :terms_not_accepted
+ else
+ :blocked
+ end
+ end
+ end
+ end
+end