mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-10-31 01:23:32 +03:00
Nextcloud 32+ #2055
This commit is contained in:
parent
9308bc13f2
commit
47d7378db6
8 changed files with 112 additions and 54 deletions
|
|
@ -40,7 +40,7 @@ There, click on the link to go to the SnappyMail admin panel.
|
|||
<repository>https://github.com/the-djmaze/snappymail/tree/master/integrations/nextcloud</repository>
|
||||
<bugs>https://github.com/the-djmaze/snappymail/issues</bugs>
|
||||
<dependencies>
|
||||
<php min-version="7.4" min-int-size="32" />
|
||||
<php min-version="8.2" min-int-size="32" />
|
||||
<lib>mbstring</lib>
|
||||
<lib>zlib</lib>
|
||||
<!--
|
||||
|
|
@ -63,9 +63,9 @@ There, click on the link to go to the SnappyMail admin panel.
|
|||
<lib>uuid</lib>
|
||||
<lib>xxtea</lib>
|
||||
<lib>zip</lib>
|
||||
<nextcloud min-version="20" max-version="34" />
|
||||
<nextcloud min-version="25" max-version="33" />
|
||||
-->
|
||||
<nextcloud min-version="20" />
|
||||
<nextcloud min-version="25" />
|
||||
</dependencies>
|
||||
<settings>
|
||||
<admin>OCA\SnappyMail\Settings\AdminSettings</admin>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace OCA\SnappyMail\AppInfo;
|
|||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||
use OCA\SnappyMail\Controller\FetchController;
|
||||
use OCA\SnappyMail\Controller\PageController;
|
||||
use OCA\SnappyMail\Dashboard\UnreadMailWidget;
|
||||
use OCA\SnappyMail\Search\Provider;
|
||||
use OCA\SnappyMail\Listeners\AccessTokenUpdatedListener;
|
||||
|
||||
|
|
@ -13,12 +12,13 @@ use OCP\AppFramework\App;
|
|||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\User\Events\PostLoginEvent;
|
||||
use OCP\User\Events\BeforeUserLoggedOutEvent;
|
||||
|
||||
use OCA\OIDCLogin\Events\AccessTokenUpdatedEvent;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Application extends App implements IBootstrap
|
||||
{
|
||||
public const APP_ID = 'snappymail';
|
||||
|
|
@ -30,26 +30,27 @@ class Application extends App implements IBootstrap
|
|||
|
||||
public function register(IRegistrationContext $context): void
|
||||
{
|
||||
// SnappyMailHelper::$server = $c->query('ServerContainer');
|
||||
|
||||
/**
|
||||
* Controllers
|
||||
*/
|
||||
$context->registerService(
|
||||
'PageController', function($c) {
|
||||
'PageController', function(ContainerInterface $c) {
|
||||
return new PageController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request')
|
||||
$c->query('Request'),
|
||||
$c
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$context->registerService(
|
||||
'FetchController', function($c) {
|
||||
'FetchController', function(ContainerInterface $c) {
|
||||
return new FetchController(
|
||||
$c->query('AppName'),
|
||||
$c->query('Request'),
|
||||
$c->getServer()->getAppManager(),
|
||||
$c->query('ServerContainer')->getConfig(),
|
||||
$c->query(IL10N::class)
|
||||
$c
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
@ -67,16 +68,18 @@ class Application extends App implements IBootstrap
|
|||
$context->registerEventListener(AccessTokenUpdatedEvent::class, AccessTokenUpdatedListener::class);
|
||||
|
||||
// TODO: Not working yet, needs a Vue UI
|
||||
// $context->registerDashboardWidget(UnreadMailWidget::class);
|
||||
// $context->registerDashboardWidget(\OCA\SnappyMail\Dashboard\UnreadMailWidget::class);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void
|
||||
{
|
||||
// SnappyMailHelper::$server = $context->getServerContainer();
|
||||
|
||||
if (!\is_dir(\rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/') . '/appdata_snappymail')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dispatcher = $context->getAppContainer()->query('OCP\EventDispatcher\IEventDispatcher');
|
||||
$dispatcher = $context->getAppContainer()->query(\OCP\EventDispatcher\IEventDispatcher::class);
|
||||
$dispatcher->addListener(PostLoginEvent::class, function (PostLoginEvent $Event) {
|
||||
/*
|
||||
// Only store the user's password in the current session if they have
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
namespace OCA\SnappyMail\Command;
|
||||
|
||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||
use OC\Core\Command\Base;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Settings extends Base
|
||||
class Settings extends Command
|
||||
{
|
||||
protected IUserManager $userManager;
|
||||
protected IConfig $config;
|
||||
|
|
|
|||
|
|
@ -11,26 +11,27 @@ use OCP\IConfig;
|
|||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
||||
class FetchController extends Controller {
|
||||
class FetchController extends Controller
|
||||
{
|
||||
private IConfig $config;
|
||||
private IAppManager $appManager;
|
||||
private IL10N $l;
|
||||
private IL10N $l10n;
|
||||
|
||||
public function __construct(string $appName, IRequest $request, IAppManager $appManager, IConfig $config, IL10N $l) {
|
||||
public function __construct(string $appName, IRequest $request, \Psr\Container\ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($appName, $request);
|
||||
$this->config = $config;
|
||||
$this->appManager = $appManager;
|
||||
$this->l = $l;
|
||||
$this->config = $container->query(IConfig::class);
|
||||
$this->l10n = $container->query(IL10N::class);
|
||||
}
|
||||
|
||||
public function upgrade(): JSONResponse {
|
||||
public function upgrade(): JSONResponse
|
||||
{
|
||||
$error = 'Upgrade failed';
|
||||
try {
|
||||
SnappyMailHelper::loadApp();
|
||||
if (\SnappyMail\Upgrade::core()) {
|
||||
return new JSONResponse([
|
||||
'status' => 'success',
|
||||
'Message' => $this->l->t('Upgraded successfully')
|
||||
'Message' => $this->l10n->t('Upgraded successfully')
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
|
@ -42,7 +43,8 @@ class FetchController extends Controller {
|
|||
]);
|
||||
}
|
||||
|
||||
public function setAdmin(): JSONResponse {
|
||||
public function setAdmin(): JSONResponse
|
||||
{
|
||||
try {
|
||||
$sUrl = '';
|
||||
$sPath = '';
|
||||
|
|
@ -57,7 +59,7 @@ class FetchController extends Controller {
|
|||
} else {
|
||||
return new JSONResponse([
|
||||
'status' => 'error',
|
||||
'Message' => $this->l->t('Invalid argument(s)')
|
||||
'Message' => $this->l10n->t('Invalid argument(s)')
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +89,7 @@ class FetchController extends Controller {
|
|||
|
||||
return new JSONResponse([
|
||||
'status' => 'success',
|
||||
'Message' => $this->l->t('Saved successfully')
|
||||
'Message' => $this->l10n->t('Saved successfully')
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse([
|
||||
|
|
@ -100,11 +102,13 @@ class FetchController extends Controller {
|
|||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setPersonal(): JSONResponse {
|
||||
public function setPersonal(): JSONResponse
|
||||
{
|
||||
try {
|
||||
$sEmail = '';
|
||||
if (isset($_POST['appname'], $_POST['snappymail-password'], $_POST['snappymail-email']) && 'snappymail' === $_POST['appname']) {
|
||||
$sUser = SnappyMailHelper::getUID();
|
||||
// $sUser = $this->userSession->getUser()?->getUID();
|
||||
if ($sUser) {
|
||||
$sEmail = $_POST['snappymail-email'];
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sEmail);
|
||||
|
|
@ -118,7 +122,7 @@ class FetchController extends Controller {
|
|||
} else {
|
||||
return new JSONResponse([
|
||||
'status' => 'error',
|
||||
'Message' => $this->l->t('Invalid argument(s)'),
|
||||
'Message' => $this->l10n->t('Invalid argument(s)'),
|
||||
'Email' => $sEmail
|
||||
]);
|
||||
}
|
||||
|
|
@ -129,7 +133,7 @@ class FetchController extends Controller {
|
|||
|
||||
return new JSONResponse([
|
||||
'status' => 'success',
|
||||
'Message' => $this->l->t('Saved successfully'),
|
||||
'Message' => $this->l10n->t('Saved successfully'),
|
||||
'Email' => $sEmail
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
|
|
|
|||
|
|
@ -8,16 +8,28 @@ use OCA\SnappyMail\ContentSecurityPolicy;
|
|||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
||||
use OCP\IConfig;
|
||||
use OCP\INavigationManager;
|
||||
use OCP\IRequest;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
private IConfig $config;
|
||||
private INavigationManager $navigationManager;
|
||||
|
||||
public function __construct($appName, IRequest $request, \Psr\Container\ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($appName, $request);
|
||||
$this->config = $container->query(IConfig::class);
|
||||
$this->navigationManager = $container->query(INavigationManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$nav = SnappyMailHelper::getNavigationManager();
|
||||
|
||||
$bAdmin = false;
|
||||
if (!empty($_SERVER['QUERY_STRING'])) {
|
||||
SnappyMailHelper::loadApp();
|
||||
|
|
@ -28,7 +40,7 @@ class PageController extends Controller
|
|||
}
|
||||
|
||||
if (!$bAdmin && SnappyMailHelper::getAppConfigValue('snappymail-no-embed')) {
|
||||
$nav->setActiveEntry('snappymail');
|
||||
$this->navigationManager->setActiveEntry('snappymail');
|
||||
\OCP\Util::addScript('snappymail', 'snappymail');
|
||||
\OCP\Util::addStyle('snappymail', 'style');
|
||||
SnappyMailHelper::startApp();
|
||||
|
|
@ -43,7 +55,7 @@ class PageController extends Controller
|
|||
return $response;
|
||||
}
|
||||
|
||||
$nav->setActiveEntry('snappymail');
|
||||
$this->navigationManager->setActiveEntry('snappymail');
|
||||
|
||||
\OCP\Util::addStyle('snappymail', 'embed');
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@
|
|||
namespace OCA\SnappyMail\Migration;
|
||||
|
||||
use OCA\SnappyMail\AppInfo\Application;
|
||||
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
use OCP\ILogger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Note: this is not run at install, but when:
|
||||
|
|
@ -15,11 +18,24 @@ use OCP\ILogger;
|
|||
*/
|
||||
class InstallStep implements IRepairStep
|
||||
{
|
||||
public function getName() {
|
||||
private IAppManager $appManager;
|
||||
private IConfig $config;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(IAppManager $appManager, IConfig $config, LoggerInterface $logger)
|
||||
{
|
||||
$this->appManager = $appManager;
|
||||
$this->config = $config;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Setup SnappyMail';
|
||||
}
|
||||
|
||||
public function run(IOutput $output) {
|
||||
public function run(IOutput $output)
|
||||
{
|
||||
|
||||
$output->info('clearstatcache');
|
||||
\clearstatcache();
|
||||
|
|
@ -53,7 +69,7 @@ class InstallStep implements IRepairStep
|
|||
|
||||
if (!$oConfig->Get('webmail', 'app_path')) {
|
||||
$output->info('Set config [webmail]app_path');
|
||||
$oConfig->Set('webmail', 'app_path', \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/');
|
||||
$oConfig->Set('webmail', 'app_path', $this->appManager->getAppWebPath('snappymail') . '/app/');
|
||||
$oConfig->Set('webmail', 'allow_languages_on_settings', false);
|
||||
$oConfig->Set('login', 'allow_languages_on_login', false);
|
||||
$bSave = true;
|
||||
|
|
@ -116,9 +132,7 @@ class InstallStep implements IRepairStep
|
|||
// ex: php occ config:app:set snappymail custom_config_file --value="/path/to/config.php"
|
||||
// https://github.com/the-djmaze/snappymail/pull/1197
|
||||
try {
|
||||
/** @var IConfig $ncConfig */
|
||||
$ncConfig = \OC::$server->get(IConfig::class);
|
||||
$customConfigFile = $ncConfig->getAppValue(Application::APP_ID, 'custom_config_file');
|
||||
$customConfigFile = $this->config->getAppValue(Application::APP_ID, 'custom_config_file');
|
||||
if ($customConfigFile) {
|
||||
$output->info("Load custom config: {$customConfigFile}");
|
||||
if (!\str_contains($customConfigFile, ':') && \is_readable($customConfigFile)) {
|
||||
|
|
@ -129,9 +143,7 @@ class InstallStep implements IRepairStep
|
|||
}
|
||||
} catch (\Throwable $e) {
|
||||
$output->warning("custom config error: " . $e->getMessage());
|
||||
/** @var \Psr\Log\LoggerInterface $logger */
|
||||
$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
|
||||
$logger->error("custom config error: " . $e->getMessage());
|
||||
$this->logger->error("custom config error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,32 @@ use OCP\AppFramework\Http\TemplateResponse;
|
|||
use OCP\IConfig;
|
||||
use OCP\Settings\ISettings;
|
||||
|
||||
use OCP\IUserSession;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\Util;
|
||||
|
||||
class AdminSettings implements ISettings
|
||||
{
|
||||
private $config;
|
||||
private IConfig $config;
|
||||
private IUserSession $userSession;
|
||||
private IGroupManager $groupManager;
|
||||
private IURLGenerator $urlGenerator;
|
||||
private IAppManager $appManager;
|
||||
|
||||
public function __construct(IConfig $config)
|
||||
{
|
||||
public function __construct(
|
||||
IConfig $config,
|
||||
IUserSession $userSession,
|
||||
IGroupManager $groupManager,
|
||||
IURLGenerator $urlGenerator,
|
||||
IAppManager $appManager
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->appManager = $appManager;
|
||||
}
|
||||
|
||||
public function getForm()
|
||||
|
|
@ -29,12 +48,13 @@ class AdminSettings implements ISettings
|
|||
foreach ($keys as $k) {
|
||||
$parameters[$k] = $this->config->getAppValue('snappymail', $k);
|
||||
}
|
||||
$uid = SnappyMailHelper::getUID();
|
||||
if (\OC_User::isAdminUser($uid)) {
|
||||
|
||||
$uid = $this->userSession->getUser()?->getUID();
|
||||
if ($uid && $this->groupManager->isAdmin($uid)) {
|
||||
// $parameters['snappymail-admin-panel-link'] = SnappyMailHelper::getAppUrl().'?admin';
|
||||
SnappyMailHelper::loadApp();
|
||||
$parameters['snappymail-admin-panel-link'] =
|
||||
\OC::$server->getURLGenerator()->linkToRoute('snappymail.page.index')
|
||||
$this->urlGenerator->linkToRoute('snappymail.page.index')
|
||||
. '?' . \RainLoop\Api::Config()->Get('security', 'admin_panel_key', 'admin');
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +68,7 @@ class AdminSettings implements ISettings
|
|||
$parameters['snappymail-admin-password'] = $sPassword;
|
||||
|
||||
$parameters['can-import-rainloop'] = $sPassword && \is_dir(
|
||||
\rtrim(\trim(SnappyMailHelper::getSystemConfigValue('datadirectory', '')), '\\/')
|
||||
\rtrim(\trim($this->config->getSystemValue('datadirectory', '')), '\\/')
|
||||
. '/rainloop-storage'
|
||||
);
|
||||
|
||||
|
|
@ -64,7 +84,7 @@ class AdminSettings implements ISettings
|
|||
// Prevent "Failed loading /nextcloud/snappymail/v/2.N.N/static/js/min/libs.min.js"
|
||||
$app_path = $oConfig->Get('webmail', 'app_path');
|
||||
if (!$app_path) {
|
||||
$app_path = \OC::$server->getAppManager()->getAppWebPath('snappymail') . '/app/';
|
||||
$app_path = $this->appManager->getAppWebPath('snappymail') . '/app/';
|
||||
$oConfig->Set('webmail', 'app_path', $app_path);
|
||||
$oConfig->Set('webmail', 'theme', 'NextcloudV25+');
|
||||
$oConfig->Save();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@ class SnappyMailResponse extends \OCP\AppFramework\Http\Response
|
|||
|
||||
class SnappyMailHelper
|
||||
{
|
||||
public static $server;
|
||||
|
||||
public static function getServerContainer(): object
|
||||
{
|
||||
return static::$server || \OC::$server;
|
||||
}
|
||||
|
||||
public static function getConfig(): object
|
||||
{
|
||||
return \method_exists(\OC::$server, 'getConfig')
|
||||
|
|
@ -60,7 +67,7 @@ class SnappyMailHelper
|
|||
|
||||
public static function getUID(): mixed
|
||||
{
|
||||
return static::getUser()->getUID();
|
||||
return static::getUser()?->getUID();
|
||||
}
|
||||
|
||||
public static function getUser(): object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue