Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4ca0cee7
Commit
4ca0cee7
authored
Oct 01, 2021
by
Sheldon Led
Committed by
Andy Soiron
Oct 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move state machine from GroupMember to Member
parent
abf3f308
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
80 deletions
+109
-80
ee/app/models/ee/group_member.rb
ee/app/models/ee/group_member.rb
+0
-28
ee/app/models/ee/member.rb
ee/app/models/ee/member.rb
+28
-0
ee/spec/models/group_member_spec.rb
ee/spec/models/group_member_spec.rb
+0
-47
ee/spec/models/member_spec.rb
ee/spec/models/member_spec.rb
+78
-0
ee/spec/policies/project_policy_spec.rb
ee/spec/policies/project_policy_spec.rb
+3
-5
No files found.
ee/app/models/ee/group_member.rb
View file @
4ca0cee7
...
...
@@ -8,10 +8,6 @@ module EE
prepended
do
include
UsageStatistics
STATE_CREATED
=
0
STATE_AWAITING
=
1
STATE_ACTIVE
=
2
validate
:sso_enforcement
,
if: :group
validate
:group_domain_limitations
,
if: :group_has_domain_limitations?
...
...
@@ -29,24 +25,6 @@ module EE
scope
:guests
,
->
{
where
(
access_level:
::
Gitlab
::
Access
::
GUEST
)
}
scope
:non_owners
,
->
{
where
(
"members.access_level < ?"
,
::
Gitlab
::
Access
::
OWNER
)
}
scope
:by_user_id
,
->
(
user_id
)
{
where
(
user_id:
user_id
)
}
state_machine
:state
,
initial: :created
do
event
:wait
do
transition
created: :awaiting
transition
active: :awaiting
end
event
:activate
do
transition
created: :active
transition
awaiting: :active
end
state
:created
,
value:
STATE_CREATED
state
:awaiting
,
value:
STATE_AWAITING
state
:active
,
value:
STATE_ACTIVE
end
before_create
:set_membership_activation
end
class_methods
do
...
...
@@ -97,12 +75,6 @@ module EE
execute_hooks_for
(
:destroy
)
end
def
set_membership_activation
return
unless
::
Feature
.
enabled?
(
:saas_user_caps
,
group
,
default_enabled: :yaml
)
self
.
state
=
group
.
user_cap_reached?
?
STATE_AWAITING
:
STATE_ACTIVE
end
def
execute_hooks_for
(
event
)
return
unless
self
.
source
.
feature_available?
(
:group_webhooks
)
return
unless
GroupHook
.
where
(
group_id:
self
.
source
.
self_and_ancestors
).
exists?
...
...
ee/app/models/ee/member.rb
View file @
4ca0cee7
...
...
@@ -6,6 +6,28 @@ module EE
extend
::
Gitlab
::
Utils
::
Override
prepended
do
STATE_CREATED
=
0
STATE_AWAITING
=
1
STATE_ACTIVE
=
2
state_machine
:state
,
initial: :created
do
event
:wait
do
transition
created: :awaiting
transition
active: :awaiting
end
event
:activate
do
transition
created: :active
transition
awaiting: :active
end
state
:created
,
value:
STATE_CREATED
state
:awaiting
,
value:
STATE_AWAITING
state
:active
,
value:
STATE_ACTIVE
end
before_create
:set_membership_activation
scope
:with_csv_entity_associations
,
->
do
includes
(
:user
,
source:
[
:route
,
:parent
])
end
...
...
@@ -116,5 +138,11 @@ module EE
def
email_not_verified
_
(
"email '%{email}' is not a verified email."
%
{
email:
user
.
email
})
end
def
set_membership_activation
return
unless
group
&&
::
Feature
.
enabled?
(
:saas_user_caps
,
group
,
default_enabled: :yaml
)
self
.
state
=
group
.
user_cap_reached?
?
STATE_AWAITING
:
STATE_ACTIVE
end
end
end
ee/spec/models/group_member_spec.rb
View file @
4ca0cee7
...
...
@@ -279,53 +279,6 @@ RSpec.describe GroupMember do
end
end
context
'check if user cap has been reached'
do
let_it_be
(
:group
)
{
create
(
:group_with_plan
,
plan: :ultimate_plan
)
}
let!
(
:user
)
{
create
(
:user
)
}
subject
(
:add_user_to_group
)
{
group
.
add_developer
(
user
)
}
context
'when the :saas_user_caps feature flag is disabled'
do
before
do
stub_feature_flags
(
saas_user_caps:
false
)
end
it
'leaves the group member state to created'
do
add_user_to_group
expect
(
user
.
group_members
.
last
).
to
be_created
end
end
context
'when the :saas_user_caps feature flag is enabled'
do
before
do
stub_feature_flags
(
saas_user_caps:
group
)
allow
(
group
).
to
receive
(
:user_cap_reached?
).
and_return
(
user_cap_reached
)
end
context
'when the user cap for this group has not been reached'
do
let
(
:user_cap_reached
)
{
false
}
it
'sets the group member to active'
do
add_user_to_group
expect
(
user
.
group_members
.
last
).
to
be_active
end
end
context
'when the user cap for this group has been reached'
do
let
(
:user_cap_reached
)
{
true
}
it
'sets the group member to awaiting'
do
add_user_to_group
expect
(
user
.
group_members
.
last
).
to
be_awaiting
end
end
end
end
describe
'#provisioned_by_this_group?'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
...
...
ee/spec/models/member_spec.rb
View file @
4ca0cee7
...
...
@@ -161,4 +161,82 @@ RSpec.describe Member, type: :model do
end
end
end
context
'check if user cap has been reached'
do
let_it_be
(
:group
)
{
create
(
:group_with_plan
,
plan: :ultimate_plan
)
}
let_it_be
(
:project
)
{
create
(
:project
,
namespace:
group
)}
let!
(
:user
)
{
create
(
:user
)
}
subject
(
:add_user_to_group
)
{
group
.
add_developer
(
user
)
}
context
'when the :saas_user_caps feature flag is disabled'
do
before
do
stub_feature_flags
(
saas_user_caps:
false
)
end
it
'leaves the group member state to created'
do
add_user_to_group
expect
(
user
.
group_members
.
last
).
to
be_created
end
it
'leaves the project member state to created'
do
project
.
add_developer
(
user
)
expect
(
user
.
project_members
.
last
).
to
be_created
end
end
context
'when the :saas_user_caps feature flag is enabled'
do
before
do
stub_feature_flags
(
saas_user_caps:
group
)
allow
(
project
.
group
).
to
receive
(
:user_cap_reached?
).
and_return
(
user_cap_reached
)
allow
(
group
).
to
receive
(
:user_cap_reached?
).
and_return
(
user_cap_reached
)
end
context
'when the user cap for this group has not been reached'
do
let
(
:user_cap_reached
)
{
false
}
it
'sets the group member to active'
do
add_user_to_group
expect
(
user
.
group_members
.
last
).
to
be_active
end
it
'sets the project member to active'
do
project
.
add_developer
(
user
)
expect
(
user
.
project_members
.
last
).
to
be_active
end
end
context
'when the user cap for this group has been reached'
do
let
(
:user_cap_reached
)
{
true
}
it
'sets the group member to awaiting'
do
add_user_to_group
expect
(
user
.
group_members
.
last
).
to
be_awaiting
end
it
'sets the project member to awaiting'
do
project
.
add_developer
(
user
)
expect
(
user
.
project_members
.
last
).
to
be_awaiting
end
end
end
context
'when user is added to a group-less project'
do
let
(
:project
)
{
create
(
:project
)
}
it
'adds project member and leaves the state to created'
do
project
.
add_developer
(
user
)
expect
(
user
.
project_members
.
last
).
to
be_created
end
end
end
end
ee/spec/policies/project_policy_spec.rb
View file @
4ca0cee7
...
...
@@ -1768,14 +1768,12 @@ RSpec.describe ProjectPolicy do
end
context
'when parent group has resource access token creation disabled'
do
let
(
:parent
)
{
create
(
:group_with_plan
,
plan: :bronze_plan
)
}
let
(
:resource_access_token_creation_allowed
)
{
false
}
let
(
:ns_for_parent
)
{
create
(
:namespace_settings
,
resource_access_token_creation_allowed:
resource_access_token_creation_allowed
)
}
let
(
:parent
)
{
create
(
:group_with_plan
,
plan: :bronze_plan
,
namespace_settings:
ns_for_parent
)
}
let
(
:group
)
{
create
(
:group
,
parent:
parent
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
before
do
parent
.
namespace_settings
.
update_column
(
:resource_access_token_creation_allowed
,
false
)
end
context
'cannot create resource access tokens'
do
it
{
is_expected
.
not_to
be_allowed
(
:create_resource_access_tokens
)
}
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment