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
Jérome Perrin
gitlab-ce
Commits
83648f24
Commit
83648f24
authored
Dec 05, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move can_toggle_cluster? from helper to presenter
parent
2eb41b5a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
53 deletions
+47
-53
app/helpers/clusters_helper.rb
app/helpers/clusters_helper.rb
+0
-5
app/presenters/clusters/cluster_presenter.rb
app/presenters/clusters/cluster_presenter.rb
+4
-0
app/views/projects/clusters/_cluster.html.haml
app/views/projects/clusters/_cluster.html.haml
+2
-2
app/views/projects/clusters/index.html.haml
app/views/projects/clusters/index.html.haml
+1
-1
spec/helpers/clusters_helper_spec.rb
spec/helpers/clusters_helper_spec.rb
+0
-45
spec/presenters/clusters/cluster_presenter_spec.rb
spec/presenters/clusters/cluster_presenter_spec.rb
+40
-0
No files found.
app/helpers/clusters_helper.rb
deleted
100644 → 0
View file @
2eb41b5a
module
ClustersHelper
def
can_toggle_cluster?
(
cluster
)
can?
(
current_user
,
:update_cluster
,
cluster
)
&&
cluster
.
created?
end
end
app/presenters/clusters/cluster_presenter.rb
View file @
83648f24
...
...
@@ -5,5 +5,9 @@ module Clusters
def
gke_cluster_url
"https://console.cloud.google.com/kubernetes/clusters/details/
#{
provider
.
zone
}
/
#{
name
}
"
if
gcp?
end
def
can_toggle_cluster?
can?
(
current_user
,
:update_cluster
,
cluster
)
&&
created?
end
end
end
app/views/projects/clusters/_cluster.html.haml
View file @
83648f24
...
...
@@ -13,9 +13,9 @@
.table-mobile-header
{
role:
"rowheader"
}
.table-mobile-content
%button
{
type:
"button"
,
class:
"js-toggle-cluster-list project-feature-toggle #{'is-checked' if cluster.enabled?} #{'is-disabled' if !c
an_toggle_cluster?(cluster)
}"
,
class:
"js-toggle-cluster-list project-feature-toggle #{'is-checked' if cluster.enabled?} #{'is-disabled' if !c
luster.can_toggle_cluster?
}"
,
"aria-label"
:
s_
(
"ClusterIntegration|Toggle Cluster"
),
disabled:
!
c
an_toggle_cluster?
(
cluster
)
,
disabled:
!
c
luster
.
can_toggle_cluster?
,
data:
{
"enabled-text"
:
s_
(
"ClusterIntegration|Active"
),
"disabled-text"
:
s_
(
"ClusterIntegration|Inactive"
),
endpoint:
namespace_project_cluster_path
(
@project
.
namespace
,
@project
,
cluster
,
format: :json
)
}
}
...
...
app/views/projects/clusters/index.html.haml
View file @
83648f24
...
...
@@ -14,7 +14,7 @@
=
s_
(
"ClusterIntegration|Project namespace"
)
.table-section.section-10
{
role:
"rowheader"
}
-
@clusters
.
each
do
|
cluster
|
=
render
"cluster"
,
cluster:
cluster
=
render
"cluster"
,
cluster:
cluster
.
present
(
current_user:
current_user
)
=
paginate
@clusters
,
theme:
"gitlab"
-
elsif
@scope
==
'all'
=
render
"empty_state"
...
...
spec/helpers/clusters_helper_spec.rb
deleted
100644 → 0
View file @
2eb41b5a
require
'spec_helper'
describe
ClustersHelper
do
let
(
:cluster
)
{
create
(
:cluster
)
}
describe
'.can_toggle_cluster'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
subject
{
helper
.
can_toggle_cluster?
(
cluster
)
}
context
'when user can update'
do
before
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
any_args
).
and_return
(
true
)
end
context
'when cluster is created'
do
before
do
allow
(
cluster
).
to
receive
(
:created?
).
and_return
(
true
)
end
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'when cluster is not created'
do
before
do
allow
(
cluster
).
to
receive
(
:created?
).
and_return
(
false
)
end
it
{
is_expected
.
to
eq
(
false
)
}
end
end
context
'when user can not update'
do
before
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
any_args
).
and_return
(
false
)
end
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
spec/presenters/clusters/cluster_presenter_spec.rb
View file @
83648f24
...
...
@@ -31,4 +31,44 @@ describe Clusters::ClusterPresenter do
it
{
is_expected
.
to
include
(
cluster
.
provider
.
zone
)
}
it
{
is_expected
.
to
include
(
cluster
.
name
)
}
end
describe
'#can_toggle_cluster'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
cluster
).
to
receive
(
:current_user
).
and_return
(
user
)
end
subject
{
described_class
.
new
(
cluster
).
can_toggle_cluster?
}
context
'when user can update'
do
before
do
allow_any_instance_of
(
described_class
).
to
receive
(
:can?
).
with
(
user
,
:update_cluster
,
cluster
).
and_return
(
true
)
end
context
'when cluster is created'
do
before
do
allow
(
cluster
).
to
receive
(
:created?
).
and_return
(
true
)
end
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'when cluster is not created'
do
before
do
allow
(
cluster
).
to
receive
(
:created?
).
and_return
(
false
)
end
it
{
is_expected
.
to
eq
(
false
)
}
end
end
context
'when user can not update'
do
before
do
allow_any_instance_of
(
described_class
).
to
receive
(
:can?
).
with
(
user
,
:update_cluster
,
cluster
).
and_return
(
false
)
end
it
{
is_expected
.
to
eq
(
false
)
}
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