-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
daily update, for more details, please ref to github release page
- Loading branch information
Showing
7 changed files
with
90 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as _ from 'lodash' | ||
import { ParameterizedContext } from 'koa' | ||
const inTestMode = process.env.TEST_MODE === 'true' | ||
|
||
|
||
export async function isLoggedIn(ctx: ParameterizedContext<any, any>, next: () => Promise<any>) { | ||
if (!inTestMode && (!ctx.session || !ctx.session.id)) { | ||
ctx.body = { | ||
isOk: false, | ||
errMsg: 'need login', | ||
} | ||
} else { | ||
await next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
import OrganizationService from '../../service/organization' | ||
import RepositoryService from '../../service/repository' | ||
import { Module, Interface, Property } from '../../models' | ||
|
||
export enum ACCESS_TYPE { ORGANIZATION, REPOSITORY, USER } | ||
export enum ACCESS_TYPE { ORGANIZATION, REPOSITORY, MODULE, INTERFACE, PROPERTY, USER, ADMIN } | ||
const inTestMode = process.env.TEST_MODE === 'true' | ||
|
||
export class AccessUtils { | ||
public static async canUserAccess(accessType: ACCESS_TYPE, curUserId: number, entityId: number): Promise<boolean> { | ||
if (inTestMode) { | ||
return true | ||
} | ||
if (accessType === ACCESS_TYPE.ORGANIZATION) { | ||
return await OrganizationService.canUserAccessOrganization(curUserId, entityId) | ||
} else if (accessType === ACCESS_TYPE.REPOSITORY) { | ||
return await RepositoryService.canUserAccessRepository(curUserId, entityId) | ||
} else if (accessType === ACCESS_TYPE.MODULE) { | ||
const mod = await Module.findByPk(entityId) | ||
return await RepositoryService.canUserAccessRepository(curUserId, mod.repositoryId) | ||
} else if (accessType === ACCESS_TYPE.INTERFACE) { | ||
const itf = await Interface.findByPk(entityId) | ||
return await RepositoryService.canUserAccessRepository(curUserId, itf.repositoryId) | ||
} else if (accessType === ACCESS_TYPE.PROPERTY) { | ||
const p = await Property.findByPk(entityId) | ||
return await RepositoryService.canUserAccessRepository(curUserId, p.repositoryId) | ||
} | ||
return false | ||
} | ||
|
||
public static isAdmin(curUserId: number) { | ||
if (inTestMode) { | ||
return true | ||
} | ||
return curUserId === 1 | ||
} | ||
} |