summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-04-27 16:02:58 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2016-04-27 16:02:58 -0400
commitfa807d8e436e87b8c1749ea54c293a15c67f7f29 (patch)
tree9557bb5342425dffd3606cb03f1378de5f5cc032 /webapp
parentd962e175f838817f4db060227cf8b5e2258b887c (diff)
downloadchat-fa807d8e436e87b8c1749ea54c293a15c67f7f29.tar.gz
chat-fa807d8e436e87b8c1749ea54c293a15c67f7f29.tar.bz2
chat-fa807d8e436e87b8c1749ea54c293a15c67f7f29.zip
Fixing permalinks to channels your not a memeber of (#2805)
Diffstat (limited to 'webapp')
-rw-r--r--webapp/action_creators/global_actions.jsx40
-rw-r--r--webapp/client/client.jsx26
-rw-r--r--webapp/components/more_channels.jsx5
-rw-r--r--webapp/i18n/en.json3
-rw-r--r--webapp/root.jsx26
-rw-r--r--webapp/stores/channel_store.jsx9
-rw-r--r--webapp/tests/client_channel.test.jsx26
7 files changed, 108 insertions, 27 deletions
diff --git a/webapp/action_creators/global_actions.jsx b/webapp/action_creators/global_actions.jsx
index bf1d82aee..335c20219 100644
--- a/webapp/action_creators/global_actions.jsx
+++ b/webapp/action_creators/global_actions.jsx
@@ -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,
+ );
+}
diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx
index 98e660227..53a514082 100644
--- a/webapp/client/client.jsx
+++ b/webapp/client/client.jsx
@@ -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}`).
diff --git a/webapp/components/more_channels.jsx b/webapp/components/more_channels.jsx
index 3ab05341b..04c613ce5 100644
--- a/webapp/components/more_channels.jsx
+++ b/webapp/components/more_channels.jsx
@@ -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);
diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json
index 6d4f4c287..e56582832 100644
--- a/webapp/i18n/en.json
+++ b/webapp/i18n/en.json
@@ -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"
}
diff --git a/webapp/root.jsx b/webapp/root.jsx
index 1e9adea16..e90d3fdc5 100644
--- a/webapp/root.jsx
+++ b/webapp/root.jsx
@@ -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
diff --git a/webapp/stores/channel_store.jsx b/webapp/stores/channel_store.jsx
index 9437d5e44..32ea8441c 100644
--- a/webapp/stores/channel_store.jsx
+++ b/webapp/stores/channel_store.jsx
@@ -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;
diff --git a/webapp/tests/client_channel.test.jsx b/webapp/tests/client_channel.test.jsx
index b8374123c..9d88f3de0 100644
--- a/webapp/tests/client_channel.test.jsx
+++ b/webapp/tests/client_channel.test.jsx
@@ -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) {