mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
WIP(teams): begin simplification
This commit is contained in:
@@ -448,20 +448,6 @@
|
|||||||
v-if="groupId"
|
v-if="groupId"
|
||||||
class="option group-options mt-3"
|
class="option group-options mt-3"
|
||||||
>
|
>
|
||||||
<div
|
|
||||||
v-if="task.type === 'todo'"
|
|
||||||
class="form-group"
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
v-once
|
|
||||||
class="mb-1"
|
|
||||||
>{{ $t('sharedCompletion') }}</label>
|
|
||||||
<select-translated-array
|
|
||||||
:items="['recurringCompletion', 'singleCompletion', 'allAssignedCompletion']"
|
|
||||||
:value="sharedCompletion"
|
|
||||||
@select="sharedCompletion = $event"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="form-group row mt-3 mb-3">
|
<div class="form-group row mt-3 mb-3">
|
||||||
<label
|
<label
|
||||||
v-once
|
v-once
|
||||||
@@ -479,17 +465,6 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group flex-group mt-3 mb-4">
|
|
||||||
<label
|
|
||||||
v-once
|
|
||||||
class="mb-0 flex"
|
|
||||||
>{{ $t('approvalRequired') }}</label>
|
|
||||||
<toggle-switch
|
|
||||||
class="d-inline-block"
|
|
||||||
:checked="requiresApproval"
|
|
||||||
@change="updateRequiresApproval"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="advancedSettingsAvailable"
|
v-if="advancedSettingsAvailable"
|
||||||
@@ -1051,7 +1026,6 @@ import keys from 'lodash/keys';
|
|||||||
import pickBy from 'lodash/pickBy';
|
import pickBy from 'lodash/pickBy';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import Datepicker from '@/components/ui/datepicker';
|
import Datepicker from '@/components/ui/datepicker';
|
||||||
import toggleSwitch from '@/components/ui/toggleSwitch';
|
|
||||||
import toggleCheckbox from '@/components/ui/toggleCheckbox';
|
import toggleCheckbox from '@/components/ui/toggleCheckbox';
|
||||||
import markdownDirective from '@/directives/markdown';
|
import markdownDirective from '@/directives/markdown';
|
||||||
import { mapGetters, mapActions, mapState } from '@/libs/store';
|
import { mapGetters, mapActions, mapState } from '@/libs/store';
|
||||||
@@ -1075,7 +1049,6 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
SelectMulti,
|
SelectMulti,
|
||||||
Datepicker,
|
Datepicker,
|
||||||
toggleSwitch,
|
|
||||||
checklist,
|
checklist,
|
||||||
selectDifficulty,
|
selectDifficulty,
|
||||||
selectTranslatedArray,
|
selectTranslatedArray,
|
||||||
@@ -1102,8 +1075,6 @@ export default {
|
|||||||
calendar: calendarIcon,
|
calendar: calendarIcon,
|
||||||
grip: gripIcon,
|
grip: gripIcon,
|
||||||
}),
|
}),
|
||||||
requiresApproval: false, // We can't set task.group fields so we use this field to toggle
|
|
||||||
sharedCompletion: 'singleCompletion',
|
|
||||||
managerNotes: '',
|
managerNotes: '',
|
||||||
members: [],
|
members: [],
|
||||||
membersNameAndId: [],
|
membersNameAndId: [],
|
||||||
@@ -1283,9 +1254,6 @@ export default {
|
|||||||
if (this.task && this.task.group && this.task.group.managerNotes) {
|
if (this.task && this.task.group && this.task.group.managerNotes) {
|
||||||
this.managerNotes = this.task.group.managerNotes;
|
this.managerNotes = this.task.group.managerNotes;
|
||||||
}
|
}
|
||||||
if (this.groupId && this.task.group && this.task.group.approval) {
|
|
||||||
this.requiresApproval = this.task.group.approval.required;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.groupId) {
|
if (this.groupId) {
|
||||||
const members = await this.$store.dispatch('members:getGroupMembers', {
|
const members = await this.$store.dispatch('members:getGroupMembers', {
|
||||||
@@ -1306,9 +1274,6 @@ export default {
|
|||||||
if (this.task.group && this.task.group.assignedUsers) {
|
if (this.task.group && this.task.group.assignedUsers) {
|
||||||
this.assignedMembers = this.task.group.assignedUsers;
|
this.assignedMembers = this.task.group.assignedUsers;
|
||||||
}
|
}
|
||||||
if (this.task.group) {
|
|
||||||
this.sharedCompletion = this.task.group.sharedCompletion || 'singleCompletion';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO: This whole component is mutating a prop
|
// @TODO: This whole component is mutating a prop
|
||||||
@@ -1470,10 +1435,6 @@ export default {
|
|||||||
|
|
||||||
// TODO Fix up permissions on task.group so we don't have to keep doing these hacks
|
// TODO Fix up permissions on task.group so we don't have to keep doing these hacks
|
||||||
if (this.groupId) {
|
if (this.groupId) {
|
||||||
this.task.requiresApproval = this.requiresApproval;
|
|
||||||
this.task.group.approval.required = this.requiresApproval;
|
|
||||||
this.task.sharedCompletion = this.sharedCompletion;
|
|
||||||
this.task.group.sharedCompletion = this.sharedCompletion;
|
|
||||||
this.task.managerNotes = this.managerNotes;
|
this.task.managerNotes = this.managerNotes;
|
||||||
this.task.group.managerNotes = this.managerNotes;
|
this.task.group.managerNotes = this.managerNotes;
|
||||||
}
|
}
|
||||||
@@ -1527,11 +1488,6 @@ export default {
|
|||||||
this.newChecklistItem = '';
|
this.newChecklistItem = '';
|
||||||
this.$emit('cancel');
|
this.$emit('cancel');
|
||||||
},
|
},
|
||||||
updateRequiresApproval (newValue) {
|
|
||||||
let truthy = true;
|
|
||||||
if (!newValue) truthy = false; // This return undefined instad of false
|
|
||||||
this.requiresApproval = truthy;
|
|
||||||
},
|
|
||||||
async toggleAssignment (memberId) {
|
async toggleAssignment (memberId) {
|
||||||
if (this.purpose === 'create') {
|
if (this.purpose === 'create') {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import _ from 'lodash';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { model as User } from '../../models/user'; // eslint-disable-line import/no-cycle
|
import { model as User } from '../../models/user'; // eslint-disable-line import/no-cycle
|
||||||
|
import * as Tasks from '../../models/task'; // eslint-disable-line import/no-cycle
|
||||||
import { // eslint-disable-line import/no-cycle
|
import { // eslint-disable-line import/no-cycle
|
||||||
model as Group,
|
model as Group,
|
||||||
basicFields as basicGroupFields,
|
basicFields as basicGroupFields,
|
||||||
@@ -220,6 +221,8 @@ async function cancelGroupSubscriptionForUser (user, group, userWasRemoved = fal
|
|||||||
const index = userGroups.indexOf(group._id);
|
const index = userGroups.indexOf(group._id);
|
||||||
if (index >= 0) userGroups.splice(index, 1);
|
if (index >= 0) userGroups.splice(index, 1);
|
||||||
|
|
||||||
|
await Tasks.Task.remove({ userId: user._id, 'group.id': group._id }).exec();
|
||||||
|
|
||||||
const groupPlansQuery = {
|
const groupPlansQuery = {
|
||||||
// type: { $in: ['guild', 'party'] },
|
// type: { $in: ['guild', 'party'] },
|
||||||
// privacy: 'private',
|
// privacy: 'private',
|
||||||
|
|||||||
@@ -73,13 +73,37 @@ async function cronAsync (req, res) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasks = await Tasks.Task.find({
|
const teamsLed = await user.teamsLed();
|
||||||
userId: user._id,
|
let tasksQuery;
|
||||||
$or: [ // Exclude completed todos
|
|
||||||
{ type: 'todo', completed: false },
|
if (teamsLed.length > 0) {
|
||||||
{ type: { $in: ['habit', 'daily', 'reward'] } },
|
tasksQuery = {
|
||||||
|
$and: [
|
||||||
|
{
|
||||||
|
$or: [
|
||||||
|
{ userId: user._id },
|
||||||
|
{ userId: { $exists: false }, 'group.id': { $in: teamsLed } },
|
||||||
],
|
],
|
||||||
}).exec();
|
},
|
||||||
|
{
|
||||||
|
$or: [
|
||||||
|
{ type: 'todo', completed: false },
|
||||||
|
{ type: { $in: ['habit', 'daily'] } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
tasksQuery = {
|
||||||
|
userId: user._id,
|
||||||
|
$or: [
|
||||||
|
{ type: 'todo', completed: false },
|
||||||
|
{ type: { $in: ['habit', 'daily'] } },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const tasks = await Tasks.Task.find(tasksQuery).exec();
|
||||||
|
|
||||||
const tasksByType = {
|
const tasksByType = {
|
||||||
habits: [], dailys: [], todos: [], rewards: [],
|
habits: [], dailys: [], todos: [], rewards: [],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {
|
import {
|
||||||
defaults, map, flatten, flow, compact, uniq, partialRight,
|
defaults, map, flatten, flow, compact, uniq, partialRight, remove,
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
import common from '../../../common';
|
import common from '../../../common';
|
||||||
|
|
||||||
@@ -498,6 +498,21 @@ schema.methods.isMemberOfGroupPlan = async function isMemberOfGroupPlan () {
|
|||||||
return groups.some(g => g.hasActiveGroupPlan());
|
return groups.some(g => g.hasActiveGroupPlan());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
schema.methods.teamsLed = async function teamsLed () {
|
||||||
|
const user = this;
|
||||||
|
const groups = await getUserGroupData(user);
|
||||||
|
|
||||||
|
remove(groups, group => !group.hasActiveGroupPlan);
|
||||||
|
remove(groups, group => user._id !== group.leader);
|
||||||
|
|
||||||
|
const groupIds = [];
|
||||||
|
groups.forEach(group => {
|
||||||
|
groupIds.push(group._id);
|
||||||
|
});
|
||||||
|
|
||||||
|
return groupIds;
|
||||||
|
};
|
||||||
|
|
||||||
schema.methods.isAdmin = function isAdmin () {
|
schema.methods.isAdmin = function isAdmin () {
|
||||||
return Boolean(this.contributor && this.contributor.admin);
|
return Boolean(this.contributor && this.contributor.admin);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user