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
97ff245a
Commit
97ff245a
authored
Jun 23, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashfolders: validation for duplicates in acl modal
parent
b7255723
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
2 deletions
+103
-2
public/app/features/dashboard/acl/acl.html
+9
-2
public/app/features/dashboard/acl/acl.ts
+24
-0
public/app/features/dashboard/acl/specs/acl_specs.ts
+70
-0
No files found.
public/app/features/dashboard/acl/acl.html
View file @
97ff245a
...
...
@@ -39,6 +39,7 @@
</tr>
</table>
<div
class=
"gf-form-inline"
>
<form
name=
"addPermission"
class=
"gf-form-group"
>
<h6
class=
"muted"
>
Add Permission For
</h6>
<div
class=
"gf-form-inline"
>
...
...
@@ -55,6 +56,13 @@
</div>
</div>
</form>
<div
class=
"gf-form width-17"
>
<span
ng-if=
"ctrl.error"
class=
"text-error p-l-1"
>
<i
class=
"fa fa-warning"
></i>
{{ctrl.error}}
</span>
</div>
</div>
<div
class=
"gf-form-button-row text-center"
>
<button
type=
"button"
class=
"btn btn-danger"
ng-disabled=
"!ctrl.canUpdate"
ng-click=
"ctrl.update()"
>
...
...
@@ -62,9 +70,8 @@
</button>
<a
class=
"btn-text"
ng-click=
"ctrl.dismiss();"
>
Close
</a>
</div>
</div>
</div>
</div>
<!-- <br> -->
<!-- <br> -->
...
...
public/app/features/dashboard/acl/acl.ts
View file @
97ff245a
...
...
@@ -22,6 +22,8 @@ export class AclCtrl {
dismiss
:
()
=>
void
;
newType
:
string
;
canUpdate
:
boolean
;
error
:
string
;
readonly
duplicateError
=
'This permission exists already.'
;
/** @ngInject */
constructor
(
private
backendSrv
,
private
dashboardSrv
,
private
$sce
,
private
$scope
)
{
...
...
@@ -111,6 +113,11 @@ export class AclCtrl {
}
addNewItem
(
item
)
{
if
(
!
this
.
isValid
(
item
))
{
return
;
}
this
.
error
=
''
;
item
.
dashboardId
=
this
.
dashboard
.
id
;
this
.
items
.
push
(
this
.
prepareViewModel
(
item
));
...
...
@@ -119,6 +126,23 @@ export class AclCtrl {
this
.
canUpdate
=
true
;
}
isValid
(
item
)
{
const
dupe
=
_
.
find
(
this
.
items
,
(
it
)
=>
{
return
this
.
isDuplicate
(
it
,
item
);
});
if
(
dupe
)
{
this
.
error
=
this
.
duplicateError
;
return
false
;
}
return
true
;
}
isDuplicate
(
origItem
,
newItem
)
{
return
(
origItem
.
role
&&
newItem
.
role
&&
origItem
.
role
===
newItem
.
role
)
||
(
origItem
.
userId
&&
newItem
.
userId
&&
origItem
.
userId
===
newItem
.
userId
)
||
(
origItem
.
userGroupId
&&
newItem
.
userGroupId
&&
origItem
.
userGroupId
===
newItem
.
userGroupId
);
}
userPicked
(
user
)
{
this
.
addNewItem
({
userId
:
user
.
id
,
userLogin
:
user
.
login
,
permission
:
1
,});
this
.
$scope
.
$broadcast
(
'user-picker-reset'
);
...
...
public/app/features/dashboard/acl/specs/acl_specs.ts
View file @
97ff245a
...
...
@@ -77,4 +77,74 @@ describe('AclCtrl', () => {
expect
(
backendSrv
.
post
.
getCall
(
0
).
args
[
1
].
items
[
3
].
permission
).
to
.
eql
(
1
);
});
});
describe
(
'when duplicate role permissions are added'
,
()
=>
{
beforeEach
(()
=>
{
backendSrv
.
get
.
reset
();
backendSrv
.
post
.
reset
();
ctx
.
ctrl
.
items
=
[];
ctx
.
ctrl
.
newType
=
'Editor'
;
ctx
.
ctrl
.
typeChanged
();
ctx
.
ctrl
.
newType
=
'Editor'
;
ctx
.
ctrl
.
typeChanged
();
});
it
(
'should throw a validation error'
,
()
=>
{
expect
(
ctx
.
ctrl
.
error
).
to
.
eql
(
ctx
.
ctrl
.
duplicateError
);
});
it
(
'should not add the duplicate permission'
,
()
=>
{
expect
(
ctx
.
ctrl
.
items
.
length
).
to
.
eql
(
1
);
});
});
describe
(
'when duplicate user permissions are added'
,
()
=>
{
beforeEach
(()
=>
{
backendSrv
.
get
.
reset
();
backendSrv
.
post
.
reset
();
ctx
.
ctrl
.
items
=
[];
const
userItem
=
{
id
:
2
,
login
:
'user2'
,
};
ctx
.
ctrl
.
userPicked
(
userItem
);
ctx
.
ctrl
.
userPicked
(
userItem
);
});
it
(
'should throw a validation error'
,
()
=>
{
expect
(
ctx
.
ctrl
.
error
).
to
.
eql
(
ctx
.
ctrl
.
duplicateError
);
});
it
(
'should not add the duplicate permission'
,
()
=>
{
expect
(
ctx
.
ctrl
.
items
.
length
).
to
.
eql
(
1
);
});
});
describe
(
'when duplicate user group permissions are added'
,
()
=>
{
beforeEach
(()
=>
{
backendSrv
.
get
.
reset
();
backendSrv
.
post
.
reset
();
ctx
.
ctrl
.
items
=
[];
const
userGroupItem
=
{
id
:
2
,
name
:
'ug1'
,
};
ctx
.
ctrl
.
groupPicked
(
userGroupItem
);
ctx
.
ctrl
.
groupPicked
(
userGroupItem
);
});
it
(
'should throw a validation error'
,
()
=>
{
expect
(
ctx
.
ctrl
.
error
).
to
.
eql
(
ctx
.
ctrl
.
duplicateError
);
});
it
(
'should not add the duplicate permission'
,
()
=>
{
expect
(
ctx
.
ctrl
.
items
.
length
).
to
.
eql
(
1
);
});
});
});
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