@@ -77,7 +77,7 @@ module.exports = function(config, options) {
7777 // Serve the configuration.
7878 app . get ( '/parse-dashboard-config.json' , function ( req , res ) {
7979 let response = {
80- apps : config . apps ,
80+ apps : [ ... config . apps ] , // make a copy
8181 newFeaturesInLatestVersion : newFeaturesInLatestVersion ,
8282 } ;
8383
@@ -101,14 +101,29 @@ module.exports = function(config, options) {
101101
102102 const successfulAuth = authentication && authentication . isAuthenticated ;
103103 const appsUserHasAccess = authentication && authentication . appsUserHasAccessTo ;
104+ const isReadOnly = authentication && authentication . isReadOnly ;
105+ // User is full read-only, replace the masterKey by the read-only one
106+ if ( isReadOnly ) {
107+ response . apps = response . apps . map ( ( app ) => {
108+ app . masterKey = app . readOnlyMasterKey ;
109+ if ( ! app . masterKey ) {
110+ throw new Error ( 'You need to provide a readOnlyMasterKey to use read-only features.' ) ;
111+ }
112+ return app ;
113+ } ) ;
114+ }
104115
105116 if ( successfulAuth ) {
106117 if ( appsUserHasAccess ) {
107118 // Restric access to apps defined in user dictionary
108119 // If they didn't supply any app id, user will access all apps
109120 response . apps = response . apps . filter ( function ( app ) {
110121 return appsUserHasAccess . find ( appUserHasAccess => {
111- return app . appId == appUserHasAccess . appId
122+ const isSame = app . appId == appUserHasAccess . appId ;
123+ if ( isSame && appUserHasAccess . readOnly ) {
124+ app . masterKey = app . readOnlyMasterKey ;
125+ }
126+ return isSame ;
112127 } )
113128 } ) ;
114129 }
0 commit comments