Commit 91d57dc5 authored by Sudheer's avatar Sudheer Committed by sudheer

MM-13345 Fix to show access denied screen for restricted teams with invite link (#2151)

* MM-13345 Fix to show access denied screen for restricted teams with invite link

* Add test for addUserToTeamFromInvite

* Update test with isLicensed enabled and disabled
parent d0bb5e84
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/SignupController should call addUserToTeamFromInvite if id exists in url 1`] = `
<LoadingScreen
position="relative"
style={Object {}}
/>
`;
exports[`components/SignupController should match snapshot for addUserToTeamFromInvite error 1`] = `
<div>
<Connect(AnnouncementBarController) />
<BackButton
url="/"
/>
<div
className="col-sm-12"
>
<div
className="signup-team__container"
>
<img
className="signup-team-logo"
src={null}
/>
<div
className="signup__content"
>
<h1 />
<h4
className="color--light"
>
<FormattedMessage
id="web.root.signup_info"
values={Object {}}
/>
</h4>
<div
className="margin--extra"
>
<h5>
<strong>
<FormattedMessage
defaultMessage="Create an account with:"
id="signup.title"
values={Object {}}
/>
</strong>
</h5>
</div>
<div
className="form-group has-error"
>
<label
className="control-label"
>
<FormattedMessage
defaultMessage="The invite link was invalid. Please speak with your Administrator to receive an invitation."
id="signup_user_completed.invalid_invite"
values={Object {}}
/>
</label>
</div>
</div>
<span
className="color--light"
>
<FormattedMessage
defaultMessage="Already have an account?"
id="signup_user_completed.haveAccount"
values={Object {}}
/>
<Link
replace={false}
to="/login?id=ppni7a9t87fn3j4d56rwocdctc"
>
<FormattedMessage
defaultMessage="Click here to sign in."
id="signup_user_completed.signIn"
values={Object {}}
/>
</Link>
</span>
</div>
</div>
</div>
`;
exports[`components/SignupController should match snapshot for all signup options enabled with isLicensed disabled 1`] = `
<div>
<Connect(AnnouncementBarController) />
<BackButton
url="/"
/>
<div
className="col-sm-12"
>
<div
className="signup-team__container"
>
<img
className="signup-team-logo"
src={null}
/>
<div
className="signup__content"
>
<h1 />
<h4
className="color--light"
>
<FormattedMessage
id="web.root.signup_info"
values={Object {}}
/>
</h4>
<div
className="margin--extra"
>
<h5>
<strong>
<FormattedMessage
defaultMessage="Create an account with:"
id="signup.title"
values={Object {}}
/>
</strong>
</h5>
</div>
<Link
className="btn btn-custom-login btn--full email"
key="email"
replace={false}
to="/signup_emailundefined"
>
<span>
<span
className="icon fa fa-envelope"
title="Email Icon"
/>
<FormattedMessage
defaultMessage="Email and Password"
id="signup.email"
values={Object {}}
/>
</span>
</Link>
<a
className="btn btn-custom-login btn--full gitlab"
href="/oauth/gitlab/signupundefined"
key="gitlab"
>
<span>
<span
className="icon"
/>
<span>
<FormattedMessage
defaultMessage="GitLab Single Sign-On"
id="signup.gitlab"
values={Object {}}
/>
</span>
</span>
</a>
</div>
<span
className="color--light"
>
<FormattedMessage
defaultMessage="Already have an account?"
id="signup_user_completed.haveAccount"
values={Object {}}
/>
<Link
replace={false}
to="/login"
>
<FormattedMessage
defaultMessage="Click here to sign in."
id="signup_user_completed.signIn"
values={Object {}}
/>
</Link>
</span>
</div>
</div>
</div>
`;
exports[`components/SignupController should match snapshot for all signup options enabled with isLicensed enabled 1`] = `
<div>
<Connect(AnnouncementBarController) />
<BackButton
url="/"
/>
<div
className="col-sm-12"
>
<div
className="signup-team__container"
>
<img
className="signup-team-logo"
src={null}
/>
<div
className="signup__content"
>
<h1 />
<h4
className="color--light"
>
<FormattedMessage
id="web.root.signup_info"
values={Object {}}
/>
</h4>
<div
className="margin--extra"
>
<h5>
<strong>
<FormattedMessage
defaultMessage="Create an account with:"
id="signup.title"
values={Object {}}
/>
</strong>
</h5>
</div>
<Link
className="btn btn-custom-login btn--full email"
key="email"
replace={false}
to="/signup_emailundefined"
>
<span>
<span
className="icon fa fa-envelope"
title="Email Icon"
/>
<FormattedMessage
defaultMessage="Email and Password"
id="signup.email"
values={Object {}}
/>
</span>
</Link>
<a
className="btn btn-custom-login btn--full gitlab"
href="/oauth/gitlab/signupundefined"
key="gitlab"
>
<span>
<span
className="icon"
/>
<span>
<FormattedMessage
defaultMessage="GitLab Single Sign-On"
id="signup.gitlab"
values={Object {}}
/>
</span>
</span>
</a>
<a
className="btn btn-custom-login btn--full google"
href="/oauth/google/signupundefined"
key="google"
>
<span>
<span
className="icon"
/>
<span>
<FormattedMessage
defaultMessage="Google Account"
id="signup.google"
values={Object {}}
/>
</span>
</span>
</a>
<a
className="btn btn-custom-login btn--full office365"
href="/oauth/office365/signupundefined"
key="office365"
>
<span>
<span
className="icon"
/>
<span>
<FormattedMessage
defaultMessage="Office 365"
id="signup.office365"
values={Object {}}
/>
</span>
</span>
</a>
<Link
className="btn btn-custom-login btn--full ldap"
key="ldap"
replace={false}
to="/login?extra=create_ldap"
>
<span>
<span
className="icon fa fa-folder-open fa--margin-top"
title="AD/LDAP Icon"
/>
<span>
<FormattedMessage
defaultMessage="AD/LDAP Credentials"
id="signup.ldap"
values={Object {}}
/>
</span>
</span>
</Link>
<Link
className="btn btn-custom-login btn--full saml"
key="saml"
replace={false}
to="/login/sso/samlundefined?action=signup"
>
<span>
<span
className="icon fa fa-lock fa--margin-top"
title="SAML Icon"
/>
<span>
SAML
</span>
</span>
</Link>
</div>
<span
className="color--light"
>
<FormattedMessage
defaultMessage="Already have an account?"
id="signup_user_completed.haveAccount"
values={Object {}}
/>
<Link
replace={false}
to="/login"
>
<FormattedMessage
defaultMessage="Click here to sign in."
id="signup_user_completed.signIn"
values={Object {}}
/>
</Link>
</span>
</div>
</div>
</div>
`;
......@@ -95,23 +95,24 @@ export default class SignupController extends React.Component {
const userLoggedIn = this.props.loggedIn;
if ((inviteId || token) && userLoggedIn) {
const {data: team, error} = this.props.actions.addUserToTeamFromInvite(token, inviteId);
if (team) {
browserHistory.push('/' + team.name + `/channels/${Constants.DEFAULT_CHANNEL}`);
} else if (error) {
this.handleInvalidInvite(error);
}
}
if (inviteId) {
this.addUserToTeamFromInvite(token, inviteId);
} else if (inviteId) {
this.getInviteInfo(inviteId);
}
if (userLoggedIn) {
} else if (userLoggedIn) {
GlobalActions.redirectUserToDefaultTeam();
}
}
}
addUserToTeamFromInvite = async (token, inviteId) => {
const {data: team, error} = await this.props.actions.addUserToTeamFromInvite(token, inviteId);
if (team) {
browserHistory.push('/' + team.name + `/channels/${Constants.DEFAULT_CHANNEL}`);
} else if (error) {
this.handleInvalidInvite(error);
}
}
getInviteInfo = async (inviteId) => {
const {data, error} = await this.props.actions.getTeamInviteInfo(inviteId);
if (data) {
......
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import * as GlobalActions from 'actions/global_actions.jsx';
import {browserHistory} from 'utils/browser_history';
import {Constants} from 'utils/constants.jsx';
import SignupController from './signup_controller.jsx';
jest.mock('actions/global_actions', () => ({
redirectUserToDefaultTeam: jest.fn(),
}));
jest.mock('utils/browser_history', () => ({
browserHistory: {
push: jest.fn(),
},
}));
describe('components/SignupController', () => {
const baseProps = {
location: {
search: '',
pathname: '/signup_user_complete/',
hash: '',
},
noAccounts: false,
loggedIn: true,
isLicensed: true,
enableOpenServer: true,
enableSAML: true,
enableLDAP: true,
enableSignUpWithEmail: true,
enableSignUpWithGitLab: true,
enableSignUpWithGoogle: true,
enableSignUpWithOffice365: true,
samlLoginButtonText: 'SAML',
ldapLoginFieldName: '',
actions: {
removeGlobalItem: jest.fn(),
getTeamInviteInfo: jest.fn(),
addUserToTeamFromInvite: jest.fn(),
},
};
test('should match snapshot for all signup options enabled with isLicensed enabled', () => {
const wrapper = shallow(
<SignupController {...baseProps}/>
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot for all signup options enabled with isLicensed disabled', () => {
const props = {
...baseProps,
isLicensed: false,
};
const wrapper = shallow(
<SignupController {...props}/>
);
expect(wrapper).toMatchSnapshot();
});
test('should call addUserToTeamFromInvite if id exists in url', async () => {
browserHistory.push = jest.fn();
const addUserToTeamFromInvite = jest.fn().mockImplementation(() => Promise.resolve({data: {name: 'defaultTeam'}}));
const getInviteInfo = jest.fn();
const props = {
...baseProps,
location: {
...baseProps.location,
search: '?id=ppni7a9t87fn3j4d56rwocdctc',
},
actions: {
...baseProps.actions,
addUserToTeamFromInvite,
getInviteInfo,
},
};
const wrapper = shallow(
<SignupController {...props}/>
);
expect(wrapper).toMatchSnapshot();
expect(addUserToTeamFromInvite).toHaveBeenCalled();
expect(getInviteInfo).not.toHaveBeenCalled();
expect(GlobalActions.redirectUserToDefaultTeam).not.toHaveBeenCalled();
await addUserToTeamFromInvite();
expect(browserHistory.push).toHaveBeenCalledWith(`/defaultTeam/channels/${Constants.DEFAULT_CHANNEL}`);
});
test('should match snapshot for addUserToTeamFromInvite error', async () => {
const addUserToTeamFromInvite = jest.fn().mockImplementation(() => Promise.resolve({error: {message: 'access denied'}}));
const props = {
...baseProps,
location: {
...baseProps.location,
search: '?id=ppni7a9t87fn3j4d56rwocdctc',
},
actions: {
...baseProps.actions,
addUserToTeamFromInvite,
},
};
const wrapper = shallow(
<SignupController {...props}/>
);
expect(addUserToTeamFromInvite).toHaveBeenCalled();
await addUserToTeamFromInvite();
expect(wrapper).toMatchSnapshot();
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment