-
-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring all drivers via frontend (#1169)
This includes an API endpoint for fetching the list of possible drivers and their configuration fields. In the future, this can be extended to include more meta information about each field.
- Loading branch information
1 parent
2bd40b5
commit 5154d7e
Showing
11 changed files
with
197 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <toby.zerner@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Api\Controller; | ||
|
||
use Flarum\Api\Serializer\MailDriverSerializer; | ||
use Flarum\User\AssertPermissionTrait; | ||
use Illuminate\Contracts\Container\Container; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Tobscure\JsonApi\Document; | ||
|
||
class ListMailDriversController extends AbstractListController | ||
{ | ||
use AssertPermissionTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public $serializer = MailDriverSerializer::class; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function data(ServerRequestInterface $request, Document $document) | ||
{ | ||
$this->assertAdmin($request->getAttribute('actor')); | ||
|
||
$drivers = self::$container->make('mail.supported_drivers'); | ||
array_walk($drivers, function (&$driver, $key) { | ||
$driver = [ | ||
'id' => $key, | ||
'driver' => self::$container->make($driver), | ||
]; | ||
}); | ||
|
||
return $drivers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* (c) Toby Zerner <toby.zerner@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Api\Serializer; | ||
|
||
use Flarum\Mail\DriverInterface; | ||
use InvalidArgumentException; | ||
|
||
class MailDriverSerializer extends AbstractSerializer | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $type = 'mail-drivers'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param \Flarum\Mail\DriverInterface $driver | ||
* @throws InvalidArgumentException | ||
*/ | ||
protected function getDefaultAttributes($driver) | ||
{ | ||
if (! ($driver['driver'] instanceof DriverInterface)) { | ||
throw new InvalidArgumentException( | ||
get_class($this).' can only serialize instances of '.DriverInterface::class | ||
); | ||
} | ||
|
||
$driver = $driver['driver']; | ||
|
||
return [ | ||
'fields' => $driver->availableSettings(), | ||
]; | ||
} | ||
|
||
public function getId($model) | ||
{ | ||
return $model['id']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters