@@ -59,7 +59,8 @@ export async function getProject(req: Request, projectId: string): Promise<WebPr
5959}
6060
6161export async function searchProjects ( req : Request ) : Promise < Array < Partial < WebProject > > > {
62- const groups = await auth . getGroups ( req . user . user ) ;
62+ const user = auth . extractRequestUser ( req ) ;
63+ const groups = await auth . getGroups ( user ) ;
6364
6465 // all projects
6566 if ( req . query . all ) {
@@ -85,6 +86,7 @@ function mapProjectShortInfo(dbData): Partial<WebProject> {
8586}
8687
8788export async function createProject ( req : Request , body : WebProject ) : ProjectIdPromise {
89+ const user = auth . extractRequestUser ( req ) ;
8890 const projectId = await db . createProject ( {
8991 title : body . title ,
9092 version : body . version ,
@@ -93,13 +95,14 @@ export async function createProject(req: Request, body: WebProject): ProjectIdPr
9395 contacts : body . contacts ,
9496 acl : body . acl ,
9597 metadata : body . metadata ,
96- } , req . user . user ) ;
98+ } , user ) ;
9799
98- winston . info ( 'Project %s created by %s' , projectId , req . user . user ) ;
100+ winston . info ( 'Project %s created by %s' , projectId , user ) ;
99101 return { projectId} ;
100102}
101103
102104export async function patchProject ( req : Request , projectId , changes ) : ProjectIdPromise {
105+ const user = auth . extractRequestUser ( req ) ;
103106 const project = await db . getProject ( projectId ) ;
104107 await assertProjectAccess ( req , project , 'editor' ) ;
105108
@@ -122,15 +125,16 @@ export async function patchProject(req: Request, projectId, changes): ProjectIdP
122125 mappedChanges [ internalMap [ k ] ] = changes [ k ] ;
123126 }
124127
125- await db . patchProject ( projectId , mappedChanges , req . user . user ) ;
128+ await db . patchProject ( projectId , mappedChanges , user ) ;
126129
127- winston . info ( 'Project %s modified by %s' , projectId , req . user . user ) ;
130+ winston . info ( 'Project %s modified by %s' , projectId , user ) ;
128131 return { projectId} ;
129132}
130133
131134export async function attachPackage ( req : Request , projectId , info ) {
132135 const { packageId, name, version, website, copyright, usage } = info ;
133136 const { license, licenseText } = info ;
137+ const user = auth . extractRequestUser ( req ) ;
134138
135139 // access check
136140 const project = await db . getProject ( projectId ) ;
@@ -151,7 +155,7 @@ export async function attachPackage(req: Request, projectId, info) {
151155 await db . updatePackagesUsed ( projectId , [
152156 ...project . packages_used ,
153157 usageInfo ,
154- ] , req . user . user ) ;
158+ ] , user ) ;
155159
156160 // finally, return the updated/inserted package ID
157161 const addedPackageId = usageInfo . package_id ;
@@ -160,19 +164,21 @@ export async function attachPackage(req: Request, projectId, info) {
160164}
161165
162166export async function detachPackage ( req : Request , projectId , packageId ) : ProjectIdPromise {
167+ const user = auth . extractRequestUser ( req ) ;
163168 const project = await db . getProject ( projectId ) ;
164169 await assertProjectAccess ( req , project , 'editor' ) ;
165170
166171 const newUsage = project . packages_used . filter ( ( item ) => {
167172 return item . package_id !== packageId ;
168173 } ) ;
169174
170- await db . updatePackagesUsed ( projectId , newUsage , req . user . user ) ;
175+ await db . updatePackagesUsed ( projectId , newUsage , user ) ;
171176 winston . info ( 'Detached package %s from project %s' , packageId , projectId ) ;
172177 return { projectId} ;
173178}
174179
175180export async function replacePackage ( req : Request , projectId : string , oldId : number , newId : number ) : ProjectIdPromise {
181+ const user = auth . extractRequestUser ( req ) ;
176182 const project = await db . getProject ( projectId ) ;
177183 await assertProjectAccess ( req , project , 'editor' ) ;
178184
@@ -183,12 +189,13 @@ export async function replacePackage(req: Request, projectId: string, oldId: num
183189 }
184190 }
185191
186- await db . updatePackagesUsed ( projectId , usage , req . user . user ) ;
192+ await db . updatePackagesUsed ( projectId , usage , user ) ;
187193 winston . info ( 'Replaced package %s -> %s on project %s' , oldId , newId , projectId ) ;
188194 return { projectId} ;
189195}
190196
191197export async function generateAttributionDocument ( req : Request , projectId : string , store : boolean = false ) {
198+ const user = auth . extractRequestUser ( req ) ;
192199 const project = await db . getProject ( projectId ) ;
193200 await assertProjectAccess ( req , project , 'viewer' ) ;
194201
@@ -216,9 +223,8 @@ export async function generateAttributionDocument(req: Request, projectId: strin
216223
217224 // save a copy if requested
218225 if ( store ) {
219- const createdBy = req . user . user ;
220- documentdb . storeAttributionDocument ( projectId , project . version , text , createdBy ) ;
221- winston . info ( `Document for project ${ projectId } was stored by ${ createdBy } ` ) ;
226+ documentdb . storeAttributionDocument ( projectId , project . version , text , user ) ;
227+ winston . info ( `Document for project ${ projectId } was stored by ${ user } ` ) ;
222228 return { text} ;
223229 }
224230
0 commit comments