Skip to content

Commit

Permalink
fix: #475 minor template issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Oct 11, 2024
1 parent 021feef commit cf95bb3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"typescript.tsdk": "Coalesce.Starter.Vue.Web\\node_modules\\typescript\\lib",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ IUrlHelper urlHelper
private IDataProtector GetProtector() => dataProtector.CreateProtector("invitations");

public async Task<ItemResult> CreateAndSendInvitation(
string tenantId,
string email,
Role[] roles
)
{
var tenantId = db.TenantIdOrThrow;

if (roles.Any(r => r.TenantId != tenantId)) return "Role/tenant mismatch";

var invitation = new UserInvitation
Expand All @@ -34,6 +35,7 @@ Role[] roles

if (user is not null)
{
// Immediately accept the invitation if the user's email address already exists
return await AcceptInvitation(invitation, user);
}

Expand All @@ -47,12 +49,10 @@ Role[] roles

public async Task<ItemResult> AcceptInvitation(
UserInvitation invitation,
User? acceptingUser
User acceptingUser
)
{
var tenant = await db.Tenants.FindAsync(invitation.TenantId);

if (acceptingUser is null) return "User not found";
if (tenant is null) return "Tenant not found";

// Note: `acceptingUser` will be untracked after ForceSetTenant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static async Task<ItemResult> Create(
db.ForceSetTenant(tenant.TenantId);
new DatabaseSeeder(db).SeedNewTenant(tenant);

return await invitationService.CreateAndSendInvitation(tenant.TenantId, adminEmail, db.Roles.ToArray());
return await invitationService.CreateAndSendInvitation(adminEmail, db.Roles.ToArray());
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static async Task<ItemResult> InviteUser(
)
{
Role[] roles = role is null ? [] : [role];
return await invitationService.CreateAndSendInvitation(db.TenantIdOrThrow, email, roles);
return await invitationService.CreateAndSendInvitation(email, roles);
}
#endif
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"typescript.tsdk": "node_modules\\typescript\\lib",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<IActionResult> OnPost()
db.ForceSetTenant(Invitation.TenantId);

var user = await db.Users.FindAsync(User.GetUserId());
var result = await invitationService.AcceptInvitation(Invitation, user);
var result = await invitationService.AcceptInvitation(Invitation, user!);
if (!result.WasSuccessful)
{
ModelState.AddModelError(nameof(Code), result.Message);
Expand Down

0 comments on commit cf95bb3

Please sign in to comment.