Skip to content
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
11 changes: 11 additions & 0 deletions components/AbstractItemEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace webvimark\modules\UserManagement\components;

use yii\base\Event;

class AbstractItemEvent extends Event
{
public $parentName;
public $childrenNames;
public $throwException = false;
}
Empty file modified migrations/m140608_173539_create_user_table.php
100755 → 100644
Empty file.
Empty file modified migrations/m140808_073114_create_auth_item_group_table.php
100755 → 100644
Empty file.
Empty file modified migrations/m140809_072112_insert_superadmin_to_user.php
100755 → 100644
Empty file.
Empty file.
Empty file modified migrations/m141023_141535_create_user_visit_log.php
100755 → 100644
Empty file.
Empty file.
Empty file modified migrations/m141121_194858_split_browser_and_os_column.php
100755 → 100644
Empty file.
Empty file.
Empty file modified migrations/m141207_001649_create_basic_user_permissions.php
100755 → 100644
Empty file.
22 changes: 21 additions & 1 deletion models/rbacDB/AbstractItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
namespace webvimark\modules\UserManagement\models\rbacDB;

use webvimark\modules\UserManagement\components\AuthHelper;
use webvimark\modules\UserManagement\components\AbstractItemEvent;
use webvimark\modules\UserManagement\UserManagementModule;
use Yii;
use yii\base\Event;
use yii\base\ModelEvent;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use Yii;
use yii\helpers\Inflector;
use yii\rbac\DbManager;

Expand All @@ -25,6 +28,9 @@
*/
abstract class AbstractItem extends ActiveRecord
{
const EVENT_BEFORE_ADD_CHILDREN = 'beforeAddChildren';
const EVENT_BEFORE_REMOVE_CHILDREN = 'beforeRemoveChildren';

const TYPE_ROLE = 1;
const TYPE_PERMISSION = 2;
const TYPE_ROUTE = 3;
Expand Down Expand Up @@ -81,6 +87,7 @@ public static function addChildren($parentName, $childrenNames, $throwException

$dbManager = new DbManager();

static::beforeAddChildren($parentName, $childrenNames, $throwException = false);
foreach ($childrenNames as $childName)
{
$child = (object)['name'=>$childName];
Expand Down Expand Up @@ -109,6 +116,7 @@ public static function removeChildren($parentName, $childrenNames)
{
$childrenNames = (array) $childrenNames;

static::beforeRemoveChildren($parentName, $childrenNames);
foreach ($childrenNames as $childName)
{
Yii::$app->db->createCommand()
Expand Down Expand Up @@ -247,4 +255,16 @@ public function afterDelete()

AuthHelper::invalidatePermissions();
}

public function beforeAddChildren($parentName, $childrenNames, $throwException = false)
{
$event = new AbstractItemEvent(compact('parentName', 'childrenNames', 'throwException'));
$event->trigger(get_called_class(), self::EVENT_BEFORE_ADD_CHILDREN, $event);
}

public function beforeRemoveChildren($parentName, $childrenNames)
{
$event = new AbstractItemEvent(compact('parentName', 'childrenNames', 'throwException'));
$event->trigger(get_called_class(), self::EVENT_BEFORE_REMOVE_CHILDREN, $event);
}
}