Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
f347ead8
Commit
f347ead8
authored
Jun 27, 2018
by
ubbcou
Committed by
ιεΈ
Jun 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check it when authority is string and currentAuthority is array. And update CheckPermissions test
parent
fdd6035f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
src/components/Authorized/CheckPermissions.js
src/components/Authorized/CheckPermissions.js
+8
-0
src/components/Authorized/CheckPermissions.test.js
src/components/Authorized/CheckPermissions.test.js
+18
-0
No files found.
src/components/Authorized/CheckPermissions.js
View file @
f347ead8
...
...
@@ -45,6 +45,14 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => {
if
(
authority
===
currentAuthority
)
{
return
target
;
}
if
(
Array
.
isArray
(
currentAuthority
))
{
for
(
let
i
=
0
;
i
<
currentAuthority
.
length
;
i
+=
1
)
{
const
element
=
currentAuthority
[
i
];
if
(
authority
.
indexOf
(
element
)
>=
0
)
{
return
target
;
}
}
}
return
Exception
;
}
...
...
src/components/Authorized/CheckPermissions.test.js
View file @
f347ead8
...
...
@@ -34,4 +34,22 @@ describe('test CheckPermissions', () => {
it
(
'
Correct Function permission authentication
'
,
()
=>
{
expect
(
checkPermissions
(()
=>
true
,
'
guest
'
,
target
,
error
)).
toEqual
(
'
ok
'
);
});
it
(
'
authority is string, currentAuthority is array, return ok
'
,
()
=>
{
expect
(
checkPermissions
(
'
user
'
,
[
'
user
'
],
target
,
error
)).
toEqual
(
'
ok
'
);
});
it
(
'
authority is string, currentAuthority is array, return ok
'
,
()
=>
{
expect
(
checkPermissions
(
'
user
'
,
[
'
user
'
,
'
admin
'
],
target
,
error
)).
toEqual
(
'
ok
'
);
});
it
(
'
authority is array, currentAuthority is array, return ok
'
,
()
=>
{
expect
(
checkPermissions
([
'
user
'
,
'
admin
'
],
[
'
user
'
,
'
admin
'
],
target
,
error
)).
toEqual
(
'
ok
'
);
});
it
(
'
Wrong Function permission authentication
'
,
()
=>
{
expect
(
checkPermissions
(()
=>
false
,
[
'
user
'
],
target
,
error
)).
toEqual
(
'
error
'
);
});
it
(
'
Correct Function permission authentication
'
,
()
=>
{
expect
(
checkPermissions
(()
=>
true
,
[
'
user
'
],
target
,
error
)).
toEqual
(
'
ok
'
);
});
it
(
'
authority is undefined , return ok
'
,
()
=>
{
expect
(
checkPermissions
(
null
,
[
'
user
'
],
target
,
error
)).
toEqual
(
'
ok
'
);
});
});
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