feat: even project manager should not edit/delete project (#14)
* fix: remove unused import * feat: even project manager should not edit/delete project * docs: even project manager should not edit/delete project
This commit is contained in:
@@ -30,7 +30,7 @@ function isSignedIn(token: TokenType): boolean {
|
||||
function isAdmin(token: TokenType) {
|
||||
if (tokenExists(token) && isTokenValid(token)) {
|
||||
const adminRoleIndex = roles.findIndex((entry) => entry.uid === 'administrator');
|
||||
if (token.user.role === adminRoleIndex) {
|
||||
if (token.user && token.user.role === adminRoleIndex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,26 @@ async function fetchMyRoles(jwt: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function isProjectOnwer(projectRoles: ProjectRoleType[], projectId: number) {
|
||||
if (!projectRoles) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const found = projectRoles.find((role) => {
|
||||
return role.projectId === projectId;
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (found.isOwner === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isProjectManager(projectRoles: ProjectRoleType[], projectId: number) {
|
||||
if (!projectRoles) {
|
||||
return false;
|
||||
@@ -172,6 +192,7 @@ function checkSignInPage(token: TokenType, pathname: string) {
|
||||
export {
|
||||
isSignedIn,
|
||||
isAdmin,
|
||||
isProjectOnwer,
|
||||
isProjectManager,
|
||||
isProjectDeveloper,
|
||||
isProjectReporter,
|
||||
|
||||
Reference in New Issue
Block a user