在我自己托管的 GitLab CE 安装中,有一个 Explore 链接,这样就可以为没有登录的用户提供读取权限。我怎样才能禁用它?
1433 次
3 回答
1
您无法禁用此链接,但可以将其重定向回匿名用户的登录页面。
cd /opt/gitlab/embedded/service/gitlab-rails/app/controllers/
sudo cp application_controller.rb application_controller.rb.orig
sudo vim application_controller.rb
并将以下代码片段添加到 application_controller.rb
...
before_action :force_authenticated_user!
...
def force_authenticated_user!(*args)
if (!current_user) and (["/explore", "/help", "/public", "/users/password/new", "/users/password/edit"].include?(request.path))
redirect_to new_user_session_path and return
end
end
...
或所有路径的更好方法(带有子目录):
...
before_action :force_authenticated_user!
...
def force_authenticated_user!(*args)
if (!current_user) and (["/users/sign_in", "/users/password","/uploads/-/system/appearance/header_logo/1/your_logo.PNG","/users/auth/ldapmain/callback"].exclude?(request.path))
redirect_to new_user_session_path and return
end
end
...
于 2018-05-09T20:26:49.957 回答
