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:
Takeshi Kimata
2024-07-20 08:23:31 +09:00
committed by GitHub
parent 4c886e4600
commit a1ad775a7a
9 changed files with 64 additions and 37 deletions

View File

@@ -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,