[MM-21270] Fixing team join without the invite id (#3710) (#3712)

* Fixing team join without the invite id

* Fixing tests

* Adding tests to verify proper behavior calling the correct function based on the server version

* Extract server version from headers

* Make linter happy

* Update mattermost-redux

* Update mattermost-redux
This commit is contained in:
Miguel Alatzar 2019-12-16 19:16:25 -07:00 committed by GitHub
parent 04a161f38c
commit d82a0c6970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1322 additions and 2599 deletions

View file

@ -7,7 +7,7 @@ import RNFetchBlob from 'rn-fetch-blob';
import urlParse from 'url-parse';
import {Client4} from 'mattermost-redux/client';
import {ClientError} from 'mattermost-redux/client/client4';
import {ClientError, HEADER_X_VERSION_ID} from 'mattermost-redux/client/client4';
import mattermostBucket from 'app/mattermost_bucket';
import mattermostManaged from 'app/mattermost_managed';
@ -111,6 +111,13 @@ Client4.doFetchWithResponse = async (url, options) => {
Client4.setToken(token);
}
if (headers[HEADER_X_VERSION_ID] && !headers['Cache-Control']) {
const serverVersion = headers[HEADER_X_VERSION_ID];
if (serverVersion && Client4.serverVersion !== serverVersion) {
Client4.serverVersion = serverVersion; /* eslint-disable-line require-atomic-updates */
}
}
if (response.ok) {
const headersMap = new Map();
Object.keys(headers).forEach((key) => {

View file

@ -4,7 +4,7 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {getTeams, joinTeam} from 'mattermost-redux/actions/teams';
import {getTeams, addUserToTeam, joinTeam} from 'mattermost-redux/actions/teams';
import {logout} from 'mattermost-redux/actions/users';
import {getJoinableTeams} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
@ -22,7 +22,9 @@ function mapStateToProps(state) {
teamsRequest: state.requests.teams.getTeams,
teams: getJoinableTeams(state),
isLandscape: isLandscape(state),
currentUserId: currentUser && currentUser.id,
currentUserIsGuest,
serverVersion: state.entities.general.serverVersion,
};
}
@ -32,6 +34,7 @@ function mapDispatchToProps(dispatch) {
getTeams,
handleTeamChange,
joinTeam,
addUserToTeam,
logout,
}, dispatch),
};

View file

@ -14,6 +14,7 @@ import {Navigation} from 'react-native-navigation';
import {RequestStatus} from 'mattermost-redux/constants';
import EventEmitter from 'mattermost-redux/utils/event_emitter';
import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers';
import FormattedText from 'app/components/formatted_text';
import Loading from 'app/components/loading';
@ -34,16 +35,19 @@ export default class SelectTeam extends PureComponent {
getTeams: PropTypes.func.isRequired,
handleTeamChange: PropTypes.func.isRequired,
joinTeam: PropTypes.func.isRequired,
addUserToTeam: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
}).isRequired,
componentId: PropTypes.string.isRequired,
currentUrl: PropTypes.string.isRequired,
currentUserIsGuest: PropTypes.bool.isRequired,
currentUserId: PropTypes.string.isRequired,
userWithoutTeams: PropTypes.bool,
teams: PropTypes.array.isRequired,
theme: PropTypes.object,
teamsRequest: PropTypes.object.isRequired,
isLandscape: PropTypes.bool.isRequired,
serverVersion: PropTypes.string,
};
static defaultProps = {
@ -128,13 +132,21 @@ export default class SelectTeam extends PureComponent {
onSelectTeam = async (team) => {
this.setState({joining: true});
const {userWithoutTeams} = this.props;
const {userWithoutTeams, currentUserId, serverVersion} = this.props;
const {
joinTeam,
addUserToTeam,
handleTeamChange,
} = this.props.actions;
const {error} = await joinTeam(team.invite_id, team.id);
let error;
if (isMinimumServerVersion(serverVersion, 5, 18)) {
const result = await addUserToTeam(team.id, currentUserId);
error = result.error;
} else {
const result = await joinTeam(team.invite_id, team.id);
error = result.error;
}
if (error) {
Alert.alert(error.message);
this.setState({joining: false});

View file

@ -27,6 +27,7 @@ describe('SelectTeam', () => {
const actions = {
getTeams,
handleTeamChange: jest.fn(),
addUserToTeam: jest.fn(),
joinTeam: jest.fn(),
logout: jest.fn(),
};
@ -35,6 +36,7 @@ describe('SelectTeam', () => {
actions,
currentChannelId: 'someId',
currentUserIsGuest: false,
currentUserId: 'fakeid',
currentUrl: 'test',
userWithoutTeams: false,
teams: [],
@ -44,6 +46,7 @@ describe('SelectTeam', () => {
},
componentId: 'component-id',
isLandscape: false,
serverVersion: '5.18',
};
test('should match snapshot for fail of teams', async () => {
@ -100,4 +103,34 @@ describe('SelectTeam', () => {
await getTeams();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should call joinTeam versions prior to 5.18', async () => {
const props = {
...baseProps,
serverVersion: '5.17',
};
const wrapper = shallow(
<SelectTeam {...props}/>,
);
wrapper.instance().onSelectTeam({id: 'test_id', invite_id: 'test_invite_id'});
expect(props.actions.joinTeam).toBeCalledWith('test_invite_id', 'test_id');
expect(props.actions.addUserToTeam).not.toBeCalled();
});
test('should call joinTeam versions posterior to 5.18', async () => {
const props = {
...baseProps,
serverVersion: '5.18',
};
const wrapper = shallow(
<SelectTeam {...props}/>,
);
wrapper.instance().onSelectTeam({id: 'test_id', invite_id: 'test_invite_id'});
expect(props.actions.joinTeam).not.toBeCalled();
expect(props.actions.addUserToTeam).toBeCalledWith('test_id', 'fakeid');
});
});

3856
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -24,7 +24,7 @@
"intl": "1.2.5",
"jail-monkey": "2.3.0",
"jsc-android": "241213.1.0",
"mattermost-redux": "github:mattermost/mattermost-redux#be71db9d788a749782c9c97e3d58d3a9231194a4",
"mattermost-redux": "github:mattermost/mattermost-redux#6421d6ee52784c629a405d010047becbbf196c00",
"mime-db": "1.42.0",
"moment-timezone": "0.5.27",
"prop-types": "15.7.2",