Fixing permalinks to channels your not a memeber of (#2805)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
d962e175f8
Коммит
fa807d8e43
@@ -128,21 +128,31 @@ export function emitInitialLoad(callback) {
|
||||
);
|
||||
}
|
||||
|
||||
export function doFocusPost(channelId, postId, data) {
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_FOCUSED_POST,
|
||||
postId,
|
||||
post_list: data
|
||||
});
|
||||
AsyncClient.getChannels(true);
|
||||
AsyncClient.getChannelExtraInfo(channelId);
|
||||
AsyncClient.getPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
|
||||
AsyncClient.getPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
|
||||
}
|
||||
|
||||
export function emitPostFocusEvent(postId) {
|
||||
AsyncClient.getChannels(true);
|
||||
Client.getPostById(
|
||||
Client.getPermalinkTmp(
|
||||
postId,
|
||||
(data) => {
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_FOCUSED_POST,
|
||||
postId,
|
||||
post_list: data
|
||||
});
|
||||
|
||||
AsyncClient.getChannelExtraInfo(data.channel_id);
|
||||
|
||||
AsyncClient.getPostsBefore(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
|
||||
AsyncClient.getPostsAfter(postId, 0, Constants.POST_FOCUS_CONTEXT_RADIUS);
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
const channelId = data.posts[data.order[0]].channel_id;
|
||||
doFocusPost(channelId, postId, data);
|
||||
},
|
||||
() => {
|
||||
browserHistory.push('/error?message=' + encodeURIComponent(Utils.localizeMessage('permalink.error.access', 'Permalink belongs to a channel you do not have access to')));
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -431,3 +441,11 @@ export function emitUserLoggedOutEvent(redirectTo) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function emitJoinChannelEvent(channel, success, failure) {
|
||||
Client.joinChannel(
|
||||
channel.id,
|
||||
success,
|
||||
failure,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,10 @@ export default class Client {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels`;
|
||||
}
|
||||
|
||||
getChannelNameRoute(channelName) {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/name/${channelName}`;
|
||||
}
|
||||
|
||||
getChannelNeededRoute(channelId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/${channelId}`;
|
||||
}
|
||||
@@ -1042,6 +1046,17 @@ export default class Client {
|
||||
this.track('api', 'api_channels_join');
|
||||
}
|
||||
|
||||
joinChannelByName = (name, success, error) => {
|
||||
request.
|
||||
post(`${this.getChannelNameRoute(name)}/join`).
|
||||
set(this.defaultHeaders).
|
||||
type('application/json').
|
||||
accept('application/json').
|
||||
end(this.handleResponse.bind(this, 'joinChannelByName', success, error));
|
||||
|
||||
this.track('api', 'api_channels_join_name');
|
||||
}
|
||||
|
||||
deleteChannel = (channelId, success, error) => {
|
||||
request.
|
||||
post(`${this.getChannelNeededRoute(channelId)}/delete`).
|
||||
@@ -1212,6 +1227,17 @@ export default class Client {
|
||||
this.track('api', 'api_posts_create', post.channel_id, 'length', post.message.length);
|
||||
}
|
||||
|
||||
// This is a temporary route to get around a problem with the permissions system that
|
||||
// will be fixed in 3.1 or 3.2
|
||||
getPermalinkTmp = (postId, success, error) => {
|
||||
request.
|
||||
get(`${this.getTeamNeededRoute()}/pltmp/${postId}`).
|
||||
set(this.defaultHeaders).
|
||||
type('application/json').
|
||||
accept('application/json').
|
||||
end(this.handleResponse.bind(this, 'getPermalinkTmp', success, error));
|
||||
}
|
||||
|
||||
getPostById = (postId, success, error) => {
|
||||
request.
|
||||
get(`${this.getTeamNeededRoute()}/posts/${postId}`).
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import $ from 'jquery';
|
||||
import ReactDOM from 'react-dom';
|
||||
import * as Utils from 'utils/utils.jsx';
|
||||
import client from 'utils/web_client.jsx';
|
||||
import * as AsyncClient from 'utils/async_client.jsx';
|
||||
import * as GlobalActions from 'action_creators/global_actions.jsx';
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
import LoadingScreen from './loading_screen.jsx';
|
||||
import NewChannelFlow from './new_channel_flow.jsx';
|
||||
@@ -62,7 +62,8 @@ export default class MoreChannels extends React.Component {
|
||||
}
|
||||
handleJoin(channel, channelIndex) {
|
||||
this.setState({joiningChannel: channelIndex});
|
||||
client.joinChannel(channel.id,
|
||||
GlobalActions.emitJoinChannelEvent(
|
||||
channel,
|
||||
() => {
|
||||
$(ReactDOM.findDOMNode(this.refs.modal)).modal('hide');
|
||||
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
|
||||
|
||||
@@ -1416,5 +1416,6 @@
|
||||
"web.footer.privacy": "Privacy",
|
||||
"web.footer.terms": "Terms",
|
||||
"web.header.back": "Back",
|
||||
"web.root.singup_info": "All team communication in one place, searchable and accessible anywhere"
|
||||
"web.root.singup_info": "All team communication in one place, searchable and accessible anywhere",
|
||||
"permalink.error.access": "Permalink belongs to a channel you do not have access to"
|
||||
}
|
||||
|
||||
@@ -187,17 +187,11 @@ function onPermalinkEnter(nextState) {
|
||||
GlobalActions.emitPostFocusEvent(postId);
|
||||
}
|
||||
|
||||
function onChannelEnter(nextState, replace) {
|
||||
doChannelChange(nextState, replace);
|
||||
function onChannelEnter(nextState, replace, callback) {
|
||||
doChannelChange(nextState, replace, callback);
|
||||
}
|
||||
|
||||
function onChannelChange(prevState, nextState, replace) {
|
||||
if (prevState.params.channel !== nextState.params.channel) {
|
||||
doChannelChange(nextState, replace);
|
||||
}
|
||||
}
|
||||
|
||||
function doChannelChange(state, replace) {
|
||||
function doChannelChange(state, replace, callback) {
|
||||
let channel;
|
||||
if (state.location.query.fakechannel) {
|
||||
channel = JSON.parse(state.location.query.fakechannel);
|
||||
@@ -207,11 +201,22 @@ function doChannelChange(state, replace) {
|
||||
channel = ChannelStore.getMoreByName(state.params.channel);
|
||||
}
|
||||
if (!channel) {
|
||||
replace('/');
|
||||
Client.joinChannelByName(
|
||||
state.params.channel,
|
||||
(data) => {
|
||||
GlobalActions.emitChannelClickEvent(data);
|
||||
callback();
|
||||
},
|
||||
() => {
|
||||
replace('/');
|
||||
callback();
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
GlobalActions.emitChannelClickEvent(channel);
|
||||
callback();
|
||||
}
|
||||
|
||||
function renderRootComponent() {
|
||||
@@ -311,7 +316,6 @@ function renderRootComponent() {
|
||||
<Route
|
||||
path='channels/:channel'
|
||||
onEnter={onChannelEnter}
|
||||
onChange={onChannelChange}
|
||||
components={{
|
||||
sidebar: Sidebar,
|
||||
center: ChannelView
|
||||
|
||||
@@ -288,6 +288,14 @@ class ChannelStoreClass extends EventEmitter {
|
||||
getUnreadCounts() {
|
||||
return this.unreadCounts;
|
||||
}
|
||||
|
||||
leaveChannel(id) {
|
||||
delete this.channelMembers[id];
|
||||
const element = this.channels.indexOf(id);
|
||||
if (element > -1) {
|
||||
this.channels.splice(element, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ChannelStore = new ChannelStoreClass();
|
||||
@@ -349,6 +357,7 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => {
|
||||
break;
|
||||
|
||||
case ActionTypes.LEAVE_CHANNEL:
|
||||
ChannelStore.leaveChannel(action.id);
|
||||
ChannelStore.emitLeave(action.id);
|
||||
break;
|
||||
|
||||
|
||||
@@ -162,8 +162,30 @@ describe('Client.Channels', function() {
|
||||
function() {
|
||||
TestHelper.basicClient().joinChannel(
|
||||
channel.id,
|
||||
function(data) {
|
||||
assert.equal(data.id, channel.id);
|
||||
function() {
|
||||
done();
|
||||
},
|
||||
function(err) {
|
||||
done(new Error(err.message));
|
||||
}
|
||||
);
|
||||
},
|
||||
function(err) {
|
||||
done(new Error(err.message));
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('joinChannelByName', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
var channel = TestHelper.basicChannel();
|
||||
TestHelper.basicClient().leaveChannel(
|
||||
channel.id,
|
||||
function() {
|
||||
TestHelper.basicClient().joinChannelByName(
|
||||
channel.name,
|
||||
function() {
|
||||
done();
|
||||
},
|
||||
function(err) {
|
||||
|
||||
Ссылка в новой задаче
Block a user