From 3401e2ec833a964cc235e05cc6d2d4c35a4a2ffb Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 21 Jan 2025 13:53:45 -0500 Subject: [PATCH] Warn if trying to join project with no managers --- backend/LexBoxApi/GraphQL/ProjectMutations.cs | 4 ++++ backend/LexCore/Exceptions/ProjectHasNoManagers.cs | 3 +++ frontend/schema.graphql | 6 +++++- frontend/src/lib/i18n/locales/en.json | 1 + .../(authenticated)/project/[project_code]/+page.svelte | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 backend/LexCore/Exceptions/ProjectHasNoManagers.cs diff --git a/backend/LexBoxApi/GraphQL/ProjectMutations.cs b/backend/LexBoxApi/GraphQL/ProjectMutations.cs index 8d4070514..a48d7fa8c 100644 --- a/backend/LexBoxApi/GraphQL/ProjectMutations.cs +++ b/backend/LexBoxApi/GraphQL/ProjectMutations.cs @@ -230,6 +230,7 @@ await dbContext.ProjectUsers [Error] [Error] [Error] + [Error] [UseMutationConvention] [UseFirstOrDefault] [UseProjection] @@ -254,11 +255,14 @@ public async Task> AskToJoinProject( NotFoundException.ThrowIfNull(project); var managers = project.Users.Where(u => u.Role == ProjectRole.Manager); + var emailsSent = 0; foreach (var manager in managers) { if (manager.User is null) continue; await emailService.SendJoinProjectRequestEmail(manager.User, user, project); + emailsSent++; } + if (emailsSent == 0) throw new ProjectHasNoManagers(project.Code); return dbContext.Projects.Where(p => p.Id == projectId); } diff --git a/backend/LexCore/Exceptions/ProjectHasNoManagers.cs b/backend/LexCore/Exceptions/ProjectHasNoManagers.cs new file mode 100644 index 000000000..4df5f2cb6 --- /dev/null +++ b/backend/LexCore/Exceptions/ProjectHasNoManagers.cs @@ -0,0 +1,3 @@ +namespace LexCore.Exceptions; + +public class ProjectHasNoManagers(string projectCode) : Exception($"project {projectCode} has no managers"); diff --git a/frontend/schema.graphql b/frontend/schema.graphql index c090efba6..2476dcf57 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -404,6 +404,10 @@ type ProjectCreatorsMustHaveEmail implements Error { message: String! } +type ProjectHasNoManagers implements Error { + message: String! +} + type ProjectMemberInvitedByEmail implements Error { message: String! } @@ -579,7 +583,7 @@ union AddProjectToOrgError = DbError | NotFoundError union AddProjectsToOrgError = DbError | NotFoundError -union AskToJoinProjectError = NotFoundError | DbError | ProjectMembersMustBeVerified | ProjectMembersMustBeVerifiedForRole +union AskToJoinProjectError = NotFoundError | DbError | ProjectMembersMustBeVerified | ProjectMembersMustBeVerifiedForRole | ProjectHasNoManagers union BulkAddOrgMembersError = NotFoundError | DbError | UnauthorizedAccessError diff --git a/frontend/src/lib/i18n/locales/en.json b/frontend/src/lib/i18n/locales/en.json index b43459eb3..be14d0e7d 100644 --- a/frontend/src/lib/i18n/locales/en.json +++ b/frontend/src/lib/i18n/locales/en.json @@ -212,6 +212,7 @@ Lexbox is free and [open source](https://github.com/sillsdev/languageforge-lexbo "no_thanks": "No thanks, create a new project", "click_to_view_related_projects": "Found {count, plural, one {# related project} other {# related projects}}, click here to see {count, plural, one {it} other {them}}", "join_request_sent": "Your request to join the {projectName} project has been sent to the project manager(s)", + "join_request_error_no_managers": "The {projectName} project has no project managers, so your request to join could not be sent", "description": "Description", "no_description": "This project does not have a description", "name_missing": "Project name required", diff --git a/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte b/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte index aa881a54b..bf70f5734 100644 --- a/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte +++ b/frontend/src/routes/(authenticated)/project/[project_code]/+page.svelte @@ -286,6 +286,9 @@ if (!joinResult.error) { notifySuccess($t('project.create.join_request_sent', { projectName }), Duration.Persistent); } + if (joinResult.error?.byType('ProjectHasNoManagers')) { + notifyWarning($t('project.create.join_request_error_no_managers', { projectName }), Duration.Persistent); + } } let projectConfidentialityModal: ProjectConfidentialityModal;