Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
revert(avatars): enable default avatar (#304) (#305) r=@rfk
Browse files Browse the repository at this point in the history
This reverts commit 01b0e41.
  • Loading branch information
vladikoff authored Feb 28, 2018
1 parent 01b0e41 commit 158eb63
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 106 deletions.
20 changes: 4 additions & 16 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ curl -v \
{
"uid": "6d940dd41e636cc156074109b8092f96",
"email": "[email protected]",
"avatar": "https://firefoxusercontent.com/a9bff302615cd015692a099f691205cc"
"avatar": "https://secure.gravatar.com/avatar/6d940dd41e636cc156074109b8092f96"
}
```

Expand Down Expand Up @@ -166,27 +166,15 @@ curl -v \
"https://profile.accounts.firefox.com/v1/avatar"
```


#### Response

```json
{
"id": "a9bff302615cd015692a099f691205cc",
"avatar": "https://firefoxusercontent.com/a9bff302615cd015692a099f691205cc"
}
```


#### Response (no avatar set)
#### Response

```json
{
"id": "00000000000000000000000000000000",
"avatar": "https://firefoxusercontent.com/00000000000000000000000000000000"
"id": "81625c14128d46c2b600e74a017fa4a8",
"url": "https://secure.gravatar.com/avatar/6d940dd41e636cc156074109b8092f96"
}
```


### POST /v1/avatar/upload

- scope: `profile:avatar:write`
Expand Down
Binary file removed lib/assets/default-profile.png
Binary file not shown.
Binary file removed lib/assets/default-profile_large.png
Binary file not shown.
Binary file removed lib/assets/default-profile_small.png
Binary file not shown.
6 changes: 0 additions & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@ const conf = convict({
doc: 'Pattern to generate FxA avatar URLs. {id} will be replaced.',
default: 'http://127.0.0.1:1112/a/{id}',
env: 'IMG_URL'
},
defaultAvatarId: {
default: '00000000000000000000000000000000',
doc: 'Default avatar id',
env: 'DEFAULT_AVATAR_ID',
format: String
}
},
logging: {
Expand Down
15 changes: 0 additions & 15 deletions lib/routes/avatar/_shared.js

This file was deleted.

14 changes: 4 additions & 10 deletions lib/routes/avatar/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
const Joi = require('joi');

const db = require('../../db');
const config = require('../../config');
const hex = require('buf').to.hex;
const validate = require('../../validate');
const logger = require('../../logging')('routes.avatar.get');
const avatarShared = require('./_shared');

const DEFAULT_AVATAR = {
avatar: avatarShared.fxaUrl(config.get('img.defaultAvatarId')),
id: config.get('img.defaultAvatarId')
};

function avatarOrDefault(avatar) {
const EMPTY = Object.create(null);
function avatarOrEmpty(avatar) {
if (avatar) {
return {
id: hex(avatar.id),
avatar: avatar.url
};
}
return DEFAULT_AVATAR;
return EMPTY;
}

module.exports = {
Expand All @@ -42,7 +36,7 @@ module.exports = {
handler: function avatar(req, reply) {
var uid = req.auth.credentials.user;
db.getSelectedAvatar(uid)
.then(avatarOrDefault)
.then(avatarOrEmpty)
.done(function (result) {
var rep = reply(result);
if (result.id) {
Expand Down
11 changes: 5 additions & 6 deletions lib/routes/avatar/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const img = require('../../img');
const notifyProfileUpdated = require('../../updates-queue');
const validate = require('../../validate');
const workers = require('../../img-workers');
const avatarShared = require('./_shared');

const FXA_PROVIDER = 'fxa';
const FXA_URL_TEMPLATE = config.get('img.url');
assert(FXA_URL_TEMPLATE.indexOf('{id}') !== -1,
'img.url must contain the string "{id}"');
const DEFAULT_AVATAR_ID = config.get('img.defaultAvatarId');
assert(DEFAULT_AVATAR_ID.length === 32, 'img.default');

function fxaUrl(id) {
return FXA_URL_TEMPLATE.replace('{id}', id);
}

module.exports = {
auth: {
Expand Down Expand Up @@ -49,9 +50,7 @@ module.exports = {
handler: function upload(req, reply) {
req.server.methods.batch.cache.drop(req, function() {
var id = img.id();
// precaution to avoid the default id from being overwritten
assert(id !== DEFAULT_AVATAR_ID);
var url = avatarShared.fxaUrl(id);
var url = fxaUrl(id);
var uid = req.auth.credentials.user;
workers.upload(id, req.payload, req.headers)
.then(function save() {
Expand Down
28 changes: 0 additions & 28 deletions lib/server/_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const Hapi = require('hapi');
const Boom = require('boom');
const path = require('path');
const Inert = require('inert');

const config = require('../config').getProperties();
const logger = require('../logging')('server.static');

const DEFAULT_AVATAR_DIR = path.resolve(__dirname, '..', 'assets');
const DEFAULT_AVATAR_ID = config.img.defaultAvatarId;
const DEFAULT_AVATAR = path.resolve(DEFAULT_AVATAR_DIR, 'default-profile.png');
const DEFAULT_AVATAR_LARGE = path.resolve(DEFAULT_AVATAR_DIR, 'default-profile_large.png');
const DEFAULT_AVATAR_SMALL = path.resolve(DEFAULT_AVATAR_DIR, 'default-profile_small.png');

exports.create = function() {
var server = new Hapi.Server({
debug: false
Expand All @@ -28,26 +20,6 @@ exports.create = function() {
port: config.server.port + 1
});

server.route({
method: 'GET',
path: '/a/' + DEFAULT_AVATAR_ID + '{type?}',
handler: function (request, reply) {
switch (request.params.type) {
case '':
reply.file(DEFAULT_AVATAR);
break;
case '_small':
reply.file(DEFAULT_AVATAR_SMALL);
break;
case '_large':
reply.file(DEFAULT_AVATAR_LARGE);
break;
default:
reply(Boom.notFound());
}
}
});

server.route({
method: 'GET',
path: '/a/{id}',
Expand Down
6 changes: 1 addition & 5 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ const checksum = require('checksum');

const assert = require('insist');
const P = require('../lib/promise');
const config = require('../lib/config');
const avatarShared = require('../lib/routes/avatar/_shared');
const assertSecurityHeaders = require('./lib/util').assertSecurityHeaders;

const DEFAULT_AVATAR_ID = config.get('img.defaultAvatarId');

function randomHex(bytes) {
return crypto.randomBytes(bytes).toString('hex');
}
Expand Down Expand Up @@ -77,7 +73,7 @@ describe('/profile', function() {
assert.equal(res.statusCode, 200);
assert.equal(res.result.uid, USERID);
assert.equal(res.result.email, '[email protected]');
assert.equal(res.result.avatar, avatarShared.fxaUrl(DEFAULT_AVATAR_ID), 'return default avatar');
assert.equal(res.result.avatar, null);
assertSecurityHeaders(res);
});
});
Expand Down
20 changes: 0 additions & 20 deletions test/routes/avatar/_shared.js

This file was deleted.

0 comments on commit 158eb63

Please sign in to comment.