@@ -77,7 +77,7 @@ module.exports = function(config, options) {
77
77
// Serve the configuration.
78
78
app . get ( '/parse-dashboard-config.json' , function ( req , res ) {
79
79
let response = {
80
- apps : config . apps ,
80
+ apps : [ ... config . apps ] , // make a copy
81
81
newFeaturesInLatestVersion : newFeaturesInLatestVersion ,
82
82
} ;
83
83
@@ -101,14 +101,29 @@ module.exports = function(config, options) {
101
101
102
102
const successfulAuth = authentication && authentication . isAuthenticated ;
103
103
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
+ }
104
115
105
116
if ( successfulAuth ) {
106
117
if ( appsUserHasAccess ) {
107
118
// Restric access to apps defined in user dictionary
108
119
// If they didn't supply any app id, user will access all apps
109
120
response . apps = response . apps . filter ( function ( app ) {
110
121
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 ;
112
127
} )
113
128
} ) ;
114
129
}
0 commit comments