feat(admin): allow admins to update user's items (restoring lost items,
granting quest scrolls, etc). @deilann :)
This commit is contained in:
@@ -28,6 +28,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
||||
$rootScope.env = window.env;
|
||||
$rootScope.Math = Math;
|
||||
$rootScope.Groups = Groups;
|
||||
$rootScope.toJson = angular.toJson;
|
||||
|
||||
// Angular UI Router
|
||||
$rootScope.$state = $state;
|
||||
|
||||
+12
-1
@@ -38,7 +38,7 @@ api.getPatrons = function(req,res,next){
|
||||
|
||||
api.getHero = function(req,res,next) {
|
||||
User.findById(req.params.uid)
|
||||
.select('contributor balance profile.name purchased')
|
||||
.select('contributor balance profile.name purchased items')
|
||||
.exec(function(err, user){
|
||||
if (err) return next(err)
|
||||
if (!user) return res.json(400,{err:'User not found'});
|
||||
@@ -61,6 +61,17 @@ api.updateHero = function(req,res,next) {
|
||||
member.contributor = req.body.contributor;
|
||||
member.purchased.ads = req.body.purchased.ads;
|
||||
if (member.contributor.level >= 6) member.items.pets['Dragon-Hydra'] = 5;
|
||||
if (req.body.itemPath && req.body.itemVal
|
||||
&& req.body.itemPath.indexOf('items.')===0
|
||||
&& User.schema.paths[req.body.itemPath]) {
|
||||
// TODO remove below after verified. Seems express handles type-casting just fine
|
||||
//var itemVal = req.body.itemVal;itemVal =
|
||||
// itemVal === 'false' ? false: itemVal === 'true' ? true: // boolean
|
||||
// _.isNaN(parseInt(itemVal)) ? itemVal : // string
|
||||
// _.isDate(itemVal) ? itemVal : // date
|
||||
// parseInt(itemVal); // number
|
||||
shared.dotSet(member, req.body.itemPath, req.body.itemVal);
|
||||
}
|
||||
member.save(cb);
|
||||
}
|
||||
], function(err, saved){
|
||||
|
||||
@@ -29,6 +29,13 @@ api.getContent = function(req, res, next) {
|
||||
res.json(content);
|
||||
}
|
||||
|
||||
api.getModelPaths = function(req,res,next){
|
||||
res.json(_.reduce(User.schema.paths,function(m,v,k){
|
||||
m[k] = v.instance || 'Boolean';
|
||||
return m;
|
||||
},{}));
|
||||
}
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------
|
||||
Tasks
|
||||
|
||||
@@ -46,6 +46,10 @@ module.exports = (swagger, v2) ->
|
||||
]
|
||||
action: user.getContent
|
||||
|
||||
'/content/paths':
|
||||
spec:
|
||||
description: "Show user model tree"
|
||||
action: user.getModelPaths
|
||||
|
||||
"/export/history":
|
||||
spec:
|
||||
|
||||
@@ -37,24 +37,33 @@ script(type='text/ng-template', id='partials/options.social.hall.heroes.html')
|
||||
label
|
||||
input(type='checkbox', ng-model='hero.contributor.admin')
|
||||
=env.t('admin')
|
||||
hr
|
||||
|
||||
hr
|
||||
.form-group
|
||||
label=env.t('balance')
|
||||
input.form-control(type='number', step="any", ng-model='hero.balance')
|
||||
small!= '`user.balance`' + env.t('notGems')
|
||||
.form-group
|
||||
.checkbox
|
||||
label
|
||||
input(type='checkbox', ng-model='hero.purchased.ads')
|
||||
=env.t('hideAds')
|
||||
accordion
|
||||
accordion-group(heading='Items')
|
||||
h4 Update Item
|
||||
.form-group.well
|
||||
input.form-control(type='text',placeholder='Path (eg, items.pets.BearCub-Base)',ng-model='hero.itemPath')
|
||||
small.muted Enter the <strong>item path</strong>. E.g., <code>items.pets.BearCub-Zombie</code> or <code>items.gear.owned.head_special_0</code> or <code>items.gear.equipped.head</code>. <a href='/api/v2/content/paths' target='_blank'>See all paths here.</a> When in doubt, ask Tyler.
|
||||
br
|
||||
input.form-control(type='text',placeholder='Value (eg, 5)',ng-model='hero.itemVal')
|
||||
small.muted Enter the <strong>item value</strong>. E.g., <code>5</code> or <code>false</code> or <code>head_warrior_3</code> (respectively from above examples).
|
||||
h4 Current Items
|
||||
pre {{::toJson(hero.items,true)}}
|
||||
|
||||
.form-group
|
||||
label=env.t('balance')
|
||||
input.form-control(type='number', step="any", ng-model='hero.balance')
|
||||
small!= '`user.balance`' + env.t('notGems')
|
||||
|
||||
.form-group
|
||||
.checkbox
|
||||
label
|
||||
input(type='checkbox', ng-model='hero.purchased.ads')
|
||||
=env.t('hideAds')
|
||||
|
||||
// h4 Backer Status
|
||||
// Add backer stuff like tier, disable adds, etcs
|
||||
.form-group
|
||||
input.form-control.btn.btn-primary(type='submit')=env.t('save')
|
||||
// h4 Backer Status
|
||||
// Add backer stuff like tier, disable adds, etcs
|
||||
.form-group
|
||||
input.form-control.btn.btn-primary(type='submit')=env.t('save')
|
||||
|
||||
|
||||
table.table.table-striped
|
||||
|
||||
Reference in New Issue
Block a user