mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
challenges: add "official habitrpg challenge" option
This commit is contained in:
@@ -35,7 +35,8 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'User', 'Challenge
|
||||
leader: User.user._id,
|
||||
group: null,
|
||||
timestamp: +(new Date),
|
||||
members: []
|
||||
members: [],
|
||||
official: false
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ api.list = function(req, res) {
|
||||
{group: 'habitrpg'} // public group
|
||||
]
|
||||
})
|
||||
.select('name leader description group members prize')
|
||||
.select('name leader description group members prize official')
|
||||
.populate('group', '_id name')
|
||||
.populate('leader', 'profile.name')
|
||||
.sort('-timestamp')
|
||||
.sort('-official -timestamp')
|
||||
.exec(cb);
|
||||
}
|
||||
], function(err, challenges){
|
||||
@@ -129,6 +129,7 @@ api.create = function(req, res){
|
||||
waterfall = waterfall.concat([
|
||||
function(cb) { // if we're dealing with prize above, arguemnts will be `group, numRows, cb` - else `cb`
|
||||
req.body.leader = user._id;
|
||||
req.body.official = user.contributor.admin && req.body.official;
|
||||
var chal = new Challenge(req.body); // FIXME sanitize
|
||||
chal.members.push(user._id);
|
||||
chal.save(cb)
|
||||
|
||||
@@ -10,6 +10,7 @@ var ChallengeSchema = new Schema({
|
||||
name: String,
|
||||
shortName: String,
|
||||
description: String,
|
||||
official: {type: Boolean,'default':false},
|
||||
habits: [TaskSchemas.HabitSchema],
|
||||
dailys: [TaskSchemas.DailySchema],
|
||||
todos: [TaskSchemas.TodoSchema],
|
||||
|
||||
@@ -157,6 +157,7 @@ describe 'API', ->
|
||||
todos: [{type:'todo', text:'Challenge Todo', notes:'Challenge Notes'}]
|
||||
rewards: []
|
||||
habits: []
|
||||
official: true
|
||||
})
|
||||
.end (res) ->
|
||||
expectCode res, 200
|
||||
@@ -168,6 +169,7 @@ describe 'API', ->
|
||||
expect(_user.dailys[_user.dailys.length-1].text).to.be('Challenge Daily')
|
||||
updateTodo = _user.todos[_user.todos.length-1]
|
||||
expect(updateTodo.text).to.be('Challenge Todo')
|
||||
expect(challenge.official).to.be false
|
||||
done()
|
||||
|
||||
it 'User updates challenge notes', (done) ->
|
||||
@@ -198,6 +200,26 @@ describe 'API', ->
|
||||
expect(res.body.todos[res.body.todos.length-1].notes).to.be('User overriden notes')
|
||||
done()
|
||||
|
||||
it 'Admin creates a challenge', (done) ->
|
||||
User.findByIdAndUpdate _id, {$set:{'contributor.admin':true}}, (err,_user) ->
|
||||
expect(err).to.not.be.ok
|
||||
|
||||
async.parallel [
|
||||
(cb)->
|
||||
request.post("#{baseURL}/challenges")
|
||||
.send({group:group._id, dailys: [], todos: [], rewards: [], habits: [], official: false}).end (res) ->
|
||||
expect(res.body.official).to.be false
|
||||
cb()
|
||||
(cb)->
|
||||
request.post("#{baseURL}/challenges")
|
||||
.send({group:group._id, dailys: [], todos: [], rewards: [], habits: [], official: true}).end (res) ->
|
||||
expect(res.body.official).to.be true
|
||||
cb()
|
||||
], done
|
||||
|
||||
|
||||
|
||||
|
||||
############
|
||||
# Batch Update
|
||||
############
|
||||
|
||||
@@ -108,12 +108,19 @@ script(type='text/ng-template', id='partials/options.social.challenges.html')
|
||||
span(ng-show='newChallenge.group=="habitrpg"').
|
||||
Minimum 1 Gem for <strong>public challenges</strong> (helps prevent spam, it really does).
|
||||
|
||||
.option-medium(ng-if='user.contributor.admin')
|
||||
label.checkbox
|
||||
input(type='checkbox', ng-model='newChallenge.official')
|
||||
| Official HabitRPG Challenge
|
||||
|
||||
habitrpg-tasks(main=false, obj='newChallenge')
|
||||
|
||||
// Challenges list
|
||||
.accordion-group(ng-repeat='challenge in challenges|filter:filterChallenges')
|
||||
.accordion-heading
|
||||
ul.pull-right.challenge-accordion-header-specs
|
||||
li(ng-if='challenge.official')
|
||||
span.label.label-success Official HabitRPG Challenge
|
||||
li {{challenge.group.name}}
|
||||
li
|
||||
| by
|
||||
|
||||
Reference in New Issue
Block a user