Skip to content
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

Move admin_audit hooks to proper event listeners #37193

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tcitworld
Copy link
Member

@tcitworld tcitworld commented Mar 13, 2023

Requires #35677

Summary

Moves all of the hooks used by admin_audit to event listeners, where appropriate typed events already exist.

  • Bases itself on Introduced app enable/disable/update typed events #35677 to have app management events
  • Adds a new ConsoleEventV2 typed event to replace the legacy ConsoleEvent event in OCP (already depreciated). However, this doesn't seem used anywhere else, so we could replace it straight away.
  • Adds preview details on the BeforePreviewFetchedEvent event

Part of #14552. Follow #37194 to track all of the hooks left.

TODO

  • Add tests for the new listeners

Checklist

@tcitworld tcitworld added this to the Nextcloud 27 milestone Mar 13, 2023
@tcitworld tcitworld requested review from ChristophWurst, juliushaertl, come-nc, a team, ArtificialOwl and blizzz and removed request for a team March 13, 2023 10:26
@tcitworld tcitworld added this to In progress in Thomas things to do via automation Mar 13, 2023
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Psalm found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@tcitworld tcitworld force-pushed the admin_audit/enh/move-to-event-listeners branch 2 times, most recently from 921aa53 to 82b9461 Compare March 13, 2023 10:54
@come-nc
Copy link
Contributor

come-nc commented Mar 13, 2023

See #32128 as well

@come-nc
Copy link
Contributor

come-nc commented Mar 13, 2023

Is that different/better than #32019 ?

@tcitworld
Copy link
Member Author

I missed this one, thanks. 🙈

Well, there's more stuff in mine. I'll simply take the LDAP stuff from Carl's PR, and take over #32018 as well.

@tcitworld tcitworld force-pushed the admin_audit/enh/move-to-event-listeners branch from 82b9461 to 3fb14cc Compare March 13, 2023 17:54
@tcitworld tcitworld force-pushed the admin_audit/enh/move-to-event-listeners branch 2 times, most recently from 01e64ac to b543f31 Compare March 13, 2023 18:14

$params = [
'itemType' => $share->getNodeType(),
'path' => $share->getNode()->getPath(),
Copy link
Member Author

@tcitworld tcitworld Mar 13, 2023

Choose a reason for hiding this comment

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

question: Unfortunately, this makes extra calls to get the Node. Should the share or the event hold this information?

Copy link
Contributor

Choose a reason for hiding this comment

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

Extra PHP calls? Or extra database queries?
Does not seem that overkill to me.

apps/admin_audit/lib/AppInfo/Application.php Outdated Show resolved Hide resolved

$params = [
'itemType' => $share->getNodeType(),
'path' => $share->getNode()->getPath(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra PHP calls? Or extra database queries?
Does not seem that overkill to me.

lib/public/Console/ConsoleEventV2.php Outdated Show resolved Hide resolved
@come-nc
Copy link
Contributor

come-nc commented Mar 14, 2023

Please strict type the hell out of this, return types on all new methods and strict_type declare on all new files, otherwise nice cleanup!

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
…epreciated ConsoleEvent event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
@tcitworld tcitworld force-pushed the admin_audit/enh/move-to-event-listeners branch from b543f31 to 52a289c Compare May 2, 2023 13:39
CarlSchwan and others added 2 commits May 2, 2023 15:54
Based on work from #32019

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
@tcitworld tcitworld force-pushed the admin_audit/enh/move-to-event-listeners branch from 52a289c to 7f5ff6c Compare May 2, 2023 13:54
@skjnldsv skjnldsv mentioned this pull request May 3, 2023
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

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

some remarks, but nothing fundamental

@@ -94,53 +63,4 @@ public function unassign(string $uid): void {
[ 'uid' ]
Copy link
Member

Choose a reason for hiding this comment

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

left over? I guess the whole class can be trashed just as well.

use OCP\EventDispatcher\IEventListener;

/**
* @template-implements UserManagementEventListener<AppEnableEvent|AppDisableEvent|AppUpdateEvent>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @template-implements UserManagementEventListener<AppEnableEvent|AppDisableEvent|AppUpdateEvent>
* @template-implements AppManagementEventListener<AppEnableEvent|AppDisableEvent|AppUpdateEvent>

use OCP\User\Events\UserLoggedInWithCookieEvent;

/**
* @template-implements UserManagementEventListener<BeforeUserLoggedInEvent|UserLoggedInWithCookieEvent|UserLoggedInEvent|BeforeUserLoggedOutEvent>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @template-implements UserManagementEventListener<BeforeUserLoggedInEvent|UserLoggedInWithCookieEvent|UserLoggedInEvent|BeforeUserLoggedOutEvent>
* @template-implements AuthEventListener<BeforeUserLoggedInEvent|UserLoggedInWithCookieEvent|UserLoggedInEvent|BeforeUserLoggedOutEvent>

use OCP\EventDispatcher\IEventListener;

/**
* @template-implements UserManagementEventListener<ConsoleEventV2>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @template-implements UserManagementEventListener<ConsoleEventV2>
* @template-implements ConsoleEventListener<ConsoleEventV2>

@@ -30,6 +30,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\Log\Audit\CriticalActionPerformedEvent;

/**
* @template-implements UserManagementEventListener<CriticalActionPerformedEvent>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @template-implements UserManagementEventListener<CriticalActionPerformedEvent>
* @template-implements CriticalActionPerformedEventListener<CriticalActionPerformedEvent>

Comment on lines +63 to +69
[
'itemType',
'path',
'itemSource',
'permissions',
'id',
]
Copy link
Member

Choose a reason for hiding this comment

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

array_keys($params)? 😅

'id' => $share->getId()
];

match ($share->getShareType()) {
Copy link
Member

Choose a reason for hiding this comment

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

The type could also be parameterized, saving some lines. It's not translated after all.

/**
* @template-implements UserManagementEventListener<UserCreatedEvent|UserDeletedEvent|UserChangedEvent|PasswordUpdatedEvent|UserIdAssignedEvent|UserIdUnassignedEvent>
*/
class UserManagementEventListener extends Action implements IEventListener {
Copy link
Member

Choose a reason for hiding this comment

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

there are more issues with the docblock, check the static scanner remarks

$this->mapper = $userMapping;
$this->connectionFactory = $connectionFactory;

$this->accessFactory = new AccessFactory(
Copy link
Member

Choose a reason for hiding this comment

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

It should be safe to inject the AccessFactory directly.

IRequest $request,
LoggerInterface $logger,
MemoryInfo $memoryInfo) {
$defaults = \OC::$server->getThemingDefaults();
MemoryInfo $memoryInfo, Defaults $defaults) {
Copy link
Member

Choose a reason for hiding this comment

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

codes style, one argument per line pls

This was referenced May 9, 2023
@blizzz blizzz mentioned this pull request May 17, 2023
@blizzz blizzz modified the milestones: Nextcloud 27, Nextcloud 28 May 23, 2023
@skjnldsv skjnldsv mentioned this pull request Nov 1, 2023
This was referenced Nov 6, 2023
This was referenced Nov 14, 2023
@blizzz blizzz modified the milestones: Nextcloud 28, Nextcloud 29 Nov 23, 2023
This was referenced Mar 12, 2024
This was referenced Mar 20, 2024
@skjnldsv skjnldsv mentioned this pull request Mar 28, 2024
81 tasks
@skjnldsv skjnldsv modified the milestones: Nextcloud 29, Nextcloud 30 Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Thomas things to do
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

5 participants