Skip to content

Commit 3c13c58

Browse files
committed
Adds support for readOnly masterKey
1 parent 3607d4c commit 3c13c58

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Parse-Dashboard/Authentication.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function initialize(app, options) {
8181
function authenticate(userToTest, usernameOnly) {
8282
var appsUserHasAccessTo = null;
8383
var matchingUsername = null;
84+
var isReadOnly = false;
8485

8586
//they provided auth
8687
let isAuthenticated = userToTest &&
@@ -96,12 +97,14 @@ function authenticate(userToTest, usernameOnly) {
9697
matchingUsername = user.user;
9798
// User restricted apps
9899
appsUserHasAccessTo = user.apps || null;
100+
isReadOnly = user.readOnly;
99101
}
100102

101103
return isAuthenticated;
102104
}) ? true : false;
103105

104106
return {
107+
isReadOnly,
105108
isAuthenticated,
106109
matchingUsername,
107110
appsUserHasAccessTo

Parse-Dashboard/app.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)