mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
/user/anonymized - return user json without personal data
This commit is contained in:
@@ -259,6 +259,12 @@ describe "API", ->
|
|||||||
expect(body.err).to.be "Task not found."
|
expect(body.err).to.be "Task not found."
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "Anonymized User", ->
|
||||||
|
it "/api/v2/user/anonymized", (done) ->
|
||||||
|
request.get(baseURL + "/user/anonymized").set("Accept", "application/json").end (res) ->
|
||||||
|
expect(res.statusCode).to.be 200
|
||||||
|
done()
|
||||||
|
|
||||||
###*
|
###*
|
||||||
GROUPS
|
GROUPS
|
||||||
###
|
###
|
||||||
|
|||||||
@@ -215,6 +215,64 @@ api.getUser = function(req, res, next) {
|
|||||||
return res.json(200, user);
|
return res.json(200, user);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get anonymized User
|
||||||
|
*/
|
||||||
|
api.getUserAnonymized = function(req, res, next) {
|
||||||
|
var user = res.locals.user.toJSON();
|
||||||
|
user.stats.toNextLevel = shared.tnl(user.stats.lvl);
|
||||||
|
user.stats.maxHealth = 50;
|
||||||
|
user.stats.maxMP = res.locals.user._statsComputed.maxMP;
|
||||||
|
delete user.apiToken;
|
||||||
|
if (user.auth) {
|
||||||
|
delete user.auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete user.webhooks;
|
||||||
|
|
||||||
|
_.forEach(user.inbox.messages, function(msg){
|
||||||
|
msg.text = "inbox message text";
|
||||||
|
});
|
||||||
|
|
||||||
|
_.forEach(user.tags, function(tag){
|
||||||
|
tag.name = "tag";
|
||||||
|
tag.challenge = "challenge";
|
||||||
|
});
|
||||||
|
|
||||||
|
function cleanChecklist(task){
|
||||||
|
var checklistIndex = 0;
|
||||||
|
|
||||||
|
_.forEach(task.checklist, function(c){
|
||||||
|
c.text = "item" + checklistIndex++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_.forEach(user.habits, function(task){
|
||||||
|
task.text = "task text";
|
||||||
|
task.notes = "task notes";
|
||||||
|
});
|
||||||
|
|
||||||
|
_.forEach(user.rewards, function(task){
|
||||||
|
task.text = "task text";
|
||||||
|
task.notes = "task notes";
|
||||||
|
});
|
||||||
|
|
||||||
|
_.forEach(user.dailys, function(task){
|
||||||
|
task.text = "task text";
|
||||||
|
task.notes = "task notes";
|
||||||
|
|
||||||
|
cleanChecklist(task);
|
||||||
|
});
|
||||||
|
|
||||||
|
_.forEach(user.todos, function(task){
|
||||||
|
task.text = "task text";
|
||||||
|
task.notes = "task notes";
|
||||||
|
|
||||||
|
cleanChecklist(task);
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.json(200, user);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This tells us for which paths users can call `PUT /user` (or batch-update equiv, which use `User.set()` on our client).
|
* This tells us for which paths users can call `PUT /user` (or batch-update equiv, which use `User.set()` on our client).
|
||||||
|
|||||||
@@ -227,6 +227,11 @@ module.exports = (swagger, v2) ->
|
|||||||
description: "Get the full user object"
|
description: "Get the full user object"
|
||||||
action: user.getUser
|
action: user.getUser
|
||||||
|
|
||||||
|
"/user/anonymized":
|
||||||
|
spec:
|
||||||
|
description: "Get the user object without any personal data"
|
||||||
|
action: user.getUserAnonymized
|
||||||
|
|
||||||
"/user:PUT":
|
"/user:PUT":
|
||||||
spec:
|
spec:
|
||||||
path: '/user'
|
path: '/user'
|
||||||
|
|||||||
Reference in New Issue
Block a user