@@ -62,8 +62,14 @@ export class ProjectsService {
6262 @inject ( InstallationService ) private readonly installationService : InstallationService ,
6363 ) { }
6464
65- async getProject ( userId : string , projectId : string ) : Promise < Project > {
66- await this . auth . checkPermissionOnProject ( userId , "read_info" , projectId ) ;
65+ /**
66+ * Returns a project by its ID.
67+ * @param skipPermissionCheck useful either when the caller already checked permissions or when we need to do something purely server-side (e.g. looking up a project when starting a workspace by a collaborator)
68+ */
69+ async getProject ( userId : string , projectId : string , skipPermissionCheck ?: boolean ) : Promise < Project > {
70+ if ( ! skipPermissionCheck ) {
71+ await this . auth . checkPermissionOnProject ( userId , "read_info" , projectId ) ;
72+ }
6773 const project = await this . projectDB . findProjectById ( projectId ) ;
6874 if ( ! project ) {
6975 throw new ApplicationError ( ErrorCodes . NOT_FOUND , `Project ${ projectId } not found.` ) ;
@@ -132,11 +138,18 @@ export class ProjectsService {
132138 return filteredProjects ;
133139 }
134140
135- async findProjectsByCloneUrl ( userId : string , cloneUrl : string , organizationId ?: string ) : Promise < Project [ ] > {
141+ async findProjectsByCloneUrl (
142+ userId : string ,
143+ cloneUrl : string ,
144+ organizationId ?: string ,
145+ skipPermissionCheck ?: boolean ,
146+ ) : Promise < Project [ ] > {
136147 const projects = await this . projectDB . findProjectsByCloneUrl ( cloneUrl , organizationId ) ;
137148 const result : Project [ ] = [ ] ;
138149 for ( const project of projects ) {
139- if ( await this . auth . hasPermissionOnProject ( userId , "read_info" , project . id ) ) {
150+ const hasPermission =
151+ skipPermissionCheck || ( await this . auth . hasPermissionOnProject ( userId , "read_info" , project . id ) ) ;
152+ if ( hasPermission ) {
140153 result . push ( project ) ;
141154 }
142155 }
0 commit comments