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
1535ea91
Commit
1535ea91
authored
May 26, 2020
by
Kerri Miller
Committed by
charlie ablett
May 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply codeowner validation when creating/updating a blob in the UI
parent
1998e450
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
0 deletions
+81
-0
app/controllers/concerns/check_codeowner_rules.rb
app/controllers/concerns/check_codeowner_rules.rb
+9
-0
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+16
-0
spec/controllers/projects/blob_controller_spec.rb
spec/controllers/projects/blob_controller_spec.rb
+56
-0
No files found.
app/controllers/concerns/check_codeowner_rules.rb
0 → 100644
View file @
1535ea91
# frozen_string_literal: true
module
CheckCodeownerRules
extend
ActiveSupport
::
Concern
def
codeowners_check_error
(
project
,
branch_name
,
paths
)
::
Gitlab
::
CodeOwners
::
Validator
.
new
(
project
,
branch_name
,
paths
).
execute
end
end
app/controllers/projects/blob_controller.rb
View file @
1535ea91
...
@@ -9,6 +9,7 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -9,6 +9,7 @@ class Projects::BlobController < Projects::ApplicationController
include
ActionView
::
Helpers
::
SanitizeHelper
include
ActionView
::
Helpers
::
SanitizeHelper
include
RedirectsForMissingPathOnTree
include
RedirectsForMissingPathOnTree
include
SourcegraphDecorator
include
SourcegraphDecorator
include
CheckCodeownerRules
prepend_before_action
:authenticate_user!
,
only:
[
:edit
]
prepend_before_action
:authenticate_user!
,
only:
[
:edit
]
...
@@ -28,6 +29,7 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -28,6 +29,7 @@ class Projects::BlobController < Projects::ApplicationController
before_action
:editor_variables
,
except:
[
:show
,
:preview
,
:diff
]
before_action
:editor_variables
,
except:
[
:show
,
:preview
,
:diff
]
before_action
:validate_diff_params
,
only: :diff
before_action
:validate_diff_params
,
only: :diff
before_action
:set_last_commit_sha
,
only:
[
:edit
,
:update
]
before_action
:set_last_commit_sha
,
only:
[
:edit
,
:update
]
before_action
:validate_codeowner_rules
,
only:
[
:create
,
:update
]
before_action
only: :show
do
before_action
only: :show
do
push_frontend_feature_flag
(
:code_navigation
,
@project
)
push_frontend_feature_flag
(
:code_navigation
,
@project
)
...
@@ -71,6 +73,7 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -71,6 +73,7 @@ class Projects::BlobController < Projects::ApplicationController
def
update
def
update
@path
=
params
[
:file_path
]
if
params
[
:file_path
].
present?
@path
=
params
[
:file_path
]
if
params
[
:file_path
].
present?
create_commit
(
Files
::
UpdateService
,
success_path:
->
{
after_edit_path
},
create_commit
(
Files
::
UpdateService
,
success_path:
->
{
after_edit_path
},
failure_view: :edit
,
failure_view: :edit
,
failure_path:
project_blob_path
(
@project
,
@id
))
failure_path:
project_blob_path
(
@project
,
@id
))
...
@@ -115,6 +118,19 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -115,6 +118,19 @@ class Projects::BlobController < Projects::ApplicationController
private
private
def
validate_codeowner_rules
return
if
params
[
:file_path
].
blank?
codeowners_error
=
codeowners_check_error
(
@project
,
@branch_name
,
params
[
:file_path
])
if
codeowners_error
.
present?
flash
.
now
[
:alert
]
=
codeowners_error
view
=
params
[
:action
]
==
'update'
?
:edit
:
:new
render
view
end
end
def
blob
def
blob
@blob
||=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
@blob
||=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
...
...
spec/controllers/projects/blob_controller_spec.rb
View file @
1535ea91
...
@@ -250,6 +250,56 @@ describe Projects::BlobController do
...
@@ -250,6 +250,56 @@ describe Projects::BlobController do
end
end
end
end
shared_examples
"file matches a codeowners rule"
do
let
(
:error_msg
)
{
"Example error msg"
}
it
"renders to the edit page with an error msg"
do
default_params
[
:file_path
]
=
"CHANGELOG"
expect_next_instance_of
(
Gitlab
::
CodeOwners
::
Validator
)
do
|
validator
|
expect
(
validator
).
to
receive
(
:execute
).
and_return
(
error_msg
)
end
subject
expect
(
flash
[
:alert
]).
to
eq
(
error_msg
)
expect
(
response
).
to
render_template
(
expected_view
)
end
end
describe
'POST create'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:default_params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
'master'
,
branch_name:
'master'
,
file_name:
'CHANGELOG'
,
content:
'Added changes'
,
commit_message:
'Create CHANGELOG'
}
end
before
do
project
.
add_developer
(
user
)
sign_in
(
user
)
end
it
'redirects to blob'
do
post
:create
,
params:
default_params
expect
(
response
).
to
be_ok
end
it_behaves_like
"file matches a codeowners rule"
do
subject
{
post
:create
,
params:
default_params
}
let
(
:expected_view
)
{
:new
}
end
end
describe
'PUT update'
do
describe
'PUT update'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:default_params
)
do
let
(
:default_params
)
do
...
@@ -279,6 +329,12 @@ describe Projects::BlobController do
...
@@ -279,6 +329,12 @@ describe Projects::BlobController do
expect
(
response
).
to
redirect_to
(
blob_after_edit_path
)
expect
(
response
).
to
redirect_to
(
blob_after_edit_path
)
end
end
it_behaves_like
"file matches a codeowners rule"
do
subject
{
put
:update
,
params:
default_params
}
let
(
:expected_view
)
{
:edit
}
end
context
'?from_merge_request_iid'
do
context
'?from_merge_request_iid'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:mr_params
)
{
default_params
.
merge
(
from_merge_request_iid:
merge_request
.
iid
)
}
let
(
:mr_params
)
{
default_params
.
merge
(
from_merge_request_iid:
merge_request
.
iid
)
}
...
...
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