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
878b03ac
Commit
878b03ac
authored
3 years ago
by
Zoltan Runyo
Browse files
Options
Downloads
Patches
Plain Diff
ICSHWI-8186
: Read user roles from backend API
parent
41d02bff
No related branches found
No related tags found
1 merge request
!81
Icshwi 7851 access levels
Pipeline
#99429
passed
3 years ago
Stage: build
Stage: lint
Stage: test
Stage: package
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/api/SwaggerApi.js
+28
-15
28 additions, 15 deletions
src/api/SwaggerApi.js
src/components/auth/TokenRenew.js
+5
-4
5 additions, 4 deletions
src/components/auth/TokenRenew.js
src/views/home/HomeView.js
+3
-1
3 additions, 1 deletion
src/views/home/HomeView.js
with
36 additions
and
20 deletions
src/api/SwaggerApi.js
+
28
−
15
View file @
878b03ac
...
@@ -34,19 +34,20 @@ export function useAPI() {
...
@@ -34,19 +34,20 @@ export function useAPI() {
}
}
export
const
apiContext
=
createContext
(
null
);
export
const
apiContext
=
createContext
(
null
);
export
const
userContext
=
createContext
({
user
:
null
,
login
:
()
=>
{},
logout
:
()
=>
{}
});
export
const
userContext
=
createContext
({
user
:
null
,
userRoles
:[],
getUserRoles
:
()
=>
{},
login
:
()
=>
{},
logout
:
()
=>
{}
});
export
function
UserProvider
({
children
})
{
export
function
UserProvider
({
children
})
{
const
[
user
,
setUser
]
=
useState
();
const
[
user
,
setUser
]
=
useState
();
const
[
userRoles
,
getUserRoles
]
=
useUserRoles
();
const
[
userInfo
,
getUserInfo
]
=
useUserInfo
();
const
[
userInfo
,
getUserInfo
]
=
useUserInfo
();
const
[
isLoggedIn
,
loginFcn
]
=
useLogin
();
const
[
loginResponse
,
loginFcn
]
=
useLogin
();
const
logoutFcn
=
useLogout
();
const
logoutFcn
=
useLogout
();
const
history
=
useHistory
();
const
history
=
useHistory
();
console
.
log
(
"
rendering UserProvider
"
)
console
.
log
(
"
rendering UserProvider
"
)
console
.
log
(
user
);
console
.
log
(
user
);
useEffect
(
getUserInfo
,
[
isLoggedIn
,
getUserInfo
]);
useEffect
(
getUserInfo
,
[
Boolean
(
loginResponse
)
,
getUserInfo
]);
useEffect
(()
=>
userInfo
&&
setUser
(
userInfo
),
[
setUser
,
userInfo
]);
useEffect
(()
=>
userInfo
&&
setUser
(
userInfo
),
[
setUser
,
userInfo
]);
const
logout
=
async
()
=>
{
const
logout
=
async
()
=>
{
...
@@ -58,12 +59,14 @@ export function UserProvider({ children }) {
...
@@ -58,12 +59,14 @@ export function UserProvider({ children }) {
const
login
=
async
(
username
,
password
)
=>
{
const
login
=
async
(
username
,
password
)
=>
{
console
.
log
(
"
Logging in!
"
);
console
.
log
(
"
Logging in!
"
);
await
loginFcn
(
username
,
password
);
await
loginFcn
(
username
,
password
);
await
getUserRoles
();
setUser
(
await
getUserInfo
());
setUser
(
await
getUserInfo
());
console
.
log
(
history
);
console
.
log
(
history
);
console
.
log
(
userRoles
);
}
}
return
(
return
(
<
userContext
.
Provider
value
=
{{
user
,
login
,
logout
}}
>
<
userContext
.
Provider
value
=
{{
user
,
userRoles
,
getUserRoles
,
login
,
logout
}}
>
{
children
}
{
children
}
<
/userContext.Provider
>
<
/userContext.Provider
>
);
);
...
@@ -372,21 +375,21 @@ export function useHostIOCList(id) {
...
@@ -372,21 +375,21 @@ export function useHostIOCList(id) {
}
}
export
function
unpackLogin
(
loginResponse
)
{
export
function
unpackLogin
(
loginResponse
)
{
console
.
log
(
loginResponse
)
return
{
...
loginResponse
};
const
isLoggedIn
=
Boolean
(
loginResponse
);
return
isLoggedIn
;
}
}
export
function
useLogin
()
{
export
function
useLogin
()
{
const
api
=
useContext
(
apiContext
);
const
api
=
useContext
(
apiContext
);
const
callLogin
=
(
u
,
p
)
=>
api
.
apis
.
Authentication
.
login
({},
{
const
method
=
callAndUnpack
(
requestBody
:
{
(
username
,
password
)
=>
api
.
apis
.
Authentication
.
login
({},{
userName
:
u
,
requestBody
:
{
password
:
p
userName
:
username
,
}
password
:
password
});
}
const
method
=
callAndUnpack
(
callLogin
,
unpackLogin
)
}),
return
useAsync
({
fcn
:
method
,
call
:
false
})
unpackLogin
);
return
useAsync
({
fcn
:
method
,
call
:
false
});
}
}
export
function
unpackUser
(
user
)
{
export
function
unpackUser
(
user
)
{
...
@@ -399,6 +402,16 @@ export function useUserInfo() {
...
@@ -399,6 +402,16 @@ export function useUserInfo() {
return
useAsync
({
fcn
:
method
,
call
:
false
});
return
useAsync
({
fcn
:
method
,
call
:
false
});
}
}
export
function
unpackUserRoles
(
roles
)
{
return
{
...
roles
};
}
export
function
useUserRoles
()
{
const
api
=
useContext
(
apiContext
);
const
method
=
callAndUnpack
(
api
.
apis
.
Authentication
.
getUserRoles
,
unpackUserRoles
);
return
useAsync
({
fcn
:
method
,
call
:
false
});
}
export
function
useLogout
()
{
export
function
useLogout
()
{
const
api
=
useContext
(
apiContext
);
const
api
=
useContext
(
apiContext
);
const
method
=
callAndUnpack
(
api
.
apis
.
Authentication
.
logout
);
const
method
=
callAndUnpack
(
api
.
apis
.
Authentication
.
logout
);
...
...
This diff is collapsed.
Click to expand it.
src/components/auth/TokenRenew.js
+
5
−
4
View file @
878b03ac
...
@@ -2,17 +2,18 @@ import { useEffect, useContext } from "react";
...
@@ -2,17 +2,18 @@ import { useEffect, useContext } from "react";
import
{
useRenewToken
,
userContext
}
from
"
../../api/SwaggerApi
"
;
import
{
useRenewToken
,
userContext
}
from
"
../../api/SwaggerApi
"
;
export
default
function
TokenRenew
()
{
export
default
function
TokenRenew
()
{
const
{
user
}
=
useContext
(
userContext
);
const
{
user
,
getUserRoles
}
=
useContext
(
userContext
);
const
renewToken
=
useRenewToken
();
const
renewToken
=
useRenewToken
();
useEffect
(()
=>
{
useEffect
(()
=>
{
const
interval
=
setInterval
(()
=>
{
const
interval
=
setInterval
(
async
()
=>
{
if
(
user
)
{
if
(
user
)
{
renewToken
();
await
renewToken
();
getUserRoles
();
}
}
},
`
${
window
.
TOKEN_RENEW_INTERVAL
}
`
);
},
`
${
window
.
TOKEN_RENEW_INTERVAL
}
`
);
return
()
=>
clearInterval
(
interval
);
return
()
=>
clearInterval
(
interval
);
},
[
renewToken
,
user
]);
},
[
renewToken
,
user
,
getUserRoles
]);
return
null
;
return
null
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/views/home/HomeView.js
+
3
−
1
View file @
878b03ac
...
@@ -18,7 +18,7 @@ export function HomeView() {
...
@@ -18,7 +18,7 @@ export function HomeView() {
const
[
iocs
,
getIocs
]
=
useIOCSearch
();
const
[
iocs
,
getIocs
]
=
useIOCSearch
();
const
[
query
,
setQuery
]
=
useState
();
const
[
query
,
setQuery
]
=
useState
();
const
[
iocFormOpen
,
setIOCFormOpen
]
=
useState
(
false
);
const
[
iocFormOpen
,
setIOCFormOpen
]
=
useState
(
false
);
const
{
user
}
=
useContext
(
userContext
);
const
{
user
,
userRoles
}
=
useContext
(
userContext
);
const
classes
=
useStyles
();
const
classes
=
useStyles
();
useEffect
(()
=>
getIocs
(
`
${
query
}
`
),
[
query
,
getIocs
]);
useEffect
(()
=>
getIocs
(
`
${
query
}
`
),
[
query
,
getIocs
]);
...
@@ -34,6 +34,8 @@ export function HomeView() {
...
@@ -34,6 +34,8 @@ export function HomeView() {
function
preFilter
(
iocs
)
{
function
preFilter
(
iocs
)
{
console
.
log
(
iocs
);
console
.
log
(
iocs
);
console
.
log
(
user
);
console
.
log
(
userRoles
);
const
abcIOCs
=
iocs
.
filter
((
ioc
)
=>
ioc
.
owner
===
user
?.
loginName
).
sort
((
a
,
b
)
=>
a
.
latestVersion
.
namingName
.
localeCompare
(
b
.
latestVersion
.
namingName
));
const
abcIOCs
=
iocs
.
filter
((
ioc
)
=>
ioc
.
owner
===
user
?.
loginName
).
sort
((
a
,
b
)
=>
a
.
latestVersion
.
namingName
.
localeCompare
(
b
.
latestVersion
.
namingName
));
return
abcIOCs
;
return
abcIOCs
;
}
}
...
...
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