Commit 515804e4 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'pat-bot-terms' into 'master'

Auto-accept TOS for project access token bots

Closes #225222

See merge request gitlab-org/gitlab!43067
parents 9b588a70 105dfc5c
......@@ -14,6 +14,8 @@ class ApplicationSetting
end
def accepted_by_user?(user)
return true if user.project_bot?
user.accepted_term_id == id ||
term_agreements.accepted.where(user: user).exists?
end
......
......@@ -1674,6 +1674,8 @@ class User < ApplicationRecord
end
def terms_accepted?
return true if project_bot?
accepted_term_id.present?
end
......
---
title: Auto-accept TOS if project bot
merge_request: 43067
author:
type: fixed
......@@ -26,6 +26,21 @@ RSpec.describe 'Users > Terms' do
expect(page).not_to have_content('Continue')
end
context 'when user is a project bot' do
let(:project_bot) { create(:user, :project_bot) }
before do
enforce_terms
end
it 'auto accepts the terms' do
visit terms_path
expect(page).not_to have_content('Accept terms')
expect(project_bot.terms_accepted?).to be(true)
end
end
context 'when signed in' do
let(:user) { create(:user) }
......
......@@ -17,6 +17,7 @@ RSpec.describe ApplicationSetting::Term do
describe '#accepted_by_user?' do
let(:user) { create(:user) }
let(:project_bot) { create(:user, :project_bot) }
let(:term) { create(:term) }
it 'is true when the user accepted the terms' do
......@@ -25,6 +26,10 @@ RSpec.describe ApplicationSetting::Term do
expect(term.accepted_by_user?(user)).to be(true)
end
it 'is true when user is a bot' do
expect(term.accepted_by_user?(project_bot)).to be(true)
end
it 'is false when the user declined the terms' do
decline_terms(term, user)
......
......@@ -4330,28 +4330,32 @@ RSpec.describe User do
describe '#required_terms_not_accepted?' do
let(:user) { build(:user) }
let(:project_bot) { create(:user, :project_bot) }
subject { user.required_terms_not_accepted? }
context "when terms are not enforced" do
it { is_expected.to be_falsy }
it { is_expected.to be_falsey }
end
context "when terms are enforced and accepted by the user" do
context "when terms are enforced" do
before do
enforce_terms
accept_terms(user)
end
it { is_expected.to be_falsy }
it "is not accepted by the user" do
expect(subject).to be_truthy
end
context "when terms are enforced but the user has not accepted" do
before do
enforce_terms
it "is accepted by the user" do
accept_terms(user)
expect(subject).to be_falsey
end
it { is_expected.to be_truthy }
it "auto accepts the term for project bots" do
expect(project_bot.required_terms_not_accepted?).to be_falsey
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment