WIP(teams): begin simplification

This commit is contained in:
Sabe Jones
2021-02-04 14:42:48 -06:00
committed by SabreCat
parent 5708cb8ef1
commit cab4a2a8fa
4 changed files with 50 additions and 52 deletions

View File

@@ -448,20 +448,6 @@
v-if="groupId"
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">
<label
v-once
@@ -479,17 +465,6 @@
/>
</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
v-if="advancedSettingsAvailable"
@@ -1051,7 +1026,6 @@ import keys from 'lodash/keys';
import pickBy from 'lodash/pickBy';
import moment from 'moment';
import Datepicker from '@/components/ui/datepicker';
import toggleSwitch from '@/components/ui/toggleSwitch';
import toggleCheckbox from '@/components/ui/toggleCheckbox';
import markdownDirective from '@/directives/markdown';
import { mapGetters, mapActions, mapState } from '@/libs/store';
@@ -1075,7 +1049,6 @@ export default {
components: {
SelectMulti,
Datepicker,
toggleSwitch,
checklist,
selectDifficulty,
selectTranslatedArray,
@@ -1102,8 +1075,6 @@ export default {
calendar: calendarIcon,
grip: gripIcon,
}),
requiresApproval: false, // We can't set task.group fields so we use this field to toggle
sharedCompletion: 'singleCompletion',
managerNotes: '',
members: [],
membersNameAndId: [],
@@ -1283,9 +1254,6 @@ export default {
if (this.task && this.task.group && 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) {
const members = await this.$store.dispatch('members:getGroupMembers', {
@@ -1306,9 +1274,6 @@ export default {
if (this.task.group && 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
@@ -1470,10 +1435,6 @@ export default {
// TODO Fix up permissions on task.group so we don't have to keep doing these hacks
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.group.managerNotes = this.managerNotes;
}
@@ -1527,11 +1488,6 @@ export default {
this.newChecklistItem = '';
this.$emit('cancel');
},
updateRequiresApproval (newValue) {
let truthy = true;
if (!newValue) truthy = false; // This return undefined instad of false
this.requiresApproval = truthy;
},
async toggleAssignment (memberId) {
if (this.purpose === 'create') {
return;

View File

@@ -3,6 +3,7 @@ import _ from 'lodash';
import moment from 'moment';
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
model as Group,
basicFields as basicGroupFields,
@@ -220,6 +221,8 @@ async function cancelGroupSubscriptionForUser (user, group, userWasRemoved = fal
const index = userGroups.indexOf(group._id);
if (index >= 0) userGroups.splice(index, 1);
await Tasks.Task.remove({ userId: user._id, 'group.id': group._id }).exec();
const groupPlansQuery = {
// type: { $in: ['guild', 'party'] },
// privacy: 'private',

View File

@@ -73,13 +73,37 @@ async function cronAsync (req, res) {
return null;
}
const tasks = await Tasks.Task.find({
userId: user._id,
$or: [ // Exclude completed todos
{ type: 'todo', completed: false },
{ type: { $in: ['habit', 'daily', 'reward'] } },
const teamsLed = await user.teamsLed();
let tasksQuery;
if (teamsLed.length > 0) {
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 = {
habits: [], dailys: [], todos: [], rewards: [],

View File

@@ -1,6 +1,6 @@
import moment from 'moment';
import {
defaults, map, flatten, flow, compact, uniq, partialRight,
defaults, map, flatten, flow, compact, uniq, partialRight, remove,
} from 'lodash';
import common from '../../../common';
@@ -498,6 +498,21 @@ schema.methods.isMemberOfGroupPlan = async function isMemberOfGroupPlan () {
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 () {
return Boolean(this.contributor && this.contributor.admin);
};