-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic Setup of Action Cable #5744
Conversation
@jywarren Here's the setup of the Action Cable. Have a look at it. |
After deploying this we can test this out. |
After merging of this we can work further on this. |
Screenshots 📸 (click to expand)Learn about automated screenshots Generated by 🚫 Danger |
@jywarren @gautamig54 @gauravano Please review! Thanks |
I think rebasing this could pass tests, since we resolved some big test issues! |
efd2fbf
to
d382520
Compare
Rebased let's hope it passes! |
@jywarren Tests has passed! I think we can ignore the codeclimate? |
@jywarren, @gautamig54 Have a look. |
Can anyone review ? Its pending from a long time. |
@publiclab/reviewers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! I had a few questions, suggestions, etc! Also, once we resolve them, would you like to test this out on unstable
to see how it does in a production environment?
Thanks @namangupta01 this is exciting!!!!
@@ -0,0 +1,13 @@ | |||
App.room = App.cable.subscriptions.create "RoomChannel", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @namangupta01 this is great, and I have nothing against CoffeeScript but do you think we should try to standardize so there's not a mix of coffeescript/javascript in the project? I'm open to suggestions but just thinking about newcomers and how much they have to learn to be able to work on this file... what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I will change it to javascript. 👍
# Called when the subscription has been terminated by the server | ||
|
||
received: (data) -> | ||
console.log("Response: " + data["message"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this affect all users, or is it turned "on" for just some?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said in the other comment. Room channel will be connected to all the sessions.
@@ -0,0 +1,13 @@ | |||
class RoomChannel < ApplicationCable::Channel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will correspond to a "room"? Are we aiming for notifications of comments to start with? Is each node a "room" and comments are messages in the room? Maybe we should make a "NodeChannel" instead, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be multiple channels for multiple features, but I was thinking of making a room_channel which will be connected to all the users irrespective, in the case we want to use it in the future to send some notifications to all the users even they are logged in or not.
And I am going to make a differnt channel for a different feature, for example, node_channel, like_channel etc.
What do you say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts about this @jywarren ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, my apologies for missing this!!! Yes, this sounds good; can you add this as a comment at the top of this file, just so there's some context?
Hi @jywarren, if you can just take out one minute and have a look at it and pass it. I will complete it super soon. Just waiting for your suggestion on my comment. Thanks |
Hi! Please read my comments and let me know what do you think? I am hoping to merge this as soon as possible. |
Thanks Naman. Again, apologies for the slow response. |
@jywarren, I have done the suggested changes. And while testing on |
@jywarren How to see the configuration in https://jenkins.laboratoriopublico.org. Sorry, I checked but I didn't find any configuration. |
Hi I just adjusted our
|
Hi @icarito, thanks for changing the conf. I also tried on my local with this configuration. This is working. But this is not working in |
It's working after restarting |
I "reloaded config" but didn't restart. I'll restart now in case it helps. |
I made some changes to And I guess this is now good to merge. |
Whoa! But shouldn't we limit to admins for now, as this is an easy way to
spam?
…On Sat, Jun 22, 2019, 7:58 AM Naman Gupta ***@***.***> wrote:
I made some changes to config/production.rb. And finally, it worked and
live on unstable.
@jywarren <https://github.com/jywarren> You can check this out on unstable
by typing App.room.speak("hey") in the console and it will appear on all
the sessions connected to unstable. You can test this out by opening the
browser in a different tab, window or even computer.
And I guess this is now good to merge.
Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5744?email_source=notifications&email_token=AAAF6J74SHSDFJWDTA3EZFTP3YHTRA5CNFSM4HN4WH32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYKH5VI#issuecomment-504659669>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J52DJRERTJY62OZLXLP3YHTRANCNFSM4HN4WH3Q>
.
|
Yeah! This is what I was hoping to do in the next part. |
I think maybe we'd better just add a quick check before merging even though
it has no interface yet. You never know!
…On Sat, Jun 22, 2019, 12:42 PM Naman Gupta ***@***.***> wrote:
Yeah! This is what I was hoping to do in the next part.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5744?email_source=notifications&email_token=AAAF6J6B2TSIDI5PNTOROFLP3ZI4FA5CNFSM4HN4WH32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYKNBKI#issuecomment-504680617>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6JYASOLHU7IXKCBS2LTP3ZI4FANCNFSM4HN4WH3Q>
.
|
Sure! I am doing that. I have to add and destroy cookies while logging in and logout. |
55691b2
to
ccde4f3
Compare
@jywarren Please have a look. I have added cookie while loading the page so that the websocket connection is able to find the user and can use role of the user. |
Good to merge? What do you say? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!!
|
||
cookies.signed["user_token"] = nil | ||
if @current_user | ||
cookies.signed["user_token"] = @current_user.persistence_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, so does this update the cookie on any usage of current_user
, or when exactly? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this is answered, I think we are good to merge, yes!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I am using current_user cookie to let the WebSocket while connecting to know that from which user the WebSocket is connecting so that we can do role-based functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because session is not available in ActionCable channels so while loading page we check for current_user and when we are checking for current_user we set the cookie so that the websocket can let the action cable know which user it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren Does this helps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, just want to know, when logging out, will the cookie then be flushed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add any test for this, perhaps a system test? We can do it in follow-up, but I'd like to protect this with some tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that current_user
function will be called when we log out and the browser redirect it to any page. But it good to specifically set the cookie while logging out.
Doing it.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And regarding System Test, yes we can do this in the follow up pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is not needed to set the cookie to nil because while logging out we change the persistence token of the user.
current_user&.reset_persistence_token! |
What do you say? I guess it is not needed. Let me know what do you think?
OK, then, that sounds good! Shall we merge now? Thanks Naman, for being
careful here!
…On Thu, Jun 27, 2019 at 2:33 PM Naman Gupta ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/controllers/application_controller.rb
<#5744 (comment)>:
> @@ -91,6 +91,12 @@ def current_user
# Ensures no code will use old @current_user info. Treat the user
# as anonymous (until the login process sets @current_user again):
@current_user = nil
+
+ end
+
+ cookies.signed["user_token"] = nil
+ if @current_user
+ cookies.signed["user_token"] = @current_user.persistence_token
I guess it is not needed to set the cookie to nil while logging out
because we change the persistence token of the user while logging out.
https://github.com/publiclab/plots2/blob/7b55c883e79d33569482f9a32389914e509705d0/app/controllers/user_sessions_controller.rb#L213
What do you say? I guess it is not needed. Let me know what do you think?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5744?email_source=notifications&email_token=AAAF6JZKB4WUMX5RGUF3OVDP4UBTXA5CNFSM4HN4WH32YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB44TBGI#discussion_r298313294>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAF6J2KYCMBCCIQXLFSHSLP4UBTXANCNFSM4HN4WH3Q>
.
|
Yeah!!!!
On Fri, Jun 28, 2019 at 12:06 AM Jeffrey Warren <notifications@github.com>
wrote:
… OK, then, that sounds good! Shall we merge now? Thanks Naman, for being
careful here!
On Thu, Jun 27, 2019 at 2:33 PM Naman Gupta ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In app/controllers/application_controller.rb
> <#5744 (comment)>:
>
> > @@ -91,6 +91,12 @@ def current_user
> # Ensures no code will use old @current_user info. Treat the user
> # as anonymous (until the login process sets @current_user again):
> @current_user = nil
> +
> + end
> +
> + cookies.signed["user_token"] = nil
> + if @current_user
> + cookies.signed["user_token"] = @current_user.persistence_token
>
> I guess it is not needed to set the cookie to nil while logging out
> because we change the persistence token of the user while logging out.
>
>
https://github.com/publiclab/plots2/blob/7b55c883e79d33569482f9a32389914e509705d0/app/controllers/user_sessions_controller.rb#L213
> What do you say? I guess it is not needed. Let me know what do you think?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#5744?email_source=notifications&email_token=AAAF6JZKB4WUMX5RGUF3OVDP4UBTXA5CNFSM4HN4WH32YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB44TBGI#discussion_r298313294
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AAAF6J2KYCMBCCIQXLFSHSLP4UBTXANCNFSM4HN4WH3Q
>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5744?email_source=notifications&email_token=AE6AEYJXOWTX5J2E4SYRJLTP4UCERA5CNFSM4HN4WH32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYYACFQ#issuecomment-506462486>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE6AEYN2YWLEE6RMLEATBZDP4UCERANCNFSM4HN4WH3Q>
.
|
Ok great! Please test out on stable too! |
* Added room channel * Basic Setup Of Action Cable * Basic Implementation of Testing Channel Completed * Minor Change * Minor Change * Minor Change * Added room channel code in js and removed code in coffeescript * Added ActionCable Config Url and Action Cable Allowed Request Origin * Added ActionCable Config Url and Action Cable Allowed Request Origin * Added ActionCable Config Url and Action Cable Allowed Request Origin * Added Cookie for identifying user in websocket connection * Minor Changes
* Added room channel * Basic Setup Of Action Cable * Basic Implementation of Testing Channel Completed * Minor Change * Minor Change * Minor Change * Added room channel code in js and removed code in coffeescript * Added ActionCable Config Url and Action Cable Allowed Request Origin * Added ActionCable Config Url and Action Cable Allowed Request Origin * Added ActionCable Config Url and Action Cable Allowed Request Origin * Added Cookie for identifying user in websocket connection * Minor Changes
Fixes #5743