Skip to content

Commit

Permalink
Merge pull request #1236 from prabhat-webkul/fix-1214
Browse files Browse the repository at this point in the history
Fixed #1214
  • Loading branch information
devansh-webkul authored Jun 19, 2024
2 parents 30516c0 + 6caf3b1 commit 2e51db1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
34 changes: 33 additions & 1 deletion packages/Webkul/Admin/src/DataGrids/Setting/UserDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@
use Illuminate\Support\Facades\Storage;
use Webkul\Admin\Traits\ProvideDropdownOptions;
use Webkul\UI\DataGrid\DataGrid;
use Webkul\User\Repositories\UserRepository;

class UserDataGrid extends DataGrid
{
use ProvideDropdownOptions;

/**
* User repository instance.
*
* @var \Webkul\User\Repositories\UserRepository
*/
protected $userRepository;

/**
* Create data grid instance.
*
* @param \Webkul\User\Repositories\UserRepository $userRepository
* @return void
*/
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;

parent::__construct();
}

/**
* Prepare query builder.
*
Expand All @@ -26,7 +47,18 @@ public function prepareQueryBuilder()
'users.image',
'users.status',
'users.created_at'
);
)
->leftJoin('user_groups', 'users.id', '=', 'user_groups.user_id');

$currentUser = auth()->guard('user')->user();

if ($currentUser->view_permission != 'global') {
if ($currentUser->view_permission == 'group') {
$queryBuilder->whereIn('users.id', $this->userRepository->getCurrentUserGroupsUserIds());
} else {
$queryBuilder->where('users.id', $currentUser->id);
}
}

$this->addFilter('id', 'users.id');

Expand Down
2 changes: 1 addition & 1 deletion packages/Webkul/Admin/src/Resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $(function() {
var inputNames = [];

key.split('.').forEach(function(chunk, index) {
if(index) {
if (index) {
inputNames.push('[' + chunk + ']')
} else {
inputNames.push(chunk)
Expand Down
14 changes: 14 additions & 0 deletions packages/Webkul/Attribute/src/Repositories/AttributeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public function getLookUpOptions($lookup, $query = '', $columns = [])
$columns = [($lookup['value_column'] ?? 'id') . ' as id' , ($lookup['label_column'] ?? 'name') . ' as name'];
}

if (Str::contains($lookup['repository'], 'UserRepository')) {
$userRepository = app($lookup['repository']);

$currentUser = auth()->guard('user')->user();

if ($currentUser->view_permission === 'group') {
return $userRepository->leftJoin('user_groups', 'users.id', '=', 'user_groups.user_id')
->where('users.name', 'like', '%' . urldecode($query) . '%')
->get();
} elseif ($currentUser->view_permission === 'individual') {
return $userRepository->findByField('users.id', $currentUser->id);
}
}

return app($lookup['repository'])->findWhere([
[$lookup['label_column'] ?? 'name', 'like', '%' . urldecode($query) . '%']
], $columns);
Expand Down

0 comments on commit 2e51db1

Please sign in to comment.