Skip to content
代码片段 群组 项目
未验证 提交 12bfdf4e 编辑于 作者: Brian Williams's avatar Brian Williams 提交者: GitLab
浏览文件

Merge branch 'kkloss-hook-logs-with-admin_hook-permission' into 'master'

Allow viewing webhook logs with admin_hook permission

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/153806



Merged-by: default avatarBrian Williams <bwilliams@gitlab.com>
Approved-by: default avatarLee Tickett <ltickett@gitlab.com>
Approved-by: default avatarBrian Williams <bwilliams@gitlab.com>
Approved-by: default avatarAlex Buijs <abuijs@gitlab.com>
Reviewed-by: default avatarAlex Buijs <abuijs@gitlab.com>
Reviewed-by: default avatarLee Tickett <ltickett@gitlab.com>
Co-authored-by: default avatarKev Kloss <kkloss@gitlab.com>
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true # frozen_string_literal: true
class Projects::HookLogsController < Projects::ApplicationController class Projects::HookLogsController < Projects::ApplicationController
before_action :authorize_admin_project! before_action :authorize_admin_hook!
include WebHooks::HookLogActions include WebHooks::HookLogActions
...@@ -16,4 +16,8 @@ def hook ...@@ -16,4 +16,8 @@ def hook
def after_retry_redirect_path def after_retry_redirect_path
edit_project_hook_path(@project, hook) edit_project_hook_path(@project, hook)
end end
def authorize_admin_hook!
render_404 unless can?(current_user, :admin_web_hook, project)
end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Groups module Groups
class HookLogsController < Groups::ApplicationController class HookLogsController < Groups::ApplicationController
before_action :authorize_admin_group! before_action :authorize_admin_hook!
include ::WebHooks::HookLogActions include ::WebHooks::HookLogActions
...@@ -17,5 +17,9 @@ def hook ...@@ -17,5 +17,9 @@ def hook
def after_retry_redirect_path def after_retry_redirect_path
edit_group_hook_path(@group, hook) edit_group_hook_path(@group, hook)
end end
def authorize_admin_hook!
render_404 unless can?(current_user, :admin_web_hook, group)
end
end end
end end
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) } let_it_be(:project) { create(:project, group: group) }
let_it_be(:role) { create(:member_role, :guest, :admin_web_hook, namespace: group) } let(:can_admin_web_hook) { true }
let(:role) { create(:member_role, :guest, admin_web_hook: can_admin_web_hook, namespace: group) }
before do before do
stub_licensed_features(custom_roles: true) stub_licensed_features(custom_roles: true)
...@@ -24,7 +25,7 @@ ...@@ -24,7 +25,7 @@
describe '#edit' do describe '#edit' do
it 'allows access' do it 'allows access' do
get edit_path get edit_hook_path
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
...@@ -65,35 +66,94 @@ ...@@ -65,35 +66,94 @@
end end
end end
describe Projects::HooksController do shared_examples 'HookLogsController' do
let_it_be(:membership) { create(:project_member, :guest, member_role: role, user: user, project: project) } describe '#show' do
it 'allows access' do
get show_path
expect(response).to have_gitlab_http_status(:ok)
end
context 'without admin_web_hook permission' do
let(:can_admin_web_hook) { false }
it 'does not allow access' do
get show_path
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe '#retry' do
it 'allows access' do
stub_request(:post, hook.interpolated_url)
post retry_path
expect(response).to have_gitlab_http_status(:redirect)
expect(response).to redirect_to(edit_hook_path)
end
end
end
context 'in a project' do
let_it_be(:project_hook) { create(:project_hook, project: project, url: 'http://example.test/') } let_it_be(:project_hook) { create(:project_hook, project: project, url: 'http://example.test/') }
let(:hook) { create(:project_hook, project: project) } let(:hook) { create(:project_hook, project: project) }
let(:edit_hook_path) { edit_project_hook_path(project, hook) }
before do
create(:project_member, :guest, member_role: role, user: user, project: project)
end
describe Projects::HooksController do
let(:index_path) { project_hooks_path(project) }
let(:create_path) { project_hooks_path(project) }
let(:update_path) { project_hook_path(project, project_hook) }
let(:destroy_path) { project_hook_path(project, project_hook) }
let(:test_path) { test_project_hook_path(project, project_hook) }
it_behaves_like 'HooksController'
end
describe Projects::HookLogsController do
let(:hook_log) { create(:web_hook_log, web_hook: hook, internal_error_message: 'get error') }
let(:index_path) { project_hooks_path(project) } let(:show_path) { hook_log.present.details_path }
let(:edit_path) { edit_project_hook_path(project, project_hook) } let(:retry_path) { hook_log.present.retry_path }
let(:create_path) { project_hooks_path(project) }
let(:update_path) { project_hook_path(project, project_hook) }
let(:destroy_path) { project_hook_path(project, hook) }
let(:test_path) { test_project_hook_path(project, project_hook) }
it_behaves_like 'HooksController' it_behaves_like 'HookLogsController'
end
end end
describe Groups::HooksController do context 'in a group' do
let_it_be(:membership) { create(:group_member, :guest, member_role: role, user: user, group: group) }
let_it_be(:group_hook) { create(:group_hook, group: group, url: 'http://example.test/') } let_it_be(:group_hook) { create(:group_hook, group: group, url: 'http://example.test/') }
let(:hook) { create(:group_hook, group: group) } let(:hook) { create(:group_hook, group: group) }
let(:edit_hook_path) { edit_group_hook_path(group, hook) }
before do
create(:group_member, :guest, member_role: role, user: user, group: group)
end
describe Groups::HooksController do
let(:index_path) { group_hooks_path(group) }
let(:create_path) { group_hooks_path(group) }
let(:update_path) { group_hook_path(group, group_hook) }
let(:destroy_path) { group_hook_path(group, hook) }
let(:test_path) { test_group_hook_path(group, group_hook) }
let(:index_path) { group_hooks_path(group) } it_behaves_like 'HooksController'
let(:edit_path) { edit_group_hook_path(group, group_hook) } end
let(:create_path) { group_hooks_path(group) }
let(:update_path) { group_hook_path(group, group_hook) } describe Groups::HookLogsController do
let(:destroy_path) { group_hook_path(group, hook) } let(:hook_log) { create(:web_hook_log, web_hook: hook, internal_error_message: 'get error') }
let(:test_path) { test_group_hook_path(group, group_hook) }
it_behaves_like 'HooksController' let(:show_path) { hook_log.present.details_path }
let(:retry_path) { hook_log.present.retry_path }
it_behaves_like 'HookLogsController'
end
end end
end end
...@@ -7,13 +7,26 @@ ...@@ -7,13 +7,26 @@
let_it_be_with_refind(:web_hook) { create(:group_hook) } let_it_be_with_refind(:web_hook) { create(:group_hook) }
let_it_be_with_refind(:web_hook_log) { create(:web_hook_log, web_hook: web_hook) } let_it_be_with_refind(:web_hook_log) { create(:web_hook_log, web_hook: web_hook) }
let(:group) { web_hook.group } let_it_be(:group) { web_hook.group }
it_behaves_like WebHooks::HookLogActions do it_behaves_like WebHooks::HookLogActions do
let(:edit_hook_path) { edit_group_hook_url(group, web_hook) } let(:edit_hook_path) { edit_group_hook_url(group, web_hook) }
before do before_all do
group.add_owner(user) group.add_owner(user)
end end
end end
context 'with a custom role' do
let_it_be(:role) { create(:member_role, :guest, :admin_web_hook) }
let_it_be(:membership) { create(:group_member, :guest, member_role: role, user: user, group: group) }
before do
stub_licensed_features(custom_roles: true)
end
it_behaves_like WebHooks::HookLogActions do
let(:edit_hook_path) { edit_group_hook_url(group, web_hook) }
end
end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册