Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
86e9759c
Commit
86e9759c
authored
2 years ago
by
Fred de Gier
Browse files
Options
Downloads
Patches
Plain Diff
Implement code review suggestions
parent
48ecf485
No related branches found
No related tags found
1 merge request
!100500
Add allowed status endpoint for AI Assist
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ee/lib/api/ml/ai_assist.rb
+2
-2
2 additions, 2 deletions
ee/lib/api/ml/ai_assist.rb
ee/spec/requests/api/ml/ai_assist_spec.rb
+41
-59
41 additions, 59 deletions
ee/spec/requests/api/ml/ai_assist_spec.rb
with
43 additions
and
61 deletions
ee/lib/api/ml/ai_assist.rb
+
2
−
2
View file @
86e9759c
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
ee/spec/requests/api/ml/ai_assist_spec.rb
+
41
−
59
View file @
86e9759c
...
...
@@ -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
e
xpect
(
response
).
to
have_gitlab_http_status
(
:not_fou
nd
)
w
it
h_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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment