SignupInvitedPage: Show orgName (#94940)

* no orgname

* format code

* update unit test

* delete contextSrv

* fix unit test

* run prettier

---------

Co-authored-by: Laura Benz <laura.benz@grafana.com>
This commit is contained in:
jackyin 2024-10-23 21:49:27 +08:00 committed by GitHub
parent 022297f359
commit 008c51b5b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 4 deletions

View File

@ -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 {

View File

@ -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,
})
}

View File

@ -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',
});
});
});

View File

@ -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 = () => {
<div className={cx('modal-tagline', styles.tagline)}>
<em>{invitedBy || 'Someone'}</em> has invited you to join Grafana and the organization{' '}
<span className="highlight-word">{contextSrv.user.orgName}</span>
<span className="highlight-word">{initFormModel.orgName}</span>
<br />
Please complete the following and choose a password to accept your invitation and continue:
</div>