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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
1cc7f4a4
Commit
1cc7f4a4
authored
Sep 01, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable share_with_group_lock on subgroup
…when needed
parent
8437a24f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
188 additions
and
0 deletions
+188
-0
app/models/namespace.rb
app/models/namespace.rb
+14
-0
spec/features/groups/share_lock_spec.rb
spec/features/groups/share_lock_spec.rb
+62
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+112
-0
No files found.
app/models/namespace.rb
View file @
1cc7f4a4
...
@@ -44,6 +44,10 @@ class Namespace < ActiveRecord::Base
...
@@ -44,6 +44,10 @@ class Namespace < ActiveRecord::Base
after_commit
:refresh_access_of_projects_invited_groups
,
on: :update
,
if:
->
{
previous_changes
.
key?
(
'share_with_group_lock'
)
}
after_commit
:refresh_access_of_projects_invited_groups
,
on: :update
,
if:
->
{
previous_changes
.
key?
(
'share_with_group_lock'
)
}
before_create
:sync_share_with_group_lock_with_parent
before_update
:sync_share_with_group_lock_with_parent
,
if: :parent_changed?
after_commit
:force_share_with_group_lock_on_descendants
,
on: :update
,
if:
->
{
previous_changes
.
key?
(
'share_with_group_lock'
)
&&
share_with_group_lock?
}
# Legacy Storage specific hooks
# Legacy Storage specific hooks
after_update
:move_dir
,
if: :path_changed?
after_update
:move_dir
,
if: :path_changed?
...
@@ -219,4 +223,14 @@ class Namespace < ActiveRecord::Base
...
@@ -219,4 +223,14 @@ class Namespace < ActiveRecord::Base
errors
.
add
(
:parent_id
,
"has too deep level of nesting"
)
errors
.
add
(
:parent_id
,
"has too deep level of nesting"
)
end
end
end
end
def
sync_share_with_group_lock_with_parent
if
has_parent?
&&
parent
.
share_with_group_lock?
self
.
share_with_group_lock
=
true
end
end
def
force_share_with_group_lock_on_descendants
descendants
.
update_all
(
share_with_group_lock:
true
)
end
end
end
spec/features/groups/share_lock_spec.rb
0 → 100644
View file @
1cc7f4a4
require
'spec_helper'
feature
'Group share lock'
do
given
(
:root_owner
)
{
create
(
:user
)
}
given
(
:root_group
)
{
create
(
:group
)
}
background
do
root_group
.
add_owner
(
root_owner
)
sign_in
(
root_owner
)
end
context
'with a subgroup'
do
given!
(
:subgroup
)
{
create
(
:group
,
parent:
root_group
)
}
context
'when enabling the parent group share lock'
do
scenario
'the subgroup share lock becomes enabled'
do
visit
edit_group_path
(
root_group
)
check
'group_share_with_group_lock'
click_on
'Save group'
expect
(
subgroup
.
reload
.
share_with_group_lock?
).
to
be_truthy
end
end
context
'when disabling the parent group share lock (which was already enabled)'
do
background
do
visit
edit_group_path
(
root_group
)
check
'group_share_with_group_lock'
click_on
'Save group'
end
context
'and the subgroup share lock is enabled'
do
scenario
'the subgroup share lock does not change'
do
visit
edit_group_path
(
root_group
)
uncheck
'group_share_with_group_lock'
click_on
'Save group'
expect
(
subgroup
.
reload
.
share_with_group_lock?
).
to
be_truthy
end
end
context
'but the subgroup share lock is disabled'
do
background
do
visit
edit_group_path
(
subgroup
)
uncheck
'group_share_with_group_lock'
click_on
'Save group'
end
scenario
'the subgroup share lock does not change'
do
visit
edit_group_path
(
root_group
)
uncheck
'group_share_with_group_lock'
click_on
'Save group'
expect
(
subgroup
.
reload
.
share_with_group_lock?
).
to
be_falsey
end
end
end
end
end
spec/models/namespace_spec.rb
View file @
1cc7f4a4
...
@@ -406,4 +406,116 @@ describe Namespace do
...
@@ -406,4 +406,116 @@ describe Namespace do
it
{
expect
(
group
.
all_projects
.
to_a
).
to
eq
([
project2
,
project1
])
}
it
{
expect
(
group
.
all_projects
.
to_a
).
to
eq
([
project2
,
project1
])
}
end
end
describe
'#share_with_group_lock with subgroups'
do
context
'when creating a subgroup'
do
let
(
:subgroup
)
{
create
(
:group
,
parent:
root_group
)}
context
'under a parent with share lock enabled'
do
let
(
:root_group
)
{
create
(
:group
,
share_with_group_lock:
true
)
}
it
'enables share lock on the subgroup'
do
expect
(
subgroup
.
share_with_group_lock
).
to
be_truthy
end
end
context
'under a parent with share lock disabled'
do
let
(
:root_group
)
{
create
(
:group
)
}
it
'does not enable share lock on the subgroup'
do
expect
(
subgroup
.
share_with_group_lock
).
to
be_falsey
end
end
end
context
'when enabling the parent group share lock'
do
let
(
:root_group
)
{
create
(
:group
)
}
let!
(
:subgroup
)
{
create
(
:group
,
parent:
root_group
)}
it
'the subgroup share lock becomes enabled'
do
root_group
.
update
(
share_with_group_lock:
true
)
expect
(
subgroup
.
reload
.
share_with_group_lock
).
to
be_truthy
end
end
context
'when disabling the parent group share lock (which was already enabled)'
do
let
(
:root_group
)
{
create
(
:group
,
share_with_group_lock:
true
)
}
context
'and the subgroup share lock is enabled'
do
let
(
:subgroup
)
{
create
(
:group
,
parent:
root_group
,
share_with_group_lock:
true
)}
it
'the subgroup share lock does not change'
do
root_group
.
update
(
share_with_group_lock:
false
)
expect
(
subgroup
.
reload
.
share_with_group_lock
).
to
be_truthy
end
end
context
'but the subgroup share lock is disabled'
do
let
(
:subgroup
)
{
create
(
:group
,
parent:
root_group
)}
it
'the subgroup share lock does not change'
do
root_group
.
update
(
share_with_group_lock:
false
)
expect
(
subgroup
.
reload
.
share_with_group_lock?
).
to
be_falsey
end
end
end
# Note: Group transfers are not yet implemented
context
'when a group is transferred into a root group'
do
context
'when the root group share lock is enabled'
do
let
(
:root_group
)
{
create
(
:group
,
share_with_group_lock:
true
)
}
context
'when the subgroup share lock is enabled'
do
let
(
:subgroup
)
{
create
(
:group
,
share_with_group_lock:
true
)}
it
'the subgroup share lock does not change'
do
subgroup
.
parent
=
root_group
subgroup
.
save!
expect
(
subgroup
.
share_with_group_lock
).
to
be_truthy
end
end
context
'when the subgroup share lock is disabled'
do
let
(
:subgroup
)
{
create
(
:group
)}
it
'the subgroup share lock becomes enabled'
do
subgroup
.
parent
=
root_group
subgroup
.
save!
expect
(
subgroup
.
share_with_group_lock
).
to
be_truthy
end
end
end
context
'when the root group share lock is disabled'
do
let
(
:root_group
)
{
create
(
:group
)
}
context
'when the subgroup share lock is enabled'
do
let
(
:subgroup
)
{
create
(
:group
,
share_with_group_lock:
true
)}
it
'the subgroup share lock does not change'
do
subgroup
.
parent
=
root_group
subgroup
.
save!
expect
(
subgroup
.
share_with_group_lock
).
to
be_truthy
end
end
context
'when the subgroup share lock is disabled'
do
let
(
:subgroup
)
{
create
(
:group
)}
it
'the subgroup share lock does not change'
do
subgroup
.
parent
=
root_group
subgroup
.
save!
expect
(
subgroup
.
share_with_group_lock
).
to
be_falsey
end
end
end
end
end
end
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