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

[stable27] add user to group of company after cretated #55

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ occ config:system:set auth.bruteforce.protection.enabled --value false --type bo
occ config:app:set password_policy minLength --value 8
occ config:system:set force_language --value en
occ config:system:set knowledgebaseenabled --value false --type boolean
occ config:system:set overwrite.cli.url --value "https://mycompany.coop"

# Skeleton directory
# First, go to root folder of Nextcloud
Expand Down
311 changes: 190 additions & 121 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@

use OCA\Analytics\Datasource\DatasourceEvent;
use OCA\MyCompany\Listener\AnalyticsDatasourceListener;
use OCA\MyCompany\Listener\UserCreatedEventListener;
use OCA\MyCompany\Middleware\InjectionMiddleware;
use OCA\MyCompany\Provider\PublicShareTemplateProvider;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\User\Events\UserCreatedEvent;

/**
* @codeCoverageIgnore
Expand All @@ -52,5 +54,6 @@ public function register(IRegistrationContext $context): void {
$context->registerMiddleWare(InjectionMiddleware::class, true);
$context->registerPublicShareTemplateProvider(PublicShareTemplateProvider::class);
$context->registerEventListener(DatasourceEvent::class, AnalyticsDatasourceListener::class);
$context->registerEventListener(UserCreatedEvent::class, UserCreatedEventListener::class);
}
}
9 changes: 6 additions & 3 deletions lib/Datasource/AdminAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ public function readData($option): array {
$i = 1;
while (($buffer = fgets($fp, 4096)) !== false) {
$json = json_decode($buffer, true);
if (str_contains($json['message'], '.directory')) {
continue;
}
if (!str_contains($json['message'], 'File accessed')) {
continue;
}
preg_match('/File accessed: "(?<file>.*)"/', $json['message'], $matches);
$data[] = [
$json['user'],
$json['time'],
$matches['file'],
$json['user'],
$json['remoteAddr'],
$json['userAgent'],
$i,
Expand All @@ -89,12 +92,12 @@ public function readData($option): array {
fclose($fp);

$header = [
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the user that trigged the log.
$this->l10n->t('User'),
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the date of log.
$this->l10n->t('Date'),
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the acessed file.
$this->l10n->t('File'),
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the user that trigged the log.
$this->l10n->t('User'),
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the IP of user that trigged the log.
$this->l10n->t('IP'),
// TRANSLATORS Column name of report that list log entries of app Audit Report. This column will display the user agent of user that trigged the log.
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/AnalyticsDatasourceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<Event|DatasourceEvent>
*/
class AnalyticsDatasourceListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof DatasourceEvent)) {
Expand Down
59 changes: 59 additions & 0 deletions lib/Listener/UserCreatedEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023, Vitor Mattos <[email protected]>
*
* @author Vitor Mattos <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\MyCompany\Listener;

use OCA\MyCompany\Service\CompanyService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IGroupManager;
use OCP\User\Events\UserCreatedEvent;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<Event|UserCreatedEvent>
*/
class UserCreatedEventListener implements IEventListener {
public function __construct(
private IGroupManager $groupManager,
private CompanyService $companyService,
private LoggerInterface $logger,
) {
}

public function handle(Event $event): void {
if (!($event instanceof UserCreatedEvent)) {
// Unrelated
return;
}
$user = $event->getUser();
$group = $this->groupManager->get($this->companyService->getCompanyCode());
if ($group === null) {
return;
}
$group->addUser($user);
}
}
13 changes: 11 additions & 2 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="lib/AppInfo/Application.php">
<InvalidArgument>
<code>AnalyticsDatasourceListener::class</code>
</InvalidArgument>
<UndefinedClass>
<code>DatasourceEvent</code>
<code>PublicShareTemplateProvider</code>
Expand Down Expand Up @@ -63,12 +66,18 @@
</UndefinedInterfaceMethod>
</file>
<file src="lib/Listener/AnalyticsDatasourceListener.php">
<MissingTemplateParam>
<InvalidTemplateParam>
<code>IEventListener</code>
</MissingTemplateParam>
</InvalidTemplateParam>
<MoreSpecificImplementedParamType>
<code>$event</code>
</MoreSpecificImplementedParamType>
<UndefinedClass>
<code>DatasourceEvent</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code>AnalyticsDatasourceListener</code>
</UndefinedDocblockClass>
</file>
<file src="lib/Middleware/InjectionMiddleware.php">
<UndefinedClass>
Expand Down
28 changes: 13 additions & 15 deletions vendor-bin/cs-fixer/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions vendor-bin/phpunit/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading