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
6d7078e7
Commit
6d7078e7
authored
Aug 10, 2021
by
Bala Kumar
Committed by
Shinya Maeda
Aug 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Use Same Endpoint for HTML and JSON in OperationsController"
parent
b8376928
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
640 additions
and
539 deletions
+640
-539
ee/app/controllers/operations_controller.rb
ee/app/controllers/operations_controller.rb
+40
-23
ee/app/helpers/ee/operations_helper.rb
ee/app/helpers/ee/operations_helper.rb
+4
-4
ee/app/serializers/dashboard_environments_project_entity.rb
ee/app/serializers/dashboard_environments_project_entity.rb
+1
-1
ee/config/routes/operations.rb
ee/config/routes/operations.rb
+6
-3
ee/spec/controllers/operations_controller_spec.rb
ee/spec/controllers/operations_controller_spec.rb
+524
-504
ee/spec/fixtures/api/schemas/dashboard/operations/environments.json
...xtures/api/schemas/dashboard/operations/environments.json
+0
-0
ee/spec/routing/operations_routing_spec.rb
ee/spec/routing/operations_routing_spec.rb
+61
-0
ee/spec/views/operations/environments.html.haml_spec.rb
ee/spec/views/operations/environments.html.haml_spec.rb
+2
-2
ee/spec/views/operations/index.html.haml_spec.rb
ee/spec/views/operations/index.html.haml_spec.rb
+2
-2
No files found.
ee/app/controllers/operations_controller.rb
View file @
6d7078e7
# frozen_string_literal: true
# frozen_string_literal: true
# Note: Both Operations dashboard (https://docs.gitlab.com/ee/user/operations_dashboard/) and Environments dashboard (https://docs.gitlab.com/ee/ci/environments/environments_dashboard.html) features are co-existing in the same controller.
class
OperationsController
<
ApplicationController
class
OperationsController
<
ApplicationController
before_action
:authorize_read_operations_dashboard!
before_action
:authorize_read_operations_dashboard!
respond_to
:json
,
only:
[
:list
]
feature_category
:release_orchestration
feature_category
:release_orchestration
POLLING_INTERVAL
=
120_000
POLLING_INTERVAL
=
120_000
# Used by Operations dashboard.
def
index
def
index
end
respond_to
do
|
format
|
format
.
html
def
environments
end
def
list
format
.
json
do
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
POLLING_INTERVAL
)
set_polling_interval_header
projects
=
load_projects
projects
=
load_projects
render
json:
{
projects:
serialize_as_json
(
projects
)
}
render
json:
{
projects:
serialize_as_json
(
projects
)
}
end
end
end
end
def
environments_list
# Used by Environments dashboard.
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
POLLING_INTERVAL
)
def
environments
respond_to
do
|
format
|
format
.
html
format
.
json
do
set_polling_interval_header
projects
=
load_environments_projects
projects
=
load_environments_projects
render
json:
{
projects:
serialize_as_json_for_environments
(
projects
)
}
render
json:
{
projects:
serialize_as_json_for_environments
(
projects
)
}
end
end
end
end
# Used by Operations and Environments dashboard.
def
create
def
create
respond_to
do
|
format
|
format
.
json
do
project_ids
=
params
[
'project_ids'
]
project_ids
=
params
[
'project_ids'
]
result
=
add_projects
(
project_ids
)
result
=
add_projects
(
project_ids
)
...
@@ -40,7 +50,10 @@ class OperationsController < ApplicationController
...
@@ -40,7 +50,10 @@ class OperationsController < ApplicationController
invalid:
result
.
invalid_project_ids
invalid:
result
.
invalid_project_ids
}
}
end
end
end
end
# Used by Operations and Environments dashboard.
def
destroy
def
destroy
project_id
=
params
[
'project_id'
]
project_id
=
params
[
'project_id'
]
...
@@ -57,6 +70,10 @@ class OperationsController < ApplicationController
...
@@ -57,6 +70,10 @@ class OperationsController < ApplicationController
render_404
unless
can?
(
current_user
,
:read_operations_dashboard
)
render_404
unless
can?
(
current_user
,
:read_operations_dashboard
)
end
end
def
set_polling_interval_header
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
POLLING_INTERVAL
)
end
def
load_projects
def
load_projects
Dashboard
::
Operations
::
ListService
.
new
(
current_user
).
execute
Dashboard
::
Operations
::
ListService
.
new
(
current_user
).
execute
end
end
...
...
ee/app/helpers/ee/operations_helper.rb
View file @
6d7078e7
...
@@ -6,8 +6,8 @@ module EE
...
@@ -6,8 +6,8 @@ module EE
def
operations_data
def
operations_data
{
{
'add-path'
=>
add_operations_project_path
,
'add-path'
=>
add_operations_project_path
(
format: :json
)
,
'list-path'
=>
operations_
list_path
,
'list-path'
=>
operations_
path
(
format: :json
)
,
'empty-dashboard-svg-path'
=>
image_path
(
'illustrations/operations-dashboard_empty.svg'
),
'empty-dashboard-svg-path'
=>
image_path
(
'illustrations/operations-dashboard_empty.svg'
),
'empty-dashboard-help-path'
=>
help_page_path
(
'user/operations_dashboard/index.md'
)
'empty-dashboard-help-path'
=>
help_page_path
(
'user/operations_dashboard/index.md'
)
}
}
...
@@ -15,8 +15,8 @@ module EE
...
@@ -15,8 +15,8 @@ module EE
def
environments_data
def
environments_data
{
{
'add-path'
=>
add_operations_
project_path
,
'add-path'
=>
add_operations_
environments_project_path
(
format: :json
)
,
'list-path'
=>
operations_environments_
list_path
,
'list-path'
=>
operations_environments_
path
(
format: :json
)
,
'empty-dashboard-svg-path'
=>
image_path
(
'illustrations/operations-dashboard_empty.svg'
),
'empty-dashboard-svg-path'
=>
image_path
(
'illustrations/operations-dashboard_empty.svg'
),
'empty-dashboard-help-path'
=>
help_page_path
(
'ci/environments/environments_dashboard.md'
),
'empty-dashboard-help-path'
=>
help_page_path
(
'ci/environments/environments_dashboard.md'
),
'environments-dashboard-help-path'
=>
help_page_path
(
'ci/environments/environments_dashboard.md'
)
'environments-dashboard-help-path'
=>
help_page_path
(
'ci/environments/environments_dashboard.md'
)
...
...
ee/app/serializers/dashboard_environments_project_entity.rb
View file @
6d7078e7
...
@@ -9,7 +9,7 @@ class DashboardEnvironmentsProjectEntity < Grape::Entity
...
@@ -9,7 +9,7 @@ class DashboardEnvironmentsProjectEntity < Grape::Entity
expose
:web_url
expose
:web_url
expose
:remove_path
do
|
project
|
expose
:remove_path
do
|
project
|
remove_operations_project_path
(
project_id:
project
.
id
)
remove_operations_
environments_
project_path
(
project_id:
project
.
id
)
end
end
expose
:namespace
,
using:
API
::
Entities
::
NamespaceBasic
expose
:namespace
,
using:
API
::
Entities
::
NamespaceBasic
...
...
ee/config/routes/operations.rb
View file @
6d7078e7
# frozen_string_literal: true
# frozen_string_literal: true
# Used by Operations dashboard
get
'operations'
=>
'operations#index'
get
'operations'
=>
'operations#index'
get
'operations/environments'
=>
'operations#environments'
get
'operations/list'
=>
'operations#list'
get
'operations/environments_list'
=>
'operations#environments_list'
post
'operations'
=>
'operations#create'
,
as: :add_operations_project
post
'operations'
=>
'operations#create'
,
as: :add_operations_project
delete
'operations'
=>
'operations#destroy'
,
as: :remove_operations_project
delete
'operations'
=>
'operations#destroy'
,
as: :remove_operations_project
# Used by Environments dashboard
get
'operations/environments'
=>
'operations#environments'
post
'operations/environments'
=>
'operations#create'
,
as: :add_operations_environments_project
delete
'operations/environments'
=>
'operations#destroy'
,
as: :remove_operations_environments_project
ee/spec/controllers/operations_controller_spec.rb
View file @
6d7078e7
This diff is collapsed.
Click to expand it.
ee/spec/fixtures/api/schemas/dashboard/operations/environments
_list
.json
→
ee/spec/fixtures/api/schemas/dashboard/operations/environments.json
View file @
6d7078e7
File moved
ee/spec/routing/operations_routing_spec.rb
0 → 100644
View file @
6d7078e7
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Operations routing'
,
'routing'
do
describe
'/-/operations'
do
it
'routes to the operations index action'
do
expect
(
get
(
"
#{
operations_path
}
.html"
)).
to
route_to
(
controller:
'operations'
,
action:
'index'
,
format:
'html'
)
expect
(
get
(
"
#{
operations_path
}
.json"
)).
to
route_to
(
controller:
'operations'
,
action:
'index'
,
format:
'json'
)
end
it
'routes to the operations create action'
do
expect
(
post
(
"
#{
add_operations_project_path
}
.json"
)).
to
route_to
(
controller:
'operations'
,
action:
'create'
,
format:
'json'
)
end
it
'routes to operations destroy action'
do
expect
(
delete
(
"
#{
remove_operations_project_path
}
.json"
)).
to
route_to
(
controller:
'operations'
,
action:
'destroy'
,
format:
'json'
)
end
end
describe
'/-/operations/environments'
do
it
'routes to the environments list action'
do
expect
(
get
(
"
#{
operations_environments_path
}
.html"
)).
to
route_to
(
controller:
'operations'
,
action:
'environments'
,
format:
'html'
)
expect
(
get
(
"
#{
operations_environments_path
}
.json"
)).
to
route_to
(
controller:
'operations'
,
action:
'environments'
,
format:
'json'
)
end
it
'routes to the environments create action'
do
expect
(
post
(
"
#{
add_operations_environments_project_path
}
.json"
)).
to
route_to
(
controller:
'operations'
,
action:
'create'
,
format:
'json'
)
end
it
'routes to environments destroy action'
do
expect
(
delete
(
"
#{
remove_operations_environments_project_path
}
.json"
)).
to
route_to
(
controller:
'operations'
,
action:
'destroy'
,
format:
'json'
)
end
end
end
ee/spec/views/operations/environments.html.haml_spec.rb
View file @
6d7078e7
...
@@ -6,8 +6,8 @@ RSpec.describe 'operations/environments.html.haml' do
...
@@ -6,8 +6,8 @@ RSpec.describe 'operations/environments.html.haml' do
it
'renders the frontend configuration'
do
it
'renders the frontend configuration'
do
render
render
expect
(
rendered
).
to
match
%r{data-add-path="/-/operations"}
expect
(
rendered
).
to
match
%r{data-add-path="/-/operations
/environments.json
"}
expect
(
rendered
).
to
match
%r{data-list-path="/-/operations/environments
_list
"}
expect
(
rendered
).
to
match
%r{data-list-path="/-/operations/environments
.json
"}
expect
(
rendered
).
to
match
%r{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*
\.
svg"}
expect
(
rendered
).
to
match
%r{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*
\.
svg"}
expect
(
rendered
).
to
match
%r{data-empty-dashboard-help-path="/help/ci/environments/environments_dashboard.md"}
expect
(
rendered
).
to
match
%r{data-empty-dashboard-help-path="/help/ci/environments/environments_dashboard.md"}
expect
(
rendered
).
to
match
%r{data-environments-dashboard-help-path="/help/ci/environments/environments_dashboard.md"}
expect
(
rendered
).
to
match
%r{data-environments-dashboard-help-path="/help/ci/environments/environments_dashboard.md"}
...
...
ee/spec/views/operations/index.html.haml_spec.rb
View file @
6d7078e7
...
@@ -6,8 +6,8 @@ RSpec.describe 'operations/index.html.haml' do
...
@@ -6,8 +6,8 @@ RSpec.describe 'operations/index.html.haml' do
it
'renders the frontend configuration'
do
it
'renders the frontend configuration'
do
render
render
expect
(
rendered
).
to
match
%r{data-add-path="/-/operations"}
expect
(
rendered
).
to
match
%r{data-add-path="/-/operations
.json
"}
expect
(
rendered
).
to
match
%r{data-list-path="/-/operations
/list
"}
expect
(
rendered
).
to
match
%r{data-list-path="/-/operations
.json
"}
expect
(
rendered
).
to
match
%{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*\.svg"}
expect
(
rendered
).
to
match
%{data-empty-dashboard-svg-path="/assets/illustrations/operations-dashboard_empty.*\.svg"}
expect
(
rendered
).
to
match
%r{data-empty-dashboard-help-path="/help/user/operations_dashboard/index.md"}
expect
(
rendered
).
to
match
%r{data-empty-dashboard-help-path="/help/user/operations_dashboard/index.md"}
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