Skip to content

Commit 17057e7

Browse files
committed
add fxa_required option
1 parent 9891d1f commit 17057e7

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

app/ui/home.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const modal = require('./modal');
55
const intro = require('./intro');
66

77
module.exports = function(state, emit) {
8+
if (state.user.loginRequired && !state.user.loggedIn) {
9+
emit('signup-cta', 'required');
10+
}
811
const archives = state.storage.files
912
.filter(archive => !archive.expired)
1013
.map(archive => archiveTile(state, emit, archive));

app/user.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export default class User {
9494
: this.limits.ANON.MAX_DOWNLOADS;
9595
}
9696

97+
get loginRequired() {
98+
return this.authConfig.fxa_required;
99+
}
100+
97101
async metricId() {
98102
return this.loggedIn ? hashId(this.info.uid) : undefined;
99103
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"release": "npm-run-all contributors changelog",
2424
"test": "npm-run-all test:*",
2525
"test:backend": "nyc --reporter=lcovonly mocha --reporter=min test/backend",
26-
"test:frontend": "cross-env NODE_ENV=development node test/frontend/runner.js",
26+
"test:frontend": "cross-env NODE_ENV=development FXA_REQUIRED=false node test/frontend/runner.js",
2727
"test:report": "nyc report --reporter=html",
2828
"test-integration": "cross-env NODE_ENV=development wdio test/wdio.docker.conf.js",
2929
"circleci-test-integration": "echo 'webdriverio tests need to be updated to node 12'",

server/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ const conf = convict({
155155
default: `${tmpdir()}${path.sep}send-${randomBytes(4).toString('hex')}`,
156156
env: 'FILE_DIR'
157157
},
158+
fxa_required: {
159+
format: Boolean,
160+
default: true,
161+
env: 'FXA_REQUIRED'
162+
},
158163
fxa_url: {
159164
format: 'url',
160165
default: 'http://localhost:3030',

server/routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module.exports = function(app) {
117117
app.get(`/api/metadata/:id${ID_REGEX}`, auth.hmac, require('./metadata'));
118118
app.get('/api/filelist/:id([\\w-]{16})', auth.fxa, filelist.get);
119119
app.post('/api/filelist/:id([\\w-]{16})', auth.fxa, filelist.post);
120-
app.post('/api/upload', auth.fxa, require('./upload'));
120+
// app.post('/api/upload', auth.fxa, require('./upload'));
121121
app.post(`/api/delete/:id${ID_REGEX}`, auth.owner, require('./delete'));
122122
app.post(`/api/password/:id${ID_REGEX}`, auth.owner, require('./password'));
123123
app.post(

server/routes/ws.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ module.exports = function(ws, req) {
4646
!auth ||
4747
timeLimit <= 0 ||
4848
timeLimit > maxExpireSeconds ||
49-
dlimit > maxDownloads
49+
dlimit > maxDownloads ||
50+
(config.fxa_required && !user)
5051
) {
5152
ws.send(
5253
JSON.stringify({

server/state.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ module.exports = async function(req) {
1515
try {
1616
authConfig = await getFxaConfig();
1717
authConfig.client_id = config.fxa_client_id;
18+
authConfig.fxa_required = config.fxa_required;
1819
} catch (e) {
20+
if (config.auth_required) {
21+
throw new Error('fxa_required is set but no config was found');
22+
}
1923
// continue without accounts
2024
}
2125
}

0 commit comments

Comments
 (0)