Skip to content

Commit

Permalink
added basic option to allow user configs, remove config from proxy
Browse files Browse the repository at this point in the history
tabels #1639
  • Loading branch information
nadar committed Nov 29, 2017
1 parent 605dc19 commit e2e20af
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 2 deletions.
3 changes: 3 additions & 0 deletions modules/admin/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ final class Module extends \luya\admin\base\Module implements CoreModuleInterfac
'api-admin-proxymachine' => 'luya\admin\apis\ProxyMachineController',
'api-admin-proxybuild' => 'luya\admin\apis\ProxyBuildController',
'api-admin-proxy' => 'luya\admin\apis\ProxyController',
'api-admin-config' => 'luya\admin\apis\ConfigController',

];

/**
Expand Down Expand Up @@ -258,6 +260,7 @@ public function getMenu()
->itemApi('menu_access_item_user', 'admin/user/index', 'person', 'api-admin-user')
->itemApi('menu_access_item_group', 'admin/group/index', 'group', 'api-admin-group')
->group('menu_group_system')
->itemApi('Config', 'admin/config/index', 'label', 'api-admin-config')
->itemApi('menu_system_item_language', 'admin/lang/index', 'language', 'api-admin-lang')
->itemApi('menu_system_item_tags', 'admin/tag/index', 'view_list', 'api-admin-tag')
->itemApi('menu_system_logger', 'admin/logger/index', 'notifications', 'api-admin-logger')
Expand Down
16 changes: 16 additions & 0 deletions modules/admin/src/apis/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace luya\admin\apis;

/**
* Config Controller.
*
* File has been created with `crud/create` command on LUYA version 1.0.0-dev.
*/
class ConfigController extends \luya\admin\ngrest\base\Api
{
/**
* @var string The path to the model which is the provider for the rules and fields.
*/
public $modelClass = 'luya\admin\models\Config';
}
2 changes: 1 addition & 1 deletion modules/admin/src/apis/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ProxyController extends Controller
* @var array A list of tables which will be ignored and can not be synced with the proxy command.
*/
protected $ignoreTables = [
'migration', 'admin_proxy_build', 'admin_proxy_machine', 'admin_config',
'migration', 'admin_proxy_build', 'admin_proxy_machine',
];

/**
Expand Down
5 changes: 5 additions & 0 deletions modules/admin/src/commands/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public function actionSync()

$process = new ClientTransfer(['build' => $build]);
if ($process->start()) {
// as the admin_config table is synced to, we have to restore the current active config which has been used.
Config::set(self::CONFIG_VAR_IDENTIFIER, $identifier);
Config::set(self::CONFIG_VAR_IDENTIFIER, $token);
Config::set(self::CONFIG_VAR_URL, $url);

return $this->outputSuccess('Sync process has been successfully finished.');
}
}
Expand Down
16 changes: 16 additions & 0 deletions modules/admin/src/controllers/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace luya\admin\controllers;

/**
* Config Controller.
*
* File has been created with `crud/create` command on LUYA version 1.0.0-dev.
*/
class ConfigController extends \luya\admin\ngrest\base\Controller
{
/**
* @var string The path to the model which is the provider for the rules and fields.
*/
public $modelClass = 'luya\admin\models\Config';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use yii\db\Migration;

/**
* Class m171129_104706_config_add_system_type
*/
class m171129_104706_config_add_system_type extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$this->addColumn('admin_config', 'is_system', $this->boolean()->defaultValue(true));
}

/**
* @inheritdoc
*/
public function safeDown()
{
$this->dropColumn('admin_config', 'is_system');
}
}
45 changes: 44 additions & 1 deletion modules/admin/src/models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use yii\db\ActiveRecord;
use luya\traits\RegistryTrait;
use luya\admin\ngrest\base\NgRestModel;

/**
* This is the model class for table "admin_config".
Expand All @@ -14,7 +15,7 @@
* @author Basil Suter <basil@nadar.io>
* @since 1.0.0
*/
final class Config extends ActiveRecord
final class Config extends NgRestModel
{
use RegistryTrait;

Expand All @@ -32,6 +33,14 @@ public static function tableName()
return 'admin_config';
}

/**
* @inheritdoc
*/
public static function ngRestApiEndpoint()
{
return 'api-admin-config';
}

/**
* @inheritdoc
*/
Expand All @@ -40,6 +49,7 @@ public function rules()
return [
[['name', 'value'], 'required'],
[['name'], 'unique'],
[['is_system'], 'integer'],
];
}

Expand All @@ -51,6 +61,39 @@ public function attributeLabels()
return [
'name' => 'Name',
'value' => 'Value',
'is_system' => 'System Config',
];
}

/**
* @inheritdoc
*/
public function ngRestAttributeTypes()
{
return [
'value' => 'text',
'name' => 'slug',
'is_system' => ['hidden', 'value' => 0],
];
}

/**
* @inheritdoc
*/
public function ngRestScopes()
{
return [
[['list'], ['name', 'value']],
[['create', 'update'], ['name', 'value', 'is_system']],
[['delete'], true],
];
}

/**
* @inheritdoc
*/
public static function ngRestFind()
{
return parent::ngRestFind()->where(['is_system' => false]);
}
}

0 comments on commit e2e20af

Please sign in to comment.