Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
b3b75242
未验证
提交
b3b75242
编辑于
1 year ago
作者:
Mohamed Hamda
提交者:
GitLab
1 year ago
浏览文件
操作
下载
补丁
差异文件
Extend bulk_user_assignment lib
Extend the lib to support gitlab.com
上级
a5d687b0
No related branches found
No related tags found
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
ee/lib/duo_pro/bulk_user_assignment.rb
+8
-4
8 个添加, 4 个删除
ee/lib/duo_pro/bulk_user_assignment.rb
ee/spec/lib/duo_pro/bulk_user_assignment_spec.rb
+94
-46
94 个添加, 46 个删除
ee/spec/lib/duo_pro/bulk_user_assignment_spec.rb
有
102 个添加
和
50 个删除
ee/lib/duo_pro/bulk_user_assignment.rb
+
8
−
4
浏览文件 @
b3b75242
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
module
DuoPro
module
DuoPro
class
BulkUserAssignment
class
BulkUserAssignment
include
::
GitlabSubscriptions
::
SubscriptionHelper
attr_reader
:usernames
,
:add_on_purchase
,
:successful_assignments
,
:failed_assignments
attr_reader
:usernames
,
:add_on_purchase
,
:successful_assignments
,
:failed_assignments
def
initialize
(
usernames
,
add_on_purchase
)
def
initialize
(
usernames
,
add_on_purchase
)
...
@@ -57,10 +58,13 @@ def process_users(usernames)
...
@@ -57,10 +58,13 @@ def process_users(usernames)
end
end
def
assign
(
user
)
def
assign
(
user
)
::
GitlabSubscriptions
::
UserAddOnAssignments
::
SelfManaged
::
CreateService
.
new
(
service_class
=
if
gitlab_com_subscription?
add_on_purchase:
add_on_purchase
,
::
GitlabSubscriptions
::
UserAddOnAssignments
::
Saas
::
CreateService
user:
user
else
).
execute
::
GitlabSubscriptions
::
UserAddOnAssignments
::
SelfManaged
::
CreateService
end
service_class
.
new
(
add_on_purchase:
add_on_purchase
,
user:
user
).
execute
end
end
def
log_no_seats_available
(
result
,
username
)
def
log_no_seats_available
(
result
,
username
)
...
...
此差异已折叠。
点击以展开。
ee/spec/lib/duo_pro/bulk_user_assignment_spec.rb
+
94
−
46
浏览文件 @
b3b75242
...
@@ -15,19 +15,46 @@
...
@@ -15,19 +15,46 @@
end
end
describe
'#execute'
do
describe
'#execute'
do
let
(
:add_on
)
{
create
(
:gitlab_subscription_add_on
)
}
let
_it_be
(
:add_on
)
{
create
(
:gitlab_subscription_add_on
)
}
let
(
:usernames
)
{
User
.
pluck
(
:username
)
+
[
'code_suggestions_not_found_username'
]
}
let
(
:usernames
)
{
User
.
pluck
(
:username
)
+
[
'code_suggestions_not_found_username'
]
}
before
do
subject
(
:bulk_assignment
)
{
described_class
.
new
(
usernames
,
add_on_purchase
)
}
create
(
:user
,
username:
'code_suggestions_active_user1'
)
create
(
:user
,
username:
'code_suggestions_active_user2'
)
shared_examples
'bulk user assignment with enough seats'
do
create
(
:user
,
username:
'code_suggestions_active_user3'
)
it
'returns success and failed assignments'
do
create
(
:user
,
username:
'code_suggestions_extra_user1'
)
results
=
bulk_assignment
.
execute
create
(
:user
,
username:
'code_suggestions_extra_user2'
)
create
(
:user
,
:blocked
,
username:
'code_suggestions_blocked_user'
)
expect
(
results
[
:successful_assignments
]).
to
eq
([
create
(
:user
,
:banned
,
username:
'code_suggestions_banned_user'
)
"User assigned: code_suggestions_active_user1"
,
create
(
:user
,
:bot
,
username:
'code_suggestions_bot_user'
)
"User assigned: code_suggestions_active_user2"
,
create
(
:user
,
:ghost
,
username:
'code_suggestions_ghost_user'
)
"User assigned: code_suggestions_active_user3"
,
"User assigned: code_suggestions_extra_user1"
,
"User assigned: code_suggestions_extra_user2"
])
expect
(
results
[
:failed_assignments
]).
to
eq
([
"Failed to assign seat to user: code_suggestions_blocked_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"Failed to assign seat to user: code_suggestions_banned_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"Failed to assign seat to user: code_suggestions_bot_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"Failed to assign seat to user: code_suggestions_ghost_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"User is not found: code_suggestions_not_found_username"
])
end
end
shared_examples
'bulk user assignment with not enough seats'
do
it
'returns success and failed assignments and stops execution'
do
results
=
bulk_assignment
.
execute
expect
(
results
[
:successful_assignments
]).
to
eq
(
[
"User assigned: code_suggestions_active_user1"
,
"User assigned: code_suggestions_active_user2"
,
"User assigned: code_suggestions_active_user3"
])
expect
(
results
[
:failed_assignments
]).
to
eq
(
[
"Failed to assign seat to user: code_suggestions_extra_user1, Errors: [
\"
NO_SEATS_AVAILABLE
\"
]"
,
"##No seats are left; users starting from @code_suggestions_extra_user1 onwards were not assigned.##"
])
end
end
end
context
'when the AddOn is not purchased'
do
context
'when the AddOn is not purchased'
do
...
@@ -37,51 +64,72 @@
...
@@ -37,51 +64,72 @@
end
end
end
end
context
'when the AddOn is purchased'
do
context
'on self managed instances'
do
let
(
:add_on_purchase
)
do
before
do
create
(
:gitlab_subscription_add_on_purchase
,
:self_managed
,
quantity:
10
,
add_on:
add_on
)
create
(
:user
,
username:
'code_suggestions_active_user1'
)
create
(
:user
,
username:
'code_suggestions_active_user2'
)
create
(
:user
,
username:
'code_suggestions_active_user3'
)
create
(
:user
,
username:
'code_suggestions_extra_user1'
)
create
(
:user
,
username:
'code_suggestions_extra_user2'
)
create
(
:user
,
:blocked
,
username:
'code_suggestions_blocked_user'
)
create
(
:user
,
:banned
,
username:
'code_suggestions_banned_user'
)
create
(
:user
,
:bot
,
username:
'code_suggestions_bot_user'
)
create
(
:user
,
:ghost
,
username:
'code_suggestions_ghost_user'
)
end
end
subject
(
:bulk_assignment
)
{
described_class
.
new
(
usernames
,
add_on_purchase
)
}
context
'when the AddOn is purchased'
do
context
'with enough seats'
do
context
'with enough seats'
do
include_examples
'bulk user assignment with enough seats'
do
it
'returns success and failed assignments'
do
let
(
:add_on_purchase
)
do
results
=
bulk_assignment
.
execute
create
(
:gitlab_subscription_add_on_purchase
,
:self_managed
,
quantity:
10
,
add_on:
add_on
)
end
end
end
expect
(
results
[
:successful_assignments
]).
to
eq
([
context
'with not enough seats'
do
"User assigned: code_suggestions_active_user1"
,
include_examples
'bulk user assignment with not enough seats'
do
"User assigned: code_suggestions_active_user2"
,
let
(
:add_on_purchase
)
do
"User assigned: code_suggestions_active_user3"
,
create
(
:gitlab_subscription_add_on_purchase
,
:self_managed
,
quantity:
3
,
add_on:
add_on
)
"User assigned: code_suggestions_extra_user1"
,
end
"User assigned: code_suggestions_extra_user2"
end
])
expect
(
results
[
:failed_assignments
]).
to
eq
([
"Failed to assign seat to user: code_suggestions_blocked_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"Failed to assign seat to user: code_suggestions_banned_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"Failed to assign seat to user: code_suggestions_bot_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"Failed to assign seat to user: code_suggestions_ghost_user, Errors: [
\"
INVALID_USER_MEMBERSHIP
\"
]"
,
"User is not found: code_suggestions_not_found_username"
])
end
end
end
end
end
context
'with not enough seats'
do
context
'on Gitlab.com'
do
let
(
:add_on_purchase
)
do
before
do
create
(
:gitlab_subscription_add_on_purchase
,
:self_managed
,
quantity:
3
,
add_on:
add_on
)
stub_saas_features
(
gitlab_com_subscriptions:
true
)
end
let_it_be
(
:namespace
)
{
create
(
:group
)
}
context
'with bulk assignment'
do
before_all
do
namespace
.
add_developer
(
create
(
:user
,
username:
'code_suggestions_active_user1'
))
namespace
.
add_developer
(
create
(
:user
,
username:
'code_suggestions_active_user2'
))
namespace
.
add_developer
(
create
(
:user
,
username:
'code_suggestions_active_user3'
))
namespace
.
add_developer
(
create
(
:user
,
username:
'code_suggestions_extra_user1'
))
namespace
.
add_developer
(
create
(
:user
,
username:
'code_suggestions_extra_user2'
))
namespace
.
add_developer
(
create
(
:user
,
:blocked
,
username:
'code_suggestions_blocked_user'
))
namespace
.
add_developer
(
create
(
:user
,
:banned
,
username:
'code_suggestions_banned_user'
))
namespace
.
add_developer
(
create
(
:user
,
:bot
,
username:
'code_suggestions_bot_user'
))
namespace
.
add_developer
(
create
(
:user
,
:ghost
,
username:
'code_suggestions_ghost_user'
))
end
end
it
'returns success and failed assignments and stops execution'
do
context
'with enough seats'
do
results
=
bulk_assignment
.
execute
let_it_be
(
:add_on_purchase
)
do
create
(
:gitlab_subscription_add_on_purchase
,
quantity:
10
,
namespace:
namespace
,
add_on:
add_on
)
end
include_examples
'bulk user assignment with enough seats'
end
expect
(
results
[
:successful_assignments
]).
to
eq
(
context
'with not enough seats'
do
[
"User assigned: code_suggestions_active_user1"
,
let_it_be
(
:add_on_purchase
)
do
"User assigned: code_sugges
tion
s
_a
ctive_user2"
,
create
(
:gitlab_subscrip
tion_a
dd_on_purchase
,
quantity:
3
,
namespace:
namespace
,
add_on:
add_on
)
"User assigned: code_suggestions_active_user3"
])
end
expect
(
results
[
:failed_assignments
]).
to
eq
(
include_examples
'bulk user assignment with not enough seats'
[
"Failed to assign seat to user: code_suggestions_extra_user1, Errors: [
\"
NO_SEATS_AVAILABLE
\"
]"
,
"##No seats are left; users starting from @code_suggestions_extra_user1 onwards were not assigned.##"
])
end
end
end
end
end
end
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录