Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Private pusher channel #138

Merged
merged 24 commits into from
Jul 10, 2017
Merged

Private pusher channel #138

merged 24 commits into from
Jul 10, 2017

Conversation

bitamar
Copy link
Contributor

@bitamar bitamar commented Jul 7, 2017

@bitamar bitamar changed the title WIP: Private pusher channel [skip ci] Private pusher channel Jul 8, 2017
@bitamar
Copy link
Contributor Author

bitamar commented Jul 8, 2017

TODOs

@bitamar
Copy link
Contributor Author

bitamar commented Jul 9, 2017

@bitamar bitamar requested a review from amitaibu July 9, 2017 13:41
@bitamar bitamar removed the request for review from amitaibu July 9, 2017 16:24
Copy link
Member

@amitaibu amitaibu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderfull PR! Done with first review :)

(Pusher.Model.AccessToken accessToken)

msg =
case webDataUser of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing it with a combination of RemoteData.map and RemoteData.withDefault, but it looks way more complicated to me. Probably I didn't understand what's the proper way to handle it.

{-| Get a singal if internet connection is lost.
-}
port offline : (Value -> msg) -> Sub msg


pusherLogin : Model -> WebData User -> String -> Cmd Msg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth a comment on the function, and a bit more comments in the function itself.

| PageLogin Pages.Login.Model.Msg
| SetActivePage Page
| SetCurrentDate Date
| Tick Time
| ToggleSideBar
| NoOp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order by alpha bet

, accessTokenPort ""
)
let
( _, pusherLogout ) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably be ( pusherModelUpdated, pusherLogout ) = so we could update it as well:

1
--
( { emptyModel
   | accessToken = ""
   | pusher = pusherModelUpdated

@@ -15,6 +15,7 @@ type alias ItemId =
type alias Item =
{ name : String
, image : String
, privateNote : Maybe String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/
function hedley_pusher_exit() {
$queue = &drupal_static('hedley_pusher_static_queue', []);
if (!empty($queue)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, I prefer less indentation.

if (!$queue) {
  // No registered pusher events.
  return;
}

$this->handler->setAccount(user_load(1));
$result = $this->handler->post('', $pusher_auth_arguments);
$this->assertTrue(intval($result['id']), 'Received auth token ID.');
$this->assertTrue(preg_match('/^key:[\d|\w]+$/', $result['auth']), 'Received token in the expected format.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, even a test. Kudos!

* The pusher channel name: 'general' or 'private-general'.
*/
protected function getPusherChannel($uid) {
return user_access('access private pusher channel', user_load($uid)) ? 'private-general' : 'general';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's the same, I'd still use

$account = $this->getAccount();
eturn user_access('access private pusher channel', $account) ? 'private-general' : 'general';

IMO it makes it clear we're talking about the current user.

public function publicFieldsInfo() {
$public_fields = parent::publicFieldsInfo();

$public_fields['auth'] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> []

* Pusher auth plugin definition.
*/

$plugin = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> []

-- Create a MsgPusher for login, or NoOp in case the user or the config
-- are missing.
msg =
case webDataUser of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested, but could be shorten to:

RemoteData.toMaybe webDataUser
|> Maybe.map (\user -> 
          RemoteData.toMaybe model.config 
          |> Maybe.map (\config -> pusherLoginMsg config.pusherKey user.pusherChannel)
          |> Maybe.withDefault NoOp
     )
|> Maybe.withDefault NoOp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Thanks!

@bitamar bitamar requested a review from amitaibu July 10, 2017 10:25
@amitaibu
Copy link
Member

Great, if you can add a note in the README as-well, indicating the connection of the access private fields, and the private Pusher channel.

README.md Outdated
`access private fields` permission, and currently exposes the item's "Private
note" field, which normal users can't access.

Login for example with `admin` / `admin` to see the item private field, and get
Copy link
Member

@amitaibu amitaibu Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

Login for example with admin / admin to see the private field on for example /#/item/1 (-- @bitamar
is that correct? --).
Only privileged users can see this note. Also when the item will be updated (e.g. via the backend on node/1/edit), it will be updated in real time through the private channel.

@amitaibu
Copy link
Member

Great PR. Thanks @bitamar and @rgrempel !

@amitaibu amitaibu merged commit 4070f09 into master Jul 10, 2017
@amitaibu amitaibu deleted the 123-private-pusher-channel branch July 10, 2017 11:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants