Skip to content

Add logout prehooks#29329

Merged
sharidas merged 1 commit into
masterfrom
logout-prehooks
Oct 26, 2017
Merged

Add logout prehooks#29329
sharidas merged 1 commit into
masterfrom
logout-prehooks

Conversation

@sharidas

Copy link
Copy Markdown
Contributor

This change will help to do actions
in logout prehooks. Any changes to
be made before logout action can be
done here.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

Add logout prehooks

Related Issue

Motivation and Context

Adding logout prehooks

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sharidas sharidas self-assigned this Oct 23, 2017
@sharidas sharidas requested a review from PVince81 October 23, 2017 13:00
@sharidas sharidas added this to the development milestone Oct 23, 2017
Comment thread lib/private/Server.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional, but we can consider following the naming convention of EventDispatcher.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please do

Comment thread lib/private/User/Session.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

indentation

@sharidas sharidas force-pushed the logout-prehooks branch 2 times, most recently from 31ac4bf to 79c47cb Compare October 23, 2017 13:17
@codecov

codecov Bot commented Oct 23, 2017

Copy link
Copy Markdown

Codecov Report

Merging #29329 into master will increase coverage by <.01%.
The diff coverage is 77.77%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #29329      +/-   ##
============================================
+ Coverage     60.21%   60.21%   +<.01%     
- Complexity    17182    17183       +1     
============================================
  Files          1030     1030              
  Lines         57271    57280       +9     
============================================
+ Hits          34485    34493       +8     
- Misses        22786    22787       +1
Impacted Files Coverage Δ Complexity Δ
lib/private/User/Session.php 62.61% <100%> (+1%) 118 <0> (+1) ⬆️
lib/private/Server.php 82.22% <33.33%> (-0.22%) 118 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e8d5f70...44b511c. Read the comment docs.

Comment thread lib/private/User/Session.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't abuse the session to pass around variables. There is an existing way to receive values from a symfony event, just use it. Here's an example: https://github.com/owncloud/guests/blob/master/controller/userscontroller.php#L130

@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 No more sessions. Data handled via Symfony events.

Comment thread lib/private/User/Session.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should be called "cancel".

Also why not use booleans instead of strings containing booleans ?

@sharidas sharidas force-pushed the logout-prehooks branch 2 times, most recently from 685b513 to 4fb0892 Compare October 23, 2017 15:14
@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 Updated the new patch by making 'cancel' and used booleans instead of string containing booleans. Thanks for the feedback.

Comment thread lib/private/User/Session.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you tested this ? You are not even firing the event with $eventDispatcher

Please look again at the example I posted and use the same approach

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, that's a misunderstanding. Core must fire the event and apps must listen to it to react, not the other way around.

@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 Updated the change to trigger the event from core. And the impersonate app reacts to it. Thanks for the feedback.

@sharidas sharidas force-pushed the logout-prehooks branch 2 times, most recently from 42b213c to 370ae0f Compare October 24, 2017 09:47
@sharidas sharidas changed the title [WIP] Add logout prehooks Add logout prehooks Oct 24, 2017
@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 I have used naming convention for the event names. Let me know if this change is ok.

Comment thread lib/private/Server.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"user.pre_logout_hook" is better i guess. According to the naming convention:
-Use only lowercase letters, numbers, dots (.) and underscores (_);
-Prefix names with a namespace followed by a dot (e.g. order., user.*);
-End names with a verb that indicates what action has been taken (e.g. order.placed).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread lib/private/Server.php Outdated
});
$userSession->listen('\OC\User', 'preLogout', function () {
$event = new GenericEvent(null, []);
\OC::$server->getEventDispatcher()->dispatch('user.pre_logout_hook', $event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmmm, is this the official Symfony naming convention ? for all other Symfony events in OC we used a namespaced name, please look it up

@karakayasemi karakayasemi Oct 25, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://symfony.com/doc/current/components/event_dispatcher.html#naming-conventions
Yes, this is the official Symfony naming convention, but we don't have to follow that of course. I checked quickly the other Symfony events in OC. Generally, we used a namespaced name, but 3rdparty libraries are following this convention, like:


or
const RETRY_PARAM = 'plugins.backoff.retry_count';

All the events related to a class should be constant class property and we should use these constants when dispatching an event. IMHO it is cleaner.
By the way, core has some codes that follow the convention:
$dispatcher->dispatch('remoteshare.declined', $event);

or
https://github.com/owncloud/core/blob/master/lib/public/Http/HttpEvents.php#L32

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For code consistency I am modifying the event name to use namespace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@DeepDiver1975 any comment on this ? I assume we want to continue using the namespace format like we did for loadAdditionalScripts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AFAIK, we are still in the adaptation phase to EventDispatcher. IMHO, we can add event strings as constant property to the related class, we can track it under #29174 and follow the convention.

@PVince81 PVince81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please double check namespace format and add unit tests to make codecov happy.

@sharidas sharidas force-pushed the logout-prehooks branch 2 times, most recently from 13c4c61 to 3af8477 Compare October 25, 2017 10:27
Comment thread lib/private/User/Session.php Outdated

$event = new GenericEvent(null, ['cancel' => false]);
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->dispatch('\OC\User\Session::cancel_logout', $event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, the event should be \OC\User\Session::pre_logout. We are informing every listener that we are about to logout, not about the cancel.

Comment thread lib/private/Server.php Outdated
});
$userSession->listen('\OC\User', 'preLogout', function () {
$event = new GenericEvent(null, []);
\OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logouthook', $event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"pre_logout", remove the "hook" from the name

@sharidas

Copy link
Copy Markdown
Contributor Author

@PVince81 Hope the code looks better.

@PVince81 PVince81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 thanks, please backport

@sharidas

Copy link
Copy Markdown
Contributor Author

Backport PR: #29352

@sharidas sharidas force-pushed the logout-prehooks branch 2 times, most recently from d4ba906 to d859408 Compare October 26, 2017 03:18
This change will help to do actions
in logout prehooks. Any changes to
be made before logout action can be
done here.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas merged commit c12854c into master Oct 26, 2017
@sharidas sharidas deleted the logout-prehooks branch October 26, 2017 08:44
@sharidas sharidas mentioned this pull request Nov 28, 2017
9 tasks
@lock

lock Bot commented Aug 2, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants