Skip to content

Commit

Permalink
Enable/Disable Applications migration+behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaniot committed Oct 3, 2017
1 parent 2a28c62 commit d93df2c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
14 changes: 12 additions & 2 deletions controllers/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ApplicationController extends Controller
*/
public function behaviors()
{

return [
'verbs' => [
'class' => VerbFilter::className(),
Expand All @@ -33,12 +34,21 @@ public function behaviors()
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['my-application', 'apply', 'delete-my-application', 'my-delete'],
'actions' => ['my-application'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
'matchCallback' => function ($rule, $action) {
return false === \Yii::$app->user->identity->isAdmin();
}
],
[
'actions' => ['apply', 'delete-my-application', 'my-delete'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return (false === \Yii::$app->user->identity->isAdmin()) &&
(1 == \Yii::$app->db->createCommand('SELECT enable_applications FROM config WHERE id=1')->queryColumn()[0]);
}
],
[
'actions' => ['index', 'delete'],
Expand Down
30 changes: 30 additions & 0 deletions migrations/m171003_081916_create_config_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use yii\db\Migration;

/**
* Handles the creation of table `config`.
*/
class m171003_081916_create_config_table extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$this->createTable('{{%config}}', [
'id' => $this->primaryKey(),
'enable_applications' => $this->boolean()->notNull()->defaultValue(false)
]);

$this->insert('{{%config}}', ['id' => 1, 'enable_applications' => TRUE]);
}

/**
* @inheritdoc
*/
public function safeDown()
{
$this->dropTable('config');
}
}

0 comments on commit d93df2c

Please sign in to comment.