diff --git a/pkg/api/dtos/invite.go b/pkg/api/dtos/invite.go index a0fe16472eb..4830304cea3 100644 --- a/pkg/api/dtos/invite.go +++ b/pkg/api/dtos/invite.go @@ -17,6 +17,7 @@ type InviteInfo struct { Name string `json:"name"` Username string `json:"username"` InvitedBy string `json:"invitedBy"` + OrgName string `json:"orgName"` } type CompleteInviteForm struct { diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 1591e180884..dfb5445d0be 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -220,11 +220,22 @@ func (hs *HTTPServer) GetInviteInfoByCode(c *contextmodel.ReqContext) response.R return response.Error(http.StatusNotFound, "Invite not found", nil) } + orgResult, err := hs.orgService.GetByID(c.Req.Context(), &org.GetOrgByIDQuery{ + ID: invite.OrgID, + }) + if err != nil { + if errors.Is(err, org.ErrOrgNotFound) { + return response.Error(http.StatusNotFound, "org not found", nil) + } + return response.Error(http.StatusInternalServerError, "Failed to get org", err) + } + return response.JSON(http.StatusOK, dtos.InviteInfo{ Email: invite.Email, Name: invite.Name, Username: invite.Email, InvitedBy: util.StringsFallback3(invite.InvitedByName, invite.InvitedByLogin, invite.InvitedByEmail), + OrgName: orgResult.Name, }) } diff --git a/public/app/features/invites/SignupInvited.test.tsx b/public/app/features/invites/SignupInvited.test.tsx index 9c7d8a684f5..b5aa3ee4315 100644 --- a/public/app/features/invites/SignupInvited.test.tsx +++ b/public/app/features/invites/SignupInvited.test.tsx @@ -27,6 +27,7 @@ const defaultGet = { name: 'Some User', invitedBy: 'Invited By User', username: 'someuser', + orgName: 'Some Org', }; async function setupTestContext({ get = defaultGet }: { get?: typeof defaultGet | null } = {}) { @@ -83,7 +84,7 @@ describe('SignupInvitedPage', () => { /has invited you to join grafana and the organization please complete the following and choose a password to accept your invitation and continue:/i ); - expect(within(view).getByText(/invited to org name/i)).toBeInTheDocument(); + expect(within(view).getByText(/some org/i)).toBeInTheDocument(); }); it('then the form should include form data', async () => { @@ -98,7 +99,9 @@ describe('SignupInvitedPage', () => { describe('when user submits the form and the required fields are not filled in', () => { it('then required fields should show error messages and nothing should be posted', async () => { - const { postSpy } = await setupTestContext({ get: { email: '', invitedBy: '', name: '', username: '' } }); + const { postSpy } = await setupTestContext({ + get: { email: '', invitedBy: '', name: '', username: '', orgName: '' }, + }); await userEvent.click(screen.getByRole('button', { name: /sign up/i })); @@ -123,6 +126,7 @@ describe('SignupInvitedPage', () => { username: 'some.user@localhost', password: 'pass@word1', inviteCode: 'some code', + orgName: 'Some Org', }); }); }); diff --git a/public/app/features/invites/SignupInvited.tsx b/public/app/features/invites/SignupInvited.tsx index cfc9f023eed..f9e5027e482 100644 --- a/public/app/features/invites/SignupInvited.tsx +++ b/public/app/features/invites/SignupInvited.tsx @@ -9,7 +9,6 @@ import { Button, Field, Input, useStyles2 } from '@grafana/ui'; import { Form } from 'app/core/components/Form/Form'; import { Page } from 'app/core/components/Page/Page'; import { getConfig } from 'app/core/config'; -import { contextSrv } from 'app/core/core'; import { w3cStandardEmailValidator } from '../admin/utils'; @@ -18,6 +17,7 @@ interface FormModel { name?: string; username: string; password?: string; + orgName?: string; } const navModel = { @@ -46,6 +46,7 @@ export const SignupInvitedPage = () => { email: invite.email, name: invite.name, username: invite.email, + orgName: invite.orgName, }); setGreeting(invite.name || invite.email || invite.username); @@ -68,7 +69,7 @@ export const SignupInvitedPage = () => {