Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ce-deploy-ui
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ccce
dev
ce-deploy-ui
Commits
cbe60efa
Commit
cbe60efa
authored
3 months ago
by
Max Frederiksen
Committed by
Max Frederiksen
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Add typing: /src/components/auth
parent
6a460085
No related branches found
No related tags found
2 merge requests
!612
Release 5.0.0
,
!590
CE-3429: Convert to typescript
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/auth/AccessControl/AccessControl.tsx
+31
-7
31 additions, 7 deletions
src/components/auth/AccessControl/AccessControl.tsx
src/components/auth/TokenRenew/TokenRenew.tsx
+2
-1
2 additions, 1 deletion
src/components/auth/TokenRenew/TokenRenew.tsx
with
33 additions
and
8 deletions
src/components/auth/AccessControl/AccessControl.tsx
+
31
−
7
View file @
cbe60efa
import
{
useContext
}
from
"
react
"
;
import
{
useContext
,
type
ReactNode
}
from
"
react
"
;
import
{
userContext
}
from
"
@ess-ics/ce-ui-common
"
;
import
{
userContext
}
from
"
@ess-ics/ce-ui-common
"
;
import
{
AccessDenied
}
from
"
../AccessDenied
"
;
import
{
AccessDenied
}
from
"
../AccessDenied
"
;
import
{
UserContext
}
from
"
../../../types/common
"
;
const
checkPermissions
=
(
userRoles
,
allowedRoles
)
=>
{
interface
AllowedUserWithRoles
{
user
:
string
;
role
:
string
;
}
interface
AccessControlProps
{
allowedRoles
:
string
[];
allowedUsersWithRoles
?:
AllowedUserWithRoles
[];
children
:
ReactNode
;
renderNoAccess
?:
()
=>
ReactNode
;
}
const
checkPermissions
=
(
userRoles
:
UserContext
[
"
userRoles
"
],
allowedRoles
:
string
[]
)
=>
{
if
(
allowedRoles
.
length
===
0
)
{
if
(
allowedRoles
.
length
===
0
)
{
return
true
;
return
true
;
}
}
...
@@ -10,15 +26,23 @@ const checkPermissions = (userRoles, allowedRoles) => {
...
@@ -10,15 +26,23 @@ const checkPermissions = (userRoles, allowedRoles) => {
return
userRoles
?.
some
((
role
)
=>
allowedRoles
.
includes
(
role
));
return
userRoles
?.
some
((
role
)
=>
allowedRoles
.
includes
(
role
));
};
};
const
checkUser
=
(
user
,
userRoles
,
allowedUsersWithRoles
)
=>
{
const
checkUser
=
(
if
(
!
allowedUsersWithRoles
||
allowedUsersWithRoles
.
length
===
0
)
{
user
:
UserContext
[
"
user
"
],
userRoles
:
UserContext
[
"
userRoles
"
],
allowedUsersWithRoles
?:
AllowedUserWithRoles
[]
)
=>
{
if
(
!
allowedUsersWithRoles
||
allowedUsersWithRoles
.
length
===
0
||
(
userRoles
&&
userRoles
.
length
===
0
)
)
{
return
false
;
return
false
;
}
}
return
allowedUsersWithRoles
.
find
(
return
allowedUsersWithRoles
.
find
(
(
userWithRole
)
=>
(
userWithRole
)
=>
userWithRole
.
user
===
user
?.
loginName
&&
userWithRole
.
user
===
user
?.
loginName
&&
userRoles
.
includes
(
userWithRole
.
role
)
userRoles
?
.
includes
(
userWithRole
.
role
)
);
);
};
};
...
@@ -27,8 +51,8 @@ export const AccessControl = ({
...
@@ -27,8 +51,8 @@ export const AccessControl = ({
allowedUsersWithRoles
,
allowedUsersWithRoles
,
children
,
children
,
renderNoAccess
renderNoAccess
})
=>
{
}
:
AccessControlProps
)
=>
{
const
{
user
,
userRoles
}
=
useContext
(
userContext
);
const
{
user
,
userRoles
}
=
useContext
<
UserContext
>
(
userContext
);
const
permitted
=
const
permitted
=
checkPermissions
(
userRoles
,
allowedRoles
)
||
checkPermissions
(
userRoles
,
allowedRoles
)
||
...
...
This diff is collapsed.
Click to expand it.
src/components/auth/TokenRenew/TokenRenew.tsx
+
2
−
1
View file @
cbe60efa
...
@@ -2,9 +2,10 @@ import { useContext, useEffect } from "react";
...
@@ -2,9 +2,10 @@ import { useContext, useEffect } from "react";
import
{
userContext
}
from
"
@ess-ics/ce-ui-common
"
;
import
{
userContext
}
from
"
@ess-ics/ce-ui-common
"
;
import
env
from
"
../../../config/env
"
;
import
env
from
"
../../../config/env
"
;
import
{
useTokenRenewMutation
}
from
"
../../../store/deployApi
"
;
import
{
useTokenRenewMutation
}
from
"
../../../store/deployApi
"
;
import
{
UserContext
}
from
"
../../../types/common
"
;
export
const
TokenRenew
=
()
=>
{
export
const
TokenRenew
=
()
=>
{
const
{
user
}
=
useContext
(
userContext
);
const
{
user
}
=
useContext
<
UserContext
>
(
userContext
);
const
[
renewToken
]
=
useTokenRenewMutation
();
const
[
renewToken
]
=
useTokenRenewMutation
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment