Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
b95650d1
Commit
b95650d1
authored
Jan 21, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added function hasAccessToExplore in ContextSrv and refactored tests
parent
9d6ac2c3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
38 deletions
+24
-38
public/app/core/services/context_srv.ts
+4
-0
public/app/core/services/keybindingSrv.ts
+1
-2
public/app/features/panel/metrics_panel_ctrl.ts
+3
-3
public/app/features/panel/specs/metrics_panel_ctrl.test.ts
+16
-33
No files found.
public/app/core/services/context_srv.ts
View file @
b95650d1
...
@@ -59,6 +59,10 @@ export class ContextSrv {
...
@@ -59,6 +59,10 @@ export class ContextSrv {
this
.
sidemenu
=
!
this
.
sidemenu
;
this
.
sidemenu
=
!
this
.
sidemenu
;
store
.
set
(
'grafana.sidemenu'
,
this
.
sidemenu
);
store
.
set
(
'grafana.sidemenu'
,
this
.
sidemenu
);
}
}
hasAccessToExplore
()
{
return
(
this
.
isEditor
||
config
.
viewersCanEdit
)
&&
config
.
exploreEnabled
;
}
}
}
const
contextSrv
=
new
ContextSrv
();
const
contextSrv
=
new
ContextSrv
();
...
...
public/app/core/services/keybindingSrv.ts
View file @
b95650d1
import
$
from
'jquery'
;
import
$
from
'jquery'
;
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
config
from
'app/core/config'
;
import
coreModule
from
'app/core/core_module'
;
import
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
import
appEvents
from
'app/core/app_events'
;
import
{
getExploreUrl
}
from
'app/core/utils/explore'
;
import
{
getExploreUrl
}
from
'app/core/utils/explore'
;
...
@@ -197,7 +196,7 @@ export class KeybindingSrv {
...
@@ -197,7 +196,7 @@ export class KeybindingSrv {
});
});
// jump to explore if permissions allow
// jump to explore if permissions allow
if
(
(
this
.
contextSrv
.
isEditor
||
config
.
viewersCanEdit
)
&&
config
.
exploreEnabled
)
{
if
(
this
.
contextSrv
.
hasAccessToExplore
()
)
{
this
.
bind
(
'x'
,
async
()
=>
{
this
.
bind
(
'x'
,
async
()
=>
{
if
(
dashboard
.
meta
.
focusPanelId
)
{
if
(
dashboard
.
meta
.
focusPanelId
)
{
const
panel
=
dashboard
.
getPanelById
(
dashboard
.
meta
.
focusPanelId
);
const
panel
=
dashboard
.
getPanelById
(
dashboard
.
meta
.
focusPanelId
);
...
...
public/app/features/panel/metrics_panel_ctrl.ts
View file @
b95650d1
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
kbn
from
'app/core/utils/kbn'
;
import
kbn
from
'app/core/utils/kbn'
;
import
config
from
'app/core/config'
;
import
{
PanelCtrl
}
from
'app/features/panel/panel_ctrl'
;
import
{
PanelCtrl
}
from
'app/features/panel/panel_ctrl'
;
import
{
getExploreUrl
}
from
'app/core/utils/explore'
;
import
{
getExploreUrl
}
from
'app/core/utils/explore'
;
import
{
applyPanelTimeOverrides
,
getResolution
}
from
'app/features/dashboard/utils/panel'
;
import
{
applyPanelTimeOverrides
,
getResolution
}
from
'app/features/dashboard/utils/panel'
;
import
{
ContextSrv
}
from
'app/core/services/context_srv'
;
class
MetricsPanelCtrl
extends
PanelCtrl
{
class
MetricsPanelCtrl
extends
PanelCtrl
{
scope
:
any
;
scope
:
any
;
datasource
:
any
;
datasource
:
any
;
$q
:
any
;
$q
:
any
;
$timeout
:
any
;
$timeout
:
any
;
contextSrv
:
any
;
contextSrv
:
ContextSrv
;
datasourceSrv
:
any
;
datasourceSrv
:
any
;
timeSrv
:
any
;
timeSrv
:
any
;
templateSrv
:
any
;
templateSrv
:
any
;
...
@@ -231,7 +231,7 @@ class MetricsPanelCtrl extends PanelCtrl {
...
@@ -231,7 +231,7 @@ class MetricsPanelCtrl extends PanelCtrl {
getAdditionalMenuItems
()
{
getAdditionalMenuItems
()
{
const
items
=
[];
const
items
=
[];
if
(
config
.
exploreEnabled
&&
(
this
.
contextSrv
.
isEditor
||
config
.
viewersCanEdit
)
&&
this
.
datasource
)
{
if
(
this
.
contextSrv
.
hasAccessToExplore
(
)
&&
this
.
datasource
)
{
items
.
push
({
items
.
push
({
text
:
'Explore'
,
text
:
'Explore'
,
click
:
'ctrl.explore();'
,
click
:
'ctrl.explore();'
,
...
...
public/app/features/panel/specs/metrics_panel_ctrl.test.ts
View file @
b95650d1
jest
.
mock
(
'app/core/core'
,
()
=>
({}));
jest
.
mock
(
'app/core/core'
,
()
=>
({}));
jest
.
mock
(
'app/core/config'
,
()
=>
{
jest
.
mock
(
'app/core/config'
,
()
=>
{
return
{
return
{
exploreEnabled
:
true
,
viewersCanEdit
:
false
,
panels
:
{
panels
:
{
test
:
{
test
:
{
id
:
'test'
,
id
:
'test'
,
...
@@ -15,62 +13,47 @@ jest.mock('app/core/config', () => {
...
@@ -15,62 +13,47 @@ jest.mock('app/core/config', () => {
import
q
from
'q'
;
import
q
from
'q'
;
import
{
PanelModel
}
from
'app/features/dashboard/panel_model'
;
import
{
PanelModel
}
from
'app/features/dashboard/panel_model'
;
import
{
MetricsPanelCtrl
}
from
'../metrics_panel_ctrl'
;
import
{
MetricsPanelCtrl
}
from
'../metrics_panel_ctrl'
;
import
config
from
'app/core/config'
;
describe
(
'MetricsPanelCtrl'
,
()
=>
{
describe
(
'MetricsPanelCtrl'
,
()
=>
{
let
ctrl
;
beforeEach
(()
=>
{
ctrl
=
setupController
();
});
describe
(
'when getting additional menu items'
,
()
=>
{
describe
(
'when getting additional menu items'
,
()
=>
{
let
additionalItems
;
describe
(
'and has no datasource set but user has access to explore'
,
()
=>
{
describe
(
'and has no datasource set'
,
()
=>
{
beforeEach
(()
=>
{
additionalItems
=
ctrl
.
getAdditionalMenuItems
();
});
it
(
'should not return any items'
,
()
=>
{
it
(
'should not return any items'
,
()
=>
{
expect
(
additionalItems
.
length
).
toBe
(
0
);
const
ctrl
=
setupController
({
hasAccessToExplore
:
true
});
expect
(
ctrl
.
getAdditionalMenuItems
().
length
).
toBe
(
0
);
});
});
});
});
describe
(
'and has datasource set that supports explore and user
has powers
'
,
()
=>
{
describe
(
'and has datasource set that supports explore and user
does not have access to explore
'
,
()
=>
{
beforeEach
(
()
=>
{
it
(
'should not return any items'
,
()
=>
{
c
trl
.
contextSrv
=
{
isEditor
:
true
}
;
c
onst
ctrl
=
setupController
({
hasAccessToExplore
:
false
})
;
ctrl
.
datasource
=
{
meta
:
{
explore
:
true
}
};
ctrl
.
datasource
=
{
meta
:
{
explore
:
true
}
};
additionalItems
=
ctrl
.
getAdditionalMenuItems
();
});
it
(
'should not return any items'
,
()
=>
{
expect
(
ctrl
.
getAdditionalMenuItems
().
length
).
toBe
(
0
);
expect
(
additionalItems
.
length
).
toBe
(
1
);
});
});
});
});
describe
(
'and has datasource set that supports explore and viewersCanEdit is true'
,
()
=>
{
describe
(
'and has datasource set that supports explore and user has access to explore'
,
()
=>
{
beforeEach
(()
=>
{
it
(
'should return one item'
,
()
=>
{
config
.
viewersCanEdit
=
true
;
const
ctrl
=
setupController
({
hasAccessToExplore
:
true
});
ctrl
.
contextSrv
=
{
isEditor
:
false
};
ctrl
.
datasource
=
{
meta
:
{
explore
:
true
}
};
ctrl
.
datasource
=
{
meta
:
{
explore
:
true
}
};
additionalItems
=
ctrl
.
getAdditionalMenuItems
();
});
it
(
'should not return any items'
,
()
=>
{
expect
(
ctrl
.
getAdditionalMenuItems
().
length
).
toBe
(
1
);
expect
(
additionalItems
.
length
).
toBe
(
1
);
});
});
});
});
});
});
});
});
function
setupController
()
{
function
setupController
(
{
hasAccessToExplore
}
=
{
hasAccessToExplore
:
false
}
)
{
const
injectorStub
=
{
const
injectorStub
=
{
get
:
type
=>
{
get
:
type
=>
{
switch
(
type
)
{
switch
(
type
)
{
case
'$q'
:
{
case
'$q'
:
{
return
q
;
return
q
;
}
}
case
'contextSrv'
:
{
return
{
hasAccessToExplore
:
()
=>
hasAccessToExplore
};
}
default
:
{
default
:
{
return
jest
.
fn
();
return
jest
.
fn
();
}
}
...
...
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