bedezign / yii2-audit

Yii2 Audit records and displays web/cli requests, database changes, php/js errors and associated data.
https://bedezign.github.io/yii2-audit/
Other
193 stars 112 forks source link

Audit #208

Closed ghost closed 7 years ago

ghost commented 7 years ago

'modules' => [ 'audit' => [ 'class' => 'bedezign\yii2\audit\Audit', 'ignoreActions' => ['someroute/*'], ], IgnoreActions not working. I still can view the action on the "Audit Entry" Would you help to advice how to check the reason? Thanks.

cornernote commented 7 years ago

You can have a poke around here: https://github.com/bedezign/yii2-audit/blob/master/src/Audit.php#L244

or here: https://github.com/bedezign/yii2-audit/blob/master/src/Audit.php#L473

ghost commented 7 years ago

Thanks. But I tried to run the debugger, the process already can go to return; , I wonder why the audit entry still record the entry.

public function onBeforeAction($event)  
    {
        if (!empty($this->trackActions) && !$this->routeMatches($event->action->uniqueId, $this->trackActions)) {
            return;
        }
        if (!empty($this->ignoreActions) && $this->routeMatches($event->action->uniqueId, $this->ignoreActions)) {
            return; //the process already go to this line, but Audit Entry still record the route
        }
        // Still here, start audit
        $this->getEntry(true);
    }

To solve the problem, I tried to except I added them to ignoreActions and also add the below code to AuditEntry.php, Now the problem seem solved. I doubt the problem is because the model declare the AuditBehaviour so that the Audit Entry still record them.

    public function record()
    {
        $app = Yii::$app;
        $request = $app->request;

        $this->route = $app->requestedAction ? $app->requestedAction->uniqueId : null;
        /* start of my added code */
        if (in_array($this->route,['my/route/*'])){
            return;
        }
        /* end of my added code */
        if ($request instanceof \yii\web\Request) {
            $this->user_id        = Audit::getInstance()->getUserId();
            $this->ip             = $request->userIP;
            $this->ajax           = $request->isAjax;
            $this->request_method = $request->method;
        } else if ($request instanceof \yii\console\Request) {
            $this->request_method = 'CLI';
        }

        $this->save(false);
    }