@@ -14,15 +14,15 @@ module.exports = [
14
14
permissions ( 'projectReporting.view' ) ,
15
15
async ( req , res , next ) => {
16
16
const projectId = Number ( req . params . projectId ) ;
17
- const mockReport = config . lookerConfig . USE_MOCK === 'true' ;
17
+ const mockReport = config . get ( ' lookerConfig.USE_MOCK' ) === 'true' ;
18
18
let reportName = mockReport ? 'mock' : req . query . reportName ;
19
19
const authUser = req . authUser ;
20
20
let REPORTS = null ;
21
21
let allowedUsers = null ;
22
22
try {
23
23
allowedUsers = JSON . parse ( _ . get ( config , 'lookerConfig.ALLOWED_USERS' , '[]' ) ) ;
24
24
req . log . trace ( allowedUsers , 'allowedUsers' ) ;
25
- REPORTS = JSON . parse ( config . lookerConfig . EMBED_REPORTS_MAPPING ) ;
25
+ REPORTS = JSON . parse ( config . get ( ' lookerConfig.EMBED_REPORTS_MAPPING' ) ) ;
26
26
} catch ( error ) {
27
27
req . log . error ( error ) ;
28
28
req . log . debug ( 'Invalid reports mapping. Should be a valid JSON.' ) ;
@@ -35,14 +35,39 @@ module.exports = [
35
35
if ( ! mockReport ) {
36
36
const project = await models . Project . findOne ( {
37
37
where : { id : projectId } ,
38
- attributes : [ 'id' , 'templateId' ] ,
38
+ attributes : [ 'id' , 'templateId' , 'details' ] ,
39
39
raw : true ,
40
40
} ) ;
41
+
42
+ // we would use Project Template or Product Template category to format report name
43
+ let category = '' ;
44
+
45
+ // try to get project template of the project to generate the report name
41
46
const projectTemplate = project . templateId
42
47
? await models . ProjectTemplate . findByPk ( project . templateId , { attributes : [ 'category' ] , raw : true } )
43
48
: null ;
44
- const projectCategory = _ . get ( projectTemplate , 'category' , '' ) ;
45
- reportName = `${ reportName } -${ projectCategory } ` ;
49
+ if ( projectTemplate ) {
50
+ category = _ . get ( projectTemplate , 'category' , '' ) ;
51
+
52
+ // if no project template found, try to find product template (for old project v2)
53
+ } else {
54
+ const productTemplate = _ . get ( project , 'details.products[0]' )
55
+ ? await models . ProductTemplate . findOne (
56
+ {
57
+ where : {
58
+ productKey : _ . get ( project , 'details.products[0]' ) ,
59
+ } ,
60
+ } ,
61
+ {
62
+ attributes : [ 'category' ] ,
63
+ raw : true ,
64
+ } ,
65
+ ) : null ;
66
+
67
+ category = _ . get ( productTemplate , 'category' , '' ) ;
68
+ }
69
+
70
+ reportName = `${ reportName } -${ category } ` ;
46
71
}
47
72
// check if auth user has acecss to this project
48
73
const members = req . context . currentProjectMembers ;
0 commit comments