Skip to content

Commit

Permalink
Project managers invited by email can create projects (#1300)
Browse files Browse the repository at this point in the history
If someone is promoted to manager by other means, they can create
projects without needing a draft project approved by an admin. Sending
an email invitation to a new user and giving them the project-manager
role right off the bat should have the same effect.
  • Loading branch information
rmunn authored Dec 4, 2024
1 parent effc25b commit 9ab9b37
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/LexBoxApi/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private User CreateUserEntity(RegisterAccountInput input, LexAuthUser? jwtUser,
EmailVerified = jwtUser?.Email == input.Email,
CreatedById = creatorId,
Locked = false,
CanCreateProjects = false
CanCreateProjects = jwtUser?.Email == input.Email && jwtUser.CanCreateProjects == true,
};
UpdateUserMemberships(jwtUser, userEntity);
return userEntity;
Expand Down
8 changes: 4 additions & 4 deletions backend/LexBoxApi/Services/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task SendCreateAccountWithOrgEmail(
string? language = null)
{
language ??= User.DefaultLocalizationCode;
var authUser = CreateUserForInvite(emailAddress, language);
var authUser = CreateUserForInvite(emailAddress, language, canCreateProjects: orgRole == OrgRole.Admin);
authUser.Orgs = [new AuthUserOrg(orgRole, orgId)];
await SendInvitationEmail(authUser, emailAddress, managerName, orgName, language, isProjectInvitation: false);

Expand All @@ -124,12 +124,12 @@ public async Task SendCreateAccountWithProjectEmail(
string? language = null)
{
language ??= User.DefaultLocalizationCode;
var authUser = CreateUserForInvite(emailAddress, language);
var authUser = CreateUserForInvite(emailAddress, language, canCreateProjects: role == ProjectRole.Manager);
authUser.Projects = [new AuthUserProject(role, projectId)];
await SendInvitationEmail(authUser, emailAddress, managerName, projectName, language, isProjectInvitation: true);

}
private LexAuthUser CreateUserForInvite(string emailAddress, string? language)
private LexAuthUser CreateUserForInvite(string emailAddress, string? language, bool canCreateProjects = false)
{
language ??= User.DefaultLocalizationCode;
return new LexAuthUser
Expand All @@ -141,7 +141,7 @@ private LexAuthUser CreateUserForInvite(string emailAddress, string? language)
EmailVerificationRequired = null,
Role = UserRole.user,
UpdatedDate = DateTimeOffset.Now.ToUnixTimeSeconds(),
CanCreateProjects = null,
CanCreateProjects = canCreateProjects ? true : null,
Locale = language,
Locked = null,
Projects = [],
Expand Down

0 comments on commit 9ab9b37

Please sign in to comment.