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
Boxiang Sun
gitlab-ce
Commits
9199d30a
Commit
9199d30a
authored
Dec 01, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add can_toggle_cluster? helper
parent
ce704a95
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
1 deletion
+51
-1
app/helpers/clusters_helper.rb
app/helpers/clusters_helper.rb
+5
-0
app/views/projects/clusters/_cluster.html.haml
app/views/projects/clusters/_cluster.html.haml
+1
-1
spec/helpers/clusters_helper_spec.rb
spec/helpers/clusters_helper_spec.rb
+45
-0
No files found.
app/helpers/clusters_helper.rb
0 → 100644
View file @
9199d30a
module
ClustersHelper
def
can_toggle_cluster?
(
cluster
)
can?
(
current_user
,
:update_cluster
,
cluster
)
&&
cluster
.
created?
end
end
app/views/projects/clusters/_cluster.html.haml
View file @
9199d30a
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
.table-mobile-header
{
role:
"rowheader"
}
.table-mobile-header
{
role:
"rowheader"
}
.table-mobile-content
.table-mobile-content
%button
{
type:
"button"
,
%button
{
type:
"button"
,
class:
"js-toggle-cluster-list project-feature-toggle #{'is-checked'
unless !cluster.enabled?} #{'is-disabled' unless can?(current_user, :update_cluster, cluster) && cluster.provider_gcp&.created?
}"
,
class:
"js-toggle-cluster-list project-feature-toggle #{'is-checked'
if cluster.enabled?} #{'is-disabled' if can_toggle_cluster?(cluster)
}"
,
"aria-label"
:
s_
(
"ClusterIntegration|Toggle Cluster"
),
"aria-label"
:
s_
(
"ClusterIntegration|Toggle Cluster"
),
disabled:
!
can?
(
current_user
,
:update_cluster
,
cluster
),
disabled:
!
can?
(
current_user
,
:update_cluster
,
cluster
),
data:
{
"enabled-text"
:
s_
(
"ClusterIntegration|Active"
),
data:
{
"enabled-text"
:
s_
(
"ClusterIntegration|Active"
),
...
...
spec/helpers/clusters_helper_spec.rb
0 → 100644
View file @
9199d30a
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
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