fix access bug
parent
71d48c72ab
commit
48eacfebfc
@ -1,10 +1,18 @@
|
||||
import { Repository } from "../models"
|
||||
import { Repository, RepositoriesMembers } from "../models"
|
||||
import OrganizationService from "./organization";
|
||||
|
||||
export default class RepositoryService {
|
||||
public static async canUserAccessRepository(userId: number, repositoryId: number): Promise<boolean> {
|
||||
const repo = await Repository.findById(repositoryId)
|
||||
if (!repo) return false
|
||||
if (repo.creatorId === userId || repo.ownerId === userId) return true
|
||||
const memberExistsNum = await RepositoriesMembers.count({
|
||||
where: {
|
||||
userId,
|
||||
repositoryId,
|
||||
}
|
||||
})
|
||||
if (memberExistsNum > 0) return true
|
||||
return OrganizationService.canUserAccessOrganization(userId, repo.organizationId)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue