mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Moved approval fields to group subdoc
This commit is contained in:
@@ -63,8 +63,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
|
|||||||
expect(member.notifications[0].type).to.equal('GROUP');
|
expect(member.notifications[0].type).to.equal('GROUP');
|
||||||
expect(member.notifications[0].data.message).to.equal(t('yourTaskHasBeenApproved'));
|
expect(member.notifications[0].data.message).to.equal(t('yourTaskHasBeenApproved'));
|
||||||
|
|
||||||
expect(syncedTask.approved).to.be.true;
|
expect(syncedTask.group.approved).to.be.true;
|
||||||
expect(syncedTask.approvingUser).to.equal(user._id);
|
expect(syncedTask.group.approvingUser).to.equal(user._id);
|
||||||
expect(syncedTask.approvedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
|
expect(syncedTask.group.approvedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
expect(response.message).to.equal(t('taskApprovalHasBeenRequested'));
|
expect(response.message).to.equal(t('taskApprovalHasBeenRequested'));
|
||||||
expect(updatedTask.approvalRequested).to.equal(true);
|
expect(updatedTask.group.approvalRequested).to.equal(true);
|
||||||
expect(updatedTask.approvalRequestedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
|
expect(updatedTask.group.approvalRequestedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
|
||||||
});
|
});
|
||||||
|
|
||||||
it('errors when approval has already been requested', async () => {
|
it('errors when approval has already been requested', async () => {
|
||||||
|
|||||||
@@ -316,13 +316,13 @@ api.scoreTask = {
|
|||||||
|
|
||||||
if (!task) throw new NotFound(res.t('taskNotFound'));
|
if (!task) throw new NotFound(res.t('taskNotFound'));
|
||||||
|
|
||||||
if (task.requiresApproval && !task.approved) {
|
if (task.group.requiresApproval && !task.group.approved) {
|
||||||
if (task.approvalRequested) {
|
if (task.group.approvalRequested) {
|
||||||
throw new NotAuthorized(res.t('taskRequiresApproval'));
|
throw new NotAuthorized(res.t('taskRequiresApproval'));
|
||||||
}
|
}
|
||||||
|
|
||||||
task.approvalRequested = true;
|
task.group.approvalRequested = true;
|
||||||
task.approvalRequestedDate = new Date();
|
task.group.approvalRequestedDate = new Date();
|
||||||
|
|
||||||
let group = await Group.getGroup({user, groupId: task.group.id, fields: requiredGroupFields});
|
let group = await Group.getGroup({user, groupId: task.group.id, fields: requiredGroupFields});
|
||||||
let groupLeader = await User.findById(group.leader); // Use this method so we can get access to notifications
|
let groupLeader = await User.findById(group.leader); // Use this method so we can get access to notifications
|
||||||
|
|||||||
@@ -221,9 +221,9 @@ api.approveTask = {
|
|||||||
|
|
||||||
if (group.leader !== user._id) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
|
if (group.leader !== user._id) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
|
||||||
|
|
||||||
task.approvedDate = new Date();
|
task.group.approvedDate = new Date();
|
||||||
task.approvingUser = user._id;
|
task.group.approvingUser = user._id;
|
||||||
task.approved = true;
|
task.group.approved = true;
|
||||||
|
|
||||||
assignedUser.addNotification('GROUP', {message: res.t('yourTaskHasBeenApproved')});
|
assignedUser.addNotification('GROUP', {message: res.t('yourTaskHasBeenApproved')});
|
||||||
|
|
||||||
@@ -264,8 +264,8 @@ api.getGroupApprovals = {
|
|||||||
|
|
||||||
let approvals = await Tasks.Task.find({
|
let approvals = await Tasks.Task.find({
|
||||||
'group.id': groupId,
|
'group.id': groupId,
|
||||||
approved: false,
|
'group.approved': false,
|
||||||
approvalRequested: true,
|
'group.approvalRequested': true,
|
||||||
}).exec();
|
}).exec();
|
||||||
|
|
||||||
res.respond(200, approvals);
|
res.respond(200, approvals);
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ export async function createTasks (req, res, options = {}) {
|
|||||||
let taskType = taskData.type;
|
let taskType = taskData.type;
|
||||||
let newTask = new Tasks[taskType](Tasks.Task.sanitize(taskData));
|
let newTask = new Tasks[taskType](Tasks.Task.sanitize(taskData));
|
||||||
|
|
||||||
|
if (taskData.requiresApproval) {
|
||||||
|
newTask.group.requiresApproval = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (challenge) {
|
if (challenge) {
|
||||||
newTask.challenge.id = challenge.id;
|
newTask.challenge.id = challenge.id;
|
||||||
} else if (group) {
|
} else if (group) {
|
||||||
|
|||||||
@@ -938,6 +938,8 @@ schema.methods.syncTask = async function groupSyncTask (taskToSync, user) {
|
|||||||
if (orderList.indexOf(matchingTask._id) === -1 && (matchingTask.type !== 'todo' || !matchingTask.completed)) orderList.push(matchingTask._id);
|
if (orderList.indexOf(matchingTask._id) === -1 && (matchingTask.type !== 'todo' || !matchingTask.completed)) orderList.push(matchingTask._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matchingTask.group.requiresApproval = taskToSync.group.requiresApproval;
|
||||||
|
|
||||||
if (!matchingTask.notes) matchingTask.notes = taskToSync.notes; // don't override the notes, but provide it if not provided
|
if (!matchingTask.notes) matchingTask.notes = taskToSync.notes; // don't override the notes, but provide it if not provided
|
||||||
if (matchingTask.tags.indexOf(group._id) === -1) matchingTask.tags.push(group._id); // add tag if missing
|
if (matchingTask.tags.indexOf(group._id) === -1) matchingTask.tags.push(group._id); // add tag if missing
|
||||||
|
|
||||||
|
|||||||
@@ -69,15 +69,14 @@ export let TaskSchema = new Schema({
|
|||||||
broken: {type: String, enum: ['GROUP_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED']},
|
broken: {type: String, enum: ['GROUP_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED']},
|
||||||
assignedUsers: [{type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}],
|
assignedUsers: [{type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}],
|
||||||
taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']},
|
taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']},
|
||||||
|
requiresApproval: {type: Boolean, default: false},
|
||||||
|
approved: {type: Boolean, default: false},
|
||||||
|
approvedDate: {type: Date},
|
||||||
|
approvingUser: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']},
|
||||||
|
approvalRequested: {type: Boolean, default: false},
|
||||||
|
approvalRequestedDate: {type: Date},
|
||||||
},
|
},
|
||||||
|
|
||||||
requiresApproval: {type: Boolean, default: false},
|
|
||||||
approved: {type: Boolean, default: false},
|
|
||||||
approvedDate: {type: Date},
|
|
||||||
approvingUser: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']},
|
|
||||||
approvalRequested: {type: Boolean, default: false},
|
|
||||||
approvalRequestedDate: {type: Date},
|
|
||||||
|
|
||||||
reminders: [{
|
reminders: [{
|
||||||
_id: false,
|
_id: false,
|
||||||
id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], default: shared.uuid, required: true},
|
id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], default: shared.uuid, required: true},
|
||||||
|
|||||||
Reference in New Issue
Block a user