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
4d9ede0b
Commit
4d9ede0b
authored
Oct 12, 2018
by
Peter Leitzen
Committed by
Sean McGivern
Oct 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport CE changes for Ops Dashboard in EE
parent
0047869c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
23 deletions
+89
-23
app/finders/projects_finder.rb
app/finders/projects_finder.rb
+16
-11
app/helpers/preferences_helper.rb
app/helpers/preferences_helper.rb
+25
-11
app/models/deployment.rb
app/models/deployment.rb
+11
-0
app/models/environment.rb
app/models/environment.rb
+2
-0
app/models/user.rb
app/models/user.rb
+1
-1
app/views/layouts/nav/_dashboard.html.haml
app/views/layouts/nav/_dashboard.html.haml
+1
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/helpers/preferences_helper_spec.rb
spec/helpers/preferences_helper_spec.rb
+7
-0
spec/models/deployment_spec.rb
spec/models/deployment_spec.rb
+23
-0
No files found.
app/finders/projects_finder.rb
View file @
4d9ede0b
...
@@ -42,17 +42,7 @@ class ProjectsFinder < UnionFinder
...
@@ -42,17 +42,7 @@ class ProjectsFinder < UnionFinder
init_collection
init_collection
end
end
collection
=
by_ids
(
collection
)
collection
=
filter_projects
(
collection
)
collection
=
by_personal
(
collection
)
collection
=
by_starred
(
collection
)
collection
=
by_trending
(
collection
)
collection
=
by_visibilty_level
(
collection
)
collection
=
by_tags
(
collection
)
collection
=
by_search
(
collection
)
collection
=
by_archived
(
collection
)
collection
=
by_custom_attributes
(
collection
)
collection
=
by_deleted_status
(
collection
)
sort
(
collection
)
sort
(
collection
)
end
end
...
@@ -66,6 +56,21 @@ class ProjectsFinder < UnionFinder
...
@@ -66,6 +56,21 @@ class ProjectsFinder < UnionFinder
end
end
end
end
# EE would override this to add more filters
def
filter_projects
(
collection
)
collection
=
by_ids
(
collection
)
collection
=
by_personal
(
collection
)
collection
=
by_starred
(
collection
)
collection
=
by_trending
(
collection
)
collection
=
by_visibilty_level
(
collection
)
collection
=
by_tags
(
collection
)
collection
=
by_search
(
collection
)
collection
=
by_archived
(
collection
)
collection
=
by_custom_attributes
(
collection
)
collection
=
by_deleted_status
(
collection
)
collection
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
collection_with_user
def
collection_with_user
if
owned_projects?
if
owned_projects?
...
...
app/helpers/preferences_helper.rb
View file @
4d9ede0b
...
@@ -18,22 +18,20 @@ module PreferencesHelper
...
@@ -18,22 +18,20 @@ module PreferencesHelper
groups:
_
(
"Your Groups"
),
groups:
_
(
"Your Groups"
),
todos:
_
(
"Your Todos"
),
todos:
_
(
"Your Todos"
),
issues:
_
(
"Assigned Issues"
),
issues:
_
(
"Assigned Issues"
),
merge_requests:
_
(
"Assigned Merge Requests"
)
merge_requests:
_
(
"Assigned Merge Requests"
),
operations:
_
(
"Operations Dashboard"
)
}.
with_indifferent_access
.
freeze
}.
with_indifferent_access
.
freeze
# Returns an Array usable by a select field for more user-friendly option text
# Returns an Array usable by a select field for more user-friendly option text
def
dashboard_choices
def
dashboard_choices
d
efined
=
User
.
dashboard
s
d
ashboards
=
User
.
dashboards
.
key
s
if
defined
.
size
!=
DASHBOARD_CHOICES
.
size
validate_dashboard_choices!
(
dashboards
)
# Ensure that anyone adding new options updates this method too
dashboards
-=
excluded_dashboard_choices
raise
"`User` defines
#{
defined
.
size
}
dashboard choices,"
\
" but `DASHBOARD_CHOICES` defined
#{
DASHBOARD_CHOICES
.
size
}
."
dashboards
.
map
do
|
key
|
else
# Use `fetch` so `KeyError` gets raised when a key is missing
defined
.
map
do
|
key
,
_
|
[
DASHBOARD_CHOICES
.
fetch
(
key
),
key
]
# Use `fetch` so `KeyError` gets raised when a key is missing
[
DASHBOARD_CHOICES
.
fetch
(
key
),
key
]
end
end
end
end
end
...
@@ -52,4 +50,20 @@ module PreferencesHelper
...
@@ -52,4 +50,20 @@ module PreferencesHelper
def
user_color_scheme
def
user_color_scheme
Gitlab
::
ColorSchemes
.
for_user
(
current_user
).
css_class
Gitlab
::
ColorSchemes
.
for_user
(
current_user
).
css_class
end
end
private
# Ensure that anyone adding new options updates `DASHBOARD_CHOICES` too
def
validate_dashboard_choices!
(
user_dashboards
)
if
user_dashboards
.
size
!=
DASHBOARD_CHOICES
.
size
raise
"`User` defines
#{
user_dashboards
.
size
}
dashboard choices,"
\
" but `DASHBOARD_CHOICES` defined
#{
DASHBOARD_CHOICES
.
size
}
."
end
end
# List of dashboard choice to be excluded from CE.
# EE would override this.
def
excluded_dashboard_choices
[
'operations'
]
end
end
end
app/models/deployment.rb
View file @
4d9ede0b
...
@@ -19,6 +19,17 @@ class Deployment < ActiveRecord::Base
...
@@ -19,6 +19,17 @@ class Deployment < ActiveRecord::Base
after_create
:create_ref
after_create
:create_ref
after_create
:invalidate_cache
after_create
:invalidate_cache
scope
:for_environment
,
->
(
environment
)
{
where
(
environment_id:
environment
)
}
def
self
.
last_for_environment
(
environment
)
ids
=
self
.
for_environment
(
environment
)
.
select
(
'MAX(id) AS id'
)
.
group
(
:environment_id
)
.
map
(
&
:id
)
find
(
ids
)
end
def
commit
def
commit
project
.
commit
(
sha
)
project
.
commit
(
sha
)
end
end
...
...
app/models/environment.rb
View file @
4d9ede0b
...
@@ -48,6 +48,8 @@ class Environment < ActiveRecord::Base
...
@@ -48,6 +48,8 @@ class Environment < ActiveRecord::Base
order
(
Gitlab
::
Database
.
nulls_first_order
(
"(
#{
max_deployment_id_sql
}
)"
,
'ASC'
))
order
(
Gitlab
::
Database
.
nulls_first_order
(
"(
#{
max_deployment_id_sql
}
)"
,
'ASC'
))
end
end
scope
:in_review_folder
,
->
{
where
(
environment_type:
"review"
)
}
scope
:in_review_folder
,
->
{
where
(
environment_type:
"review"
)
}
scope
:for_name
,
->
(
name
)
{
where
(
name:
name
)
}
scope
:for_project
,
->
(
project
)
{
where
(
project_id:
project
)
}
state_machine
:state
,
initial: :available
do
state_machine
:state
,
initial: :available
do
event
:start
do
event
:start
do
...
...
app/models/user.rb
View file @
4d9ede0b
...
@@ -217,7 +217,7 @@ class User < ActiveRecord::Base
...
@@ -217,7 +217,7 @@ class User < ActiveRecord::Base
# User's Dashboard preference
# User's Dashboard preference
# Note: When adding an option, it MUST go on the end of the array.
# Note: When adding an option, it MUST go on the end of the array.
enum
dashboard:
[
:projects
,
:stars
,
:project_activity
,
:starred_project_activity
,
:groups
,
:todos
,
:issues
,
:merge_requests
]
enum
dashboard:
[
:projects
,
:stars
,
:project_activity
,
:starred_project_activity
,
:groups
,
:todos
,
:issues
,
:merge_requests
,
:operations
]
# User's Project preference
# User's Project preference
# Note: When adding an option, it MUST go on the end of the array.
# Note: When adding an option, it MUST go on the end of the array.
...
...
app/views/layouts/nav/_dashboard.html.haml
View file @
4d9ede0b
...
@@ -66,6 +66,7 @@
...
@@ -66,6 +66,7 @@
-
if
Gitlab
::
Sherlock
.
enabled?
||
can?
(
current_user
,
:read_instance_statistics
)
-
if
Gitlab
::
Sherlock
.
enabled?
||
can?
(
current_user
,
:read_instance_statistics
)
%li
.line-separator.d-none.d-sm-block
%li
.line-separator.d-none.d-sm-block
=
render_if_exists
'dashboard/operations/nav_link'
-
if
can?
(
current_user
,
:read_instance_statistics
)
-
if
can?
(
current_user
,
:read_instance_statistics
)
=
nav_link
(
controller:
[
:conversational_development_index
,
:cohorts
])
do
=
nav_link
(
controller:
[
:conversational_development_index
,
:cohorts
])
do
=
link_to
instance_statistics_root_path
,
title:
_
(
'Instance Statistics'
),
aria:
{
label:
_
(
'Instance Statistics'
)
},
data:
{
toggle:
'tooltip'
,
placement:
'bottom'
,
container:
'body'
}
do
=
link_to
instance_statistics_root_path
,
title:
_
(
'Instance Statistics'
),
aria:
{
label:
_
(
'Instance Statistics'
)
},
data:
{
toggle:
'tooltip'
,
placement:
'bottom'
,
container:
'body'
}
do
...
...
locale/gitlab.pot
View file @
4d9ede0b
...
@@ -4236,6 +4236,9 @@ msgstr ""
...
@@ -4236,6 +4236,9 @@ msgstr ""
msgid "Operations"
msgid "Operations"
msgstr ""
msgstr ""
msgid "Operations Dashboard"
msgstr ""
msgid "Optionally, you can %{link_to_customize} how FogBugz email addresses and usernames are imported into GitLab."
msgid "Optionally, you can %{link_to_customize} how FogBugz email addresses and usernames are imported into GitLab."
msgstr ""
msgstr ""
...
...
spec/helpers/preferences_helper_spec.rb
View file @
4d9ede0b
...
@@ -2,6 +2,13 @@ require 'spec_helper'
...
@@ -2,6 +2,13 @@ require 'spec_helper'
describe
PreferencesHelper
do
describe
PreferencesHelper
do
describe
'#dashboard_choices'
do
describe
'#dashboard_choices'
do
let
(
:user
)
{
build
(
:user
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
allow
(
helper
).
to
receive
(
:can?
).
and_return
(
false
)
end
it
'raises an exception when defined choices may be missing'
do
it
'raises an exception when defined choices may be missing'
do
expect
(
User
).
to
receive
(
:dashboards
).
and_return
(
foo:
'foo'
)
expect
(
User
).
to
receive
(
:dashboards
).
and_return
(
foo:
'foo'
)
expect
{
helper
.
dashboard_choices
}.
to
raise_error
(
RuntimeError
)
expect
{
helper
.
dashboard_choices
}.
to
raise_error
(
RuntimeError
)
...
...
spec/models/deployment_spec.rb
View file @
4d9ede0b
...
@@ -39,6 +39,29 @@ describe Deployment do
...
@@ -39,6 +39,29 @@ describe Deployment do
end
end
end
end
describe
'scopes'
do
describe
'last_for_environment'
do
let
(
:production
)
{
create
(
:environment
)
}
let
(
:staging
)
{
create
(
:environment
)
}
let
(
:testing
)
{
create
(
:environment
)
}
let!
(
:deployments
)
do
[
create
(
:deployment
,
environment:
production
),
create
(
:deployment
,
environment:
staging
),
create
(
:deployment
,
environment:
production
)
]
end
it
'retrieves last deployments for environments'
do
last_deployments
=
described_class
.
last_for_environment
([
staging
,
production
,
testing
])
expect
(
last_deployments
.
size
).
to
eq
(
2
)
expect
(
last_deployments
).
to
eq
(
deployments
.
last
(
2
))
end
end
end
describe
'#includes_commit?'
do
describe
'#includes_commit?'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
...
...
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