mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
feat(teams): new disapproval workflow, managers can uncheck tasks
This commit is contained in:
@@ -222,6 +222,7 @@ export default {
|
|||||||
|
|
||||||
this.$root.$on('habitica:team-sync', () => {
|
this.$root.$on('habitica:team-sync', () => {
|
||||||
this.loadTasks();
|
this.loadTasks();
|
||||||
|
this.loadGroupCompletedTodos();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -1046,9 +1046,13 @@ export default {
|
|||||||
showTaskLockIcon () {
|
showTaskLockIcon () {
|
||||||
if (this.isUser) return false;
|
if (this.isUser) return false;
|
||||||
if (this.isGroupTask) {
|
if (this.isGroupTask) {
|
||||||
if (this.isOpenTask) return false;
|
if (this.teamManagerAccess) return false;
|
||||||
|
if (this.isOpenTask) {
|
||||||
|
if (!this.task.completed) return false;
|
||||||
|
if (this.task.group.completedBy === this.user._id) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (this.task.group.assignedUsers.indexOf(this.user._id) !== -1) return false;
|
if (this.task.group.assignedUsers.indexOf(this.user._id) !== -1) return false;
|
||||||
if (this.teamManagerAccess && this.task.completed) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -56,11 +56,15 @@ export default {
|
|||||||
const canScoreTask = await this.beforeTaskScore(task);
|
const canScoreTask = await this.beforeTaskScore(task);
|
||||||
if (!canScoreTask) return;
|
if (!canScoreTask) return;
|
||||||
|
|
||||||
try {
|
if (direction === 'down' && task.group.completedBy && task.group.completedBy !== user._id) {
|
||||||
scoreTask({ task, user, direction });
|
task.completed = false;
|
||||||
} catch (err) {
|
} else {
|
||||||
this.text(err.message);
|
try {
|
||||||
return;
|
scoreTask({ task, user, direction });
|
||||||
|
} catch (err) {
|
||||||
|
this.text(err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.playTaskScoreSound(task, direction);
|
this.playTaskScoreSound(task, direction);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
} from './utils';
|
} from './utils';
|
||||||
import { model as Challenge } from '../../models/challenge';
|
import { model as Challenge } from '../../models/challenge';
|
||||||
import { model as Group } from '../../models/group';
|
import { model as Group } from '../../models/group';
|
||||||
|
import { model as User } from '../../models/user';
|
||||||
import * as Tasks from '../../models/task';
|
import * as Tasks from '../../models/task';
|
||||||
import apiError from '../apiError';
|
import apiError from '../apiError';
|
||||||
import {
|
import {
|
||||||
@@ -350,9 +351,34 @@ async function scoreTask (user, task, direction, req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wasCompleted = task.completed;
|
const wasCompleted = task.completed;
|
||||||
|
|
||||||
const firstTask = !user.achievements.completedTask;
|
const firstTask = !user.achievements.completedTask;
|
||||||
const [delta] = shared.ops.scoreTask({ task, user, direction }, req, res.analytics);
|
let delta;
|
||||||
|
let rollbackUser;
|
||||||
|
|
||||||
|
if (
|
||||||
|
task.group.id && !task.userId
|
||||||
|
&& direction === 'down'
|
||||||
|
&& ['todo', 'daily'].includes(task.type)
|
||||||
|
&& task.completed
|
||||||
|
&& task.group.completedBy !== user._id
|
||||||
|
) {
|
||||||
|
const group = await Group.getGroup({
|
||||||
|
user,
|
||||||
|
groupId: task.group.id,
|
||||||
|
fields: 'leader managers',
|
||||||
|
});
|
||||||
|
if (group.leader !== user._id && !group.managers[user._id]) {
|
||||||
|
throw new BadRequest('Cannot uncheck task you did not complete if not a manager.');
|
||||||
|
}
|
||||||
|
rollbackUser = await User.findOne({ _id: task.group.completedBy });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rollbackUser) {
|
||||||
|
delta = shared.ops.scoreTask({ task, user: rollbackUser, direction }, req, res.analytics);
|
||||||
|
await rollbackUser.save();
|
||||||
|
} else {
|
||||||
|
delta = shared.ops.scoreTask({ task, user, direction }, req, res.analytics);
|
||||||
|
}
|
||||||
// Drop system (don't run on the client,
|
// Drop system (don't run on the client,
|
||||||
// as it would only be discarded since ops are sent to the API, not the results)
|
// as it would only be discarded since ops are sent to the API, not the results)
|
||||||
if (direction === 'up' && !firstTask) shared.fns.randomDrop(user, { task, delta }, req, res.analytics);
|
if (direction === 'up' && !firstTask) shared.fns.randomDrop(user, { task, delta }, req, res.analytics);
|
||||||
|
|||||||
Reference in New Issue
Block a user