Skip to content

Commit a51c511

Browse files
committed
#795 Enforce users on same team for tasks
1 parent 0d500f4 commit a51c511

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/backend/src/services/deadline-notifications.services.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default class DeadlineNotificationsService {
2525
include: {
2626
assignees: {
2727
include: {
28-
userSecureSettings: true,
2928
userSettings: true,
3029
teamAsHead: true,
3130
teamsAsLead: true,

src/backend/src/services/reimbursement-requests.services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
vendorTransformer
5050
} from '../transformers/reimbursement-requests.transformer';
5151
import reimbursementQueryArgs from '../prisma-query-args/reimbursement.query-args';
52-
import { UserWithSettings } from '../utils/auth.utils';
52+
import { UserWithSecureSettings } from '../utils/auth.utils';
5353
import { sendReimbursementRequestDeniedNotification } from '../utils/slack.utils';
5454

5555
export default class ReimbursementRequestService {
@@ -111,7 +111,7 @@ export default class ReimbursementRequestService {
111111
* @returns the created reimbursement request
112112
*/
113113
static async createReimbursementRequest(
114-
recipient: UserWithSettings,
114+
recipient: UserWithSecureSettings,
115115
dateOfExpense: Date,
116116
vendorId: string,
117117
account: ClubAccount,

src/backend/src/services/tasks.services.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import prisma from '../prisma/prisma';
77
import taskTransformer from '../transformers/tasks.transformer';
88
import { NotFoundException, AccessDeniedException, HttpException, DeletedException } from '../utils/errors.utils';
99
import { hasPermissionToEditTask, sendSlackTaskAssignedNotificationToUsers } from '../utils/tasks.utils';
10-
import { areUsersPartOfTeams, isUserOnTeam } from '../utils/teams.utils';
10+
import { allUsersOnTeam, areUsersPartOfTeams, isUserOnTeam } from '../utils/teams.utils';
1111
import { getUsers } from '../utils/users.utils';
1212
import { wbsNumOf } from '../utils/utils';
1313

@@ -80,6 +80,9 @@ export default class TasksService {
8080
if (!areUsersPartOfTeams(teams, users))
8181
throw new HttpException(400, `All assignees must be part of one of the project's team!`);
8282

83+
if (!teams.some((team) => allUsersOnTeam(team, users)))
84+
throw new HttpException(400, 'All assignees must be part of the same team!');
85+
8386
if (!isUnderWordCount(title, 15)) throw new HttpException(400, 'Title must be less than 15 words');
8487
if (!isUnderWordCount(notes, 250)) throw new HttpException(400, 'Notes must be less than 250 words');
8588

@@ -202,6 +205,9 @@ export default class TasksService {
202205
throw new HttpException(400, "All assignees must be part of one of the project's teams");
203206
}
204207

208+
if (!teams.some((team) => allUsersOnTeam(team, assigneeUsers)))
209+
throw new HttpException(400, 'All assignees must be part of the same team!');
210+
205211
// retrieve userId for every assignee to update task's assignees in the database
206212
const transformedAssigneeUsers = assigneeUsers.map((user) => {
207213
return {

src/backend/src/utils/auth.utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export const getCurrentUser = async (res: Response): Promise<User> => {
107107

108108
export type UserWithSettings = User & {
109109
userSettings: User_Settings | null;
110+
};
111+
112+
export type UserWithSecureSettings = UserWithSettings & {
110113
userSecureSettings: User_Secure_Settings | null;
111114
};
112115

@@ -116,7 +119,7 @@ export type UserWithSettings = User & {
116119
* @returns the user with their user settings
117120
* @throws if no user with the userId exists
118121
*/
119-
export const getCurrentUserWithUserSettings = async (res: Response): Promise<UserWithSettings> => {
122+
export const getCurrentUserWithUserSettings = async (res: Response): Promise<UserWithSecureSettings> => {
120123
const { userId } = res.locals;
121124
const user = await prisma.user.findUnique({
122125
where: { userId },

src/backend/src/utils/deadline-notifications.utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const usersToSlackPings = (users: UserWithSettings[]) => {
1919
};
2020

2121
/**
22-
* Gets the team of a task's assignees
22+
* Gets the team of a task's assignees.
23+
* Assumes all assigness share a team
2324
* @param users the users of the task
2425
* @returns the slack id of the team assigned to the task
2526
*/

0 commit comments

Comments
 (0)