Skip to content

Commit 7ec8f62

Browse files
committed
Update project unlink failure error messages based on permission types (mapping/validation/manager)
1 parent b623b97 commit 7ec8f62

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

frontend/src/components/teamsAndOrgs/TeamLinkedProjects.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ export function TeamLinkedProjects({ viewAllEndpoint, border = true, canUserEdit
3838
id,
3939
);
4040

41+
const setResponseAsPerSubCode = (e, isMultiple, projectId) => {
42+
if (e.message === 'TeamMappingPermissionError') {
43+
setResponse({
44+
type: 'error',
45+
message: `${
46+
isMultiple ? 'Certain projects have ' : 'Project has '
47+
}mapping permission to only team and this team is the only team assigned with mapping permission. Please contact the project author before unlinking.`,
48+
projectId: projectId,
49+
});
50+
return;
51+
}
52+
if (e.message === 'TeamValidationPermissionError') {
53+
setResponse({
54+
type: 'error',
55+
message: `${
56+
isMultiple ? 'Certain projects have ' : 'Project has '
57+
}validation permission to only team and this team is the only team assigned with validation permission. Please contact the project author before unlinking.`,
58+
projectId: projectId,
59+
});
60+
return;
61+
}
62+
if (e.message === 'ProjectManagementPermissionError') {
63+
setResponse({
64+
type: 'error',
65+
message: `${
66+
isMultiple ? 'Certain Projects have ' : 'Project has '
67+
}project management permission assigned to this team and no other team is assigned. Please contact the project author before unlinking.`,
68+
projectId: projectId,
69+
});
70+
return;
71+
}
72+
};
73+
4174
// bulk action
4275
const unlinkAllProjectsFromTeam = () => {
4376
fetchLocalJSONAPI(`teams/projects/teams/${id}/unlink`, token, 'DELETE')
@@ -46,13 +79,7 @@ export function TeamLinkedProjects({ viewAllEndpoint, border = true, canUserEdit
4679
refetch();
4780
})
4881
.catch((e) => {
49-
if (e.message === 'ProjectPermissionError') {
50-
setResponse({
51-
type: 'error',
52-
message:
53-
'Certain projects have mapping/validation permissions restricted to teams, but no other team is assigned. Please contact the project author before unlinking.',
54-
});
55-
}
82+
setResponseAsPerSubCode(e, true);
5683
console.log(e.message);
5784
})
5885
.finally(() => {
@@ -71,15 +98,11 @@ export function TeamLinkedProjects({ viewAllEndpoint, border = true, canUserEdit
7198
refetch();
7299
})
73100
.catch((e) => {
74-
if (e.message === 'ProjectPermissionError') {
75-
setResponse({
76-
type: 'error',
77-
message: `${
78-
projectIds.length === 1 ? 'Project has ' : 'Certain projects have '
79-
} mapping/validation permissions restricted to teams, but no other team is assigned. Please contact the project author before unlinking.`,
80-
projectId: projectIds.length === 1 ? projectIds[0] : 0,
81-
});
82-
}
101+
setResponseAsPerSubCode(
102+
e,
103+
projectIds.length > 1,
104+
projectIds.length === 1 ? projectIds[0] : 0,
105+
);
83106
console.log(e.message);
84107
})
85108
.finally(() => {

0 commit comments

Comments
 (0)