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
8c34f595
Commit
8c34f595
authored
Mar 14, 2019
by
Hugo Häggmark
Committed by
Leonard Gram
Mar 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
teams: disable new team button if user is viewer
parent
e3fc61b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
303 additions
and
4 deletions
+303
-4
public/app/features/teams/TeamList.test.tsx
+43
-1
public/app/features/teams/TeamList.tsx
+10
-3
public/app/features/teams/__snapshots__/TeamList.test.tsx.snap
+250
-0
No files found.
public/app/features/teams/TeamList.test.tsx
View file @
8c34f595
import
React
from
'react'
;
import
React
from
'react'
;
import
{
shallow
}
from
'enzyme'
;
import
{
shallow
}
from
'enzyme'
;
import
{
Props
,
TeamList
}
from
'./TeamList'
;
import
{
Props
,
TeamList
}
from
'./TeamList'
;
import
{
NavModel
,
Team
}
from
'../../types'
;
import
{
NavModel
,
Team
,
OrgRole
}
from
'../../types'
;
import
{
getMockTeam
,
getMultipleMockTeams
}
from
'./__mocks__/teamMocks'
;
import
{
getMockTeam
,
getMultipleMockTeams
}
from
'./__mocks__/teamMocks'
;
import
{
User
}
from
'app/core/services/context_srv'
;
const
setup
=
(
propOverrides
?:
object
)
=>
{
const
setup
=
(
propOverrides
?:
object
)
=>
{
const
props
:
Props
=
{
const
props
:
Props
=
{
...
@@ -21,6 +22,11 @@ const setup = (propOverrides?: object) => {
...
@@ -21,6 +22,11 @@ const setup = (propOverrides?: object) => {
searchQuery
:
''
,
searchQuery
:
''
,
teamsCount
:
0
,
teamsCount
:
0
,
hasFetched
:
false
,
hasFetched
:
false
,
editorsCanAdmin
:
false
,
signedInUser
:
{
id
:
1
,
orgRole
:
OrgRole
.
Viewer
,
}
as
User
,
};
};
Object
.
assign
(
props
,
propOverrides
);
Object
.
assign
(
props
,
propOverrides
);
...
@@ -49,6 +55,42 @@ describe('Render', () => {
...
@@ -49,6 +55,42 @@ describe('Render', () => {
expect
(
wrapper
).
toMatchSnapshot
();
expect
(
wrapper
).
toMatchSnapshot
();
});
});
describe
(
'when feature toggle editorsCanAdmin is turned on'
,
()
=>
{
describe
(
'and signedin user is not viewer'
,
()
=>
{
it
(
'should enable the new team button'
,
()
=>
{
const
{
wrapper
}
=
setup
({
teams
:
getMultipleMockTeams
(
1
),
teamsCount
:
1
,
hasFetched
:
true
,
editorsCanAdmin
:
true
,
signedInUser
:
{
id
:
1
,
orgRole
:
OrgRole
.
Editor
,
}
as
User
,
});
expect
(
wrapper
).
toMatchSnapshot
();
});
});
describe
(
'and signedin user is a viewer'
,
()
=>
{
it
(
'should disable the new team button'
,
()
=>
{
const
{
wrapper
}
=
setup
({
teams
:
getMultipleMockTeams
(
1
),
teamsCount
:
1
,
hasFetched
:
true
,
editorsCanAdmin
:
true
,
signedInUser
:
{
id
:
1
,
orgRole
:
OrgRole
.
Viewer
,
}
as
User
,
});
expect
(
wrapper
).
toMatchSnapshot
();
});
});
});
});
});
describe
(
'Life cycle'
,
()
=>
{
describe
(
'Life cycle'
,
()
=>
{
...
...
public/app/features/teams/TeamList.tsx
View file @
8c34f595
...
@@ -4,11 +4,13 @@ import { hot } from 'react-hot-loader';
...
@@ -4,11 +4,13 @@ import { hot } from 'react-hot-loader';
import
Page
from
'app/core/components/Page/Page'
;
import
Page
from
'app/core/components/Page/Page'
;
import
{
DeleteButton
}
from
'@grafana/ui'
;
import
{
DeleteButton
}
from
'@grafana/ui'
;
import
EmptyListCTA
from
'app/core/components/EmptyListCTA/EmptyListCTA'
;
import
EmptyListCTA
from
'app/core/components/EmptyListCTA/EmptyListCTA'
;
import
{
NavModel
,
Team
}
from
'app/types'
;
import
{
NavModel
,
Team
,
OrgRole
}
from
'app/types'
;
import
{
loadTeams
,
deleteTeam
,
setSearchQuery
}
from
'./state/actions'
;
import
{
loadTeams
,
deleteTeam
,
setSearchQuery
}
from
'./state/actions'
;
import
{
getSearchQuery
,
getTeams
,
getTeamsCount
}
from
'./state/selectors'
;
import
{
getSearchQuery
,
getTeams
,
getTeamsCount
}
from
'./state/selectors'
;
import
{
getNavModel
}
from
'app/core/selectors/navModel'
;
import
{
getNavModel
}
from
'app/core/selectors/navModel'
;
import
{
FilterInput
}
from
'app/core/components/FilterInput/FilterInput'
;
import
{
FilterInput
}
from
'app/core/components/FilterInput/FilterInput'
;
import
{
config
}
from
'app/core/config'
;
import
{
contextSrv
,
User
}
from
'app/core/services/context_srv'
;
export
interface
Props
{
export
interface
Props
{
navModel
:
NavModel
;
navModel
:
NavModel
;
...
@@ -19,6 +21,8 @@ export interface Props {
...
@@ -19,6 +21,8 @@ export interface Props {
loadTeams
:
typeof
loadTeams
;
loadTeams
:
typeof
loadTeams
;
deleteTeam
:
typeof
deleteTeam
;
deleteTeam
:
typeof
deleteTeam
;
setSearchQuery
:
typeof
setSearchQuery
;
setSearchQuery
:
typeof
setSearchQuery
;
editorsCanAdmin
?:
boolean
;
signedInUser
?:
User
;
}
}
export
class
TeamList
extends
PureComponent
<
Props
,
any
>
{
export
class
TeamList
extends
PureComponent
<
Props
,
any
>
{
...
@@ -84,7 +88,8 @@ export class TeamList extends PureComponent<Props, any> {
...
@@ -84,7 +88,8 @@ export class TeamList extends PureComponent<Props, any> {
}
}
renderTeamList
()
{
renderTeamList
()
{
const
{
teams
,
searchQuery
}
=
this
.
props
;
const
{
teams
,
searchQuery
,
editorsCanAdmin
,
signedInUser
}
=
this
.
props
;
const
disabledClass
=
editorsCanAdmin
&&
signedInUser
.
orgRole
===
OrgRole
.
Viewer
?
' disabled'
:
''
;
return
(
return
(
<>
<>
...
@@ -101,7 +106,7 @@ export class TeamList extends PureComponent<Props, any> {
...
@@ -101,7 +106,7 @@ export class TeamList extends PureComponent<Props, any> {
<
div
className=
"page-action-bar__spacer"
/>
<
div
className=
"page-action-bar__spacer"
/>
<
a
className=
"btn btn-primary"
href=
"org/teams/new"
>
<
a
className=
{
`btn btn-primary${disabledClass}`
}
href=
"org/teams/new"
>
New team
New team
</
a
>
</
a
>
</
div
>
</
div
>
...
@@ -152,6 +157,8 @@ function mapStateToProps(state) {
...
@@ -152,6 +157,8 @@ function mapStateToProps(state) {
searchQuery
:
getSearchQuery
(
state
.
teams
),
searchQuery
:
getSearchQuery
(
state
.
teams
),
teamsCount
:
getTeamsCount
(
state
.
teams
),
teamsCount
:
getTeamsCount
(
state
.
teams
),
hasFetched
:
state
.
teams
.
hasFetched
,
hasFetched
:
state
.
teams
.
hasFetched
,
editorsCanAdmin
:
config
.
editorsCanAdmin
,
// this makes the feature toggle mockable/controllable from tests,
signedInUser
:
contextSrv
.
user
,
// this makes the feature toggle mockable/controllable from tests,
};
};
}
}
...
...
public/app/features/teams/__snapshots__/TeamList.test.tsx.snap
View file @
8c34f595
...
@@ -343,3 +343,253 @@ exports[`Render should render teams table 1`] = `
...
@@ -343,3 +343,253 @@ exports[`Render should render teams table 1`] = `
</PageContents>
</PageContents>
</Page>
</Page>
`;
`;
exports[`Render when feature toggle editorsCanAdmin is turned on and signedin user is a viewer should disable the new team button 1`] = `
<Page
navModel={
Object {
"main": Object {
"text": "Configuration",
},
"node": Object {
"text": "Team List",
},
}
}
>
<PageContents
isLoading={false}
>
<div
className="page-action-bar"
>
<div
className="gf-form gf-form--grow"
>
<ForwardRef
inputClassName="gf-form-input"
labelClassName="gf-form--has-input-icon gf-form--grow"
onChange={[Function]}
placeholder="Search teams"
value=""
/>
</div>
<div
className="page-action-bar__spacer"
/>
<a
className="btn btn-primary disabled"
href="org/teams/new"
>
New team
</a>
</div>
<div
className="admin-list-table"
>
<table
className="filter-table filter-table--hover form-inline"
>
<thead>
<tr>
<th />
<th>
Name
</th>
<th>
Email
</th>
<th>
Members
</th>
<th
style={
Object {
"width": "1%",
}
}
/>
</tr>
</thead>
<tbody>
<tr
key="1"
>
<td
className="width-4 text-center link-td"
>
<a
href="org/teams/edit/1"
>
<img
className="filter-table__avatar"
src="some/url/"
/>
</a>
</td>
<td
className="link-td"
>
<a
href="org/teams/edit/1"
>
test-1
</a>
</td>
<td
className="link-td"
>
<a
href="org/teams/edit/1"
>
test-1@test.com
</a>
</td>
<td
className="link-td"
>
<a
href="org/teams/edit/1"
>
1
</a>
</td>
<td
className="text-right"
>
<DeleteButton
onConfirm={[Function]}
/>
</td>
</tr>
</tbody>
</table>
</div>
</PageContents>
</Page>
`;
exports[`Render when feature toggle editorsCanAdmin is turned on and signedin user is not viewer should enable the new team button 1`] = `
<Page
navModel={
Object {
"main": Object {
"text": "Configuration",
},
"node": Object {
"text": "Team List",
},
}
}
>
<PageContents
isLoading={false}
>
<div
className="page-action-bar"
>
<div
className="gf-form gf-form--grow"
>
<ForwardRef
inputClassName="gf-form-input"
labelClassName="gf-form--has-input-icon gf-form--grow"
onChange={[Function]}
placeholder="Search teams"
value=""
/>
</div>
<div
className="page-action-bar__spacer"
/>
<a
className="btn btn-primary"
href="org/teams/new"
>
New team
</a>
</div>
<div
className="admin-list-table"
>
<table
className="filter-table filter-table--hover form-inline"
>
<thead>
<tr>
<th />
<th>
Name
</th>
<th>
Email
</th>
<th>
Members
</th>
<th
style={
Object {
"width": "1%",
}
}
/>
</tr>
</thead>
<tbody>
<tr
key="1"
>
<td
className="width-4 text-center link-td"
>
<a
href="org/teams/edit/1"
>
<img
className="filter-table__avatar"
src="some/url/"
/>
</a>
</td>
<td
className="link-td"
>
<a
href="org/teams/edit/1"
>
test-1
</a>
</td>
<td
className="link-td"
>
<a
href="org/teams/edit/1"
>
test-1@test.com
</a>
</td>
<td
className="link-td"
>
<a
href="org/teams/edit/1"
>
1
</a>
</td>
<td
className="text-right"
>
<DeleteButton
onConfirm={[Function]}
/>
</td>
</tr>
</tbody>
</table>
</div>
</PageContents>
</Page>
`;
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