Skip to content
Snippets Groups Projects
Commit 86e9759c authored by Fred de Gier's avatar Fred de Gier
Browse files

Implement code review suggestions

parent 48ecf485
No related branches found
No related tags found
1 merge request!100500Add allowed status endpoint for AI Assist
......@@ -8,7 +8,7 @@ class AiAssist < ::API::Base
before do
authenticate!
not_found! unless current_user.groups.any? do |group|
not_found! unless current_user.groups.select(&:root?).any? do |group|
Feature.enabled?(:ai_assist_flag, group) && group.licensed_feature_available?(:ai_assist)
end
end
......@@ -20,7 +20,7 @@ class AiAssist < ::API::Base
desc 'Get status if user can use AI Assist' do
success EE::API::Entities::Ml::AiAssist
end
get 'aiassist' do
get 'ai-assist' do
response = {
user_is_allowed: true
}
......
......@@ -13,85 +13,67 @@
group
end
describe 'GET /ml/aiassist user_is_allowed' do
before do
stub_licensed_features(ai_assist: false)
stub_feature_flags(ai_assist_flag: false)
end
subject { get api("/ml/aiassist", current_user) }
describe 'GET /ml/ai-assist user_is_allowed' do
using RSpec::Parameterized::TableSyntax
context "when unauthorized" do
it "returns forbidden error" do
subject
expect(response).to have_gitlab_http_status(:unauthorized)
end
before do
stub_licensed_features(ai_assist: license_flag)
stub_feature_flags(ai_assist_flag: feature_flag)
end
context "when authorized but not ultimate, not in group, no FF" do
let(:current_user) { user }
subject { get api('/ml/ai-assist', current_user) }
it "returns forbidden error" do
subject
context 'when user not logged in' do
let(:current_user) { nil }
expect(response).to have_gitlab_http_status(:not_found)
where(:feature_flag, :license_flag, :result) do
false | false | :unauthorized
true | false | :unauthorized
false | true | :unauthorized
true | true | :unauthorized
end
end
context "when authorized but not ultimate, in group, no FF" do
let(:current_user) { group_user }
it "returns forbidden error" do
subject
expect(response).to have_gitlab_http_status(:not_found)
with_them do
it 'returns unauthorized' do
subject
expect(response).to have_gitlab_http_status(result)
end
end
end
context "when authorized and ultimate, not in group but no FF" do
context 'when user is logged in' do
let(:current_user) { user }
it "returns forbidden error" do
stub_licensed_features(ai_assist: true)
subject
expect(response).to have_gitlab_http_status(:not_found)
where(:feature_flag, :license_flag, :result) do
false | false | :not_found
true | false | :not_found
false | true | :not_found
true | true | :not_found
end
end
context "when authorized and ultimate, in group but no FF" do
let(:current_user) { group_user }
it "returns forbidden error" do
stub_licensed_features(ai_assist: true)
subject
expect(response).to have_gitlab_http_status(:not_found)
with_them do
it 'returns not found' do
subject
expect(response).to have_gitlab_http_status(result)
end
end
end
context "when authorized and ultimate, not in group and FF" do
let(:current_user) { user }
it "returns forbidden error" do
stub_licensed_features(ai_assist: true)
stub_feature_flags(ai_assist_flag: allowed_group)
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
context "when authorized and ultimate, in group and FF" do
context 'when user is logged in and in group' do
let(:current_user) { group_user }
it "returns forbidden error" do
stub_licensed_features(ai_assist: true)
stub_feature_flags(ai_assist_flag: allowed_group)
subject
where(:feature_flag, :license_flag, :result) do
false | false | :not_found
true | false | :not_found
false | true | :not_found
true | true | :ok
end
expect(response).to have_gitlab_http_status(:ok)
expect(json_response["user_is_allowed"]).to eq true
with_them do
it 'returns not found except when both flags true' do
subject
expect(response).to have_gitlab_http_status(result)
end
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment