Skip to content

Commit

Permalink
Warn if trying to join project with no managers
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Jan 21, 2025
1 parent 28087b2 commit 3401e2e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ await dbContext.ProjectUsers
[Error<DbError>]
[Error<ProjectMembersMustBeVerified>]
[Error<ProjectMembersMustBeVerifiedForRole>]
[Error<ProjectHasNoManagers>]
[UseMutationConvention]
[UseFirstOrDefault]
[UseProjection]
Expand All @@ -254,11 +255,14 @@ public async Task<IQueryable<Project>> 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);
}

Expand Down
3 changes: 3 additions & 0 deletions backend/LexCore/Exceptions/ProjectHasNoManagers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace LexCore.Exceptions;

public class ProjectHasNoManagers(string projectCode) : Exception($"project {projectCode} has no managers");
6 changes: 5 additions & 1 deletion frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ type ProjectCreatorsMustHaveEmail implements Error {
message: String!
}

type ProjectHasNoManagers implements Error {
message: String!
}

type ProjectMemberInvitedByEmail implements Error {
message: String!
}
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3401e2e

Please sign in to comment.