• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / crdc-datahub-ui / 14229012485

28 Mar 2025 05:16PM UTC coverage: 60.279% (+6.1%) from 54.222%
14229012485

push

github

web-flow
Merge pull request #655 from CBIIT/3.2.0

3.2.0 Release

3137 of 5624 branches covered (55.78%)

Branch coverage included in aggregate %.

991 of 1319 new or added lines in 98 files covered. (75.13%)

33 existing lines in 14 files now uncovered.

4372 of 6833 relevant lines covered (63.98%)

147.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.68
/src/utils/formModeUtils.ts
1
import { hasPermission } from "../config/AuthPermissions";
2

3
export type FormMode = "Unauthorized" | "Edit" | "View Only" | "Review";
4

5
export const ViewOnlyStatuses = ["Submitted", "In Review", "Approved", "Rejected"];
148✔
6
export const EditStatuses = ["New", "In Progress", "Inquired"];
148✔
7
export const ReviewStatuses = ["In Review"];
148✔
8
export const FormModes = {
148✔
9
  UNAUTHORIZED: "Unauthorized",
10
  EDIT: "Edit",
11
  VIEW_ONLY: "View Only",
12
  REVIEW: "Review",
13
} as const;
14

15
/**
16
 * Get updated form mode based on user permissions and form status
17
 *
18
 * @param {User} user - The current user
19
 * @param {Application} data - The current application/submission
20
 * @returns {FormMode} - Updated form mode based on role, organization role, and form status
21
 */
22
export const getFormMode = (user: User, data: Application): FormMode => {
148✔
23
  if (!data) {
150✔
24
    return FormModes.UNAUTHORIZED;
4✔
25
  }
26
  const isFormOwner = user?._id === data.applicant?.applicantID;
146✔
27
  if (!hasPermission(user, "submission_request", "view") && !isFormOwner) {
146✔
28
    return FormModes.UNAUTHORIZED;
36✔
29
  }
30

31
  if (
110✔
32
    !isFormOwner &&
64!
33
    !hasPermission(user, "submission_request", "view") &&
34
    !hasPermission(user, "submission_request", "create") &&
35
    !hasPermission(user, "submission_request", "review")
36
  ) {
NEW
37
    return FormModes.UNAUTHORIZED;
×
38
  }
39

40
  if (
110✔
41
    hasPermission(user, "submission_request", "review") &&
69✔
42
    ReviewStatuses.includes(data?.status)
43
  ) {
44
    return FormModes.REVIEW;
2✔
45
  }
46

47
  // User is only allowed to edit their own Submission Request
48
  if (
108✔
49
    isFormOwner &&
121✔
50
    hasPermission(user, "submission_request", "create") &&
51
    EditStatuses.includes(data?.status)
52
  ) {
53
    return FormModes.EDIT;
18✔
54
  }
55

56
  return FormModes.VIEW_ONLY;
90✔
57
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc