Skip to content

Commit 61a14c4

Browse files
author
Christopher Stebe
committed
major ar record find improvement
1 parent fe0dad1 commit 61a14c4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public static function accessColumnAttributes()
156156
public static function accessColumnAttributes()
157157
{
158158
return [
159-
'owner' => 'user_id', // the column name with owner permissions
160-
'read' => 'read_permission', // the column name with read permissions
159+
'owner' => 'user_id', // the column name with owner permissions
160+
'read' => 'read_permission', // the column name with read permissions
161161
'update' => false, // will do no access checks for update
162162
'delete' => false, // will do no access checks for delete
163163
'domain' => 'language', // the column name with the access domain permission

db/traits/ActiveRecordAccessTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ public static function find()
7272

7373
// access read check
7474
if ($accessRead) {
75-
foreach (array_keys(self::getUsersAuthItems()) as $authItem) {
76-
$query->orWhere('FIND_IN_SET("' . $authItem . '", ' . $accessRead . ')');
77-
}
75+
$queryType = ($accessOwner) ? 'orWhere' : 'where';
76+
$authItems = implode(',', array_keys(self::getUsersAuthItems()));
77+
$query->$queryType('FIND_IN_SET(' . $accessRead . ', "' . $authItems . '") > 0');
7878
}
7979

8080
// access domain check
8181
if ($accessDomain) {
82-
$query->andWhere([$accessDomain => \Yii::$app->language]);
82+
$query->andWhere([$accessDomain => [\Yii::$app->language, self::$_public]]);
8383
}
8484
}
8585

0 commit comments

Comments
 (0)