Add logout prehooks#29329
Conversation
There was a problem hiding this comment.
optional, but we can consider following the naming convention of EventDispatcher.
31ac4bf to
79c47cb
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
79c47cb to
f75b7ef
Compare
There was a problem hiding this comment.
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
f75b7ef to
1037226
Compare
|
@PVince81 No more sessions. Data handled via Symfony events. |
There was a problem hiding this comment.
I think this should be called "cancel".
Also why not use booleans instead of strings containing booleans ?
685b513 to
4fb0892
Compare
|
@PVince81 Updated the new patch by making 'cancel' and used booleans instead of string containing booleans. Thanks for the feedback. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
There was a problem hiding this comment.
Ah, that's a misunderstanding. Core must fire the event and apps must listen to it to react, not the other way around.
1e536bf to
32039d5
Compare
|
@PVince81 Updated the change to trigger the event from core. And the impersonate app reacts to it. Thanks for the feedback. |
42b213c to
370ae0f
Compare
|
@PVince81 I have used naming convention for the event names. Let me know if this change is ok. |
There was a problem hiding this comment.
"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).
370ae0f to
8988368
Compare
| }); | ||
| $userSession->listen('\OC\User', 'preLogout', function () { | ||
| $event = new GenericEvent(null, []); | ||
| \OC::$server->getEventDispatcher()->dispatch('user.pre_logout_hook', $event); |
There was a problem hiding this comment.
hmmm, is this the official Symfony naming convention ? for all other Symfony events in OC we used a namespaced name, please look it up
There was a problem hiding this comment.
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
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:
core/apps/files_sharing/lib/API/Remote.php
Line 116 in baf07a7
or
https://github.com/owncloud/core/blob/master/lib/public/Http/HttpEvents.php#L32
There was a problem hiding this comment.
For code consistency I am modifying the event name to use namespace.
There was a problem hiding this comment.
@DeepDiver1975 any comment on this ? I assume we want to continue using the namespace format like we did for loadAdditionalScripts
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
please double check namespace format and add unit tests to make codecov happy.
13c4c61 to
3af8477
Compare
|
|
||
| $event = new GenericEvent(null, ['cancel' => false]); | ||
| $eventDispatcher = \OC::$server->getEventDispatcher(); | ||
| $eventDispatcher->dispatch('\OC\User\Session::cancel_logout', $event); |
There was a problem hiding this comment.
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.
| }); | ||
| $userSession->listen('\OC\User', 'preLogout', function () { | ||
| $event = new GenericEvent(null, []); | ||
| \OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logouthook', $event); |
There was a problem hiding this comment.
"pre_logout", remove the "hook" from the name
3af8477 to
eb1384d
Compare
|
@PVince81 Hope the code looks better. |
PVince81
left a comment
There was a problem hiding this comment.
👍 thanks, please backport
|
Backport PR: #29352 |
d4ba906 to
d859408
Compare
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>
d859408 to
44b511c
Compare
|
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. |
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
Checklist: