Skip to content

Commit

Permalink
Miscellaneous fixes (#98)
Browse files Browse the repository at this point in the history
* Simplify working with paths in README
* Sync related to SimpleRuleFactory
* Actualize badges
* Improve wording
  • Loading branch information
arogachev committed Feb 18, 2024
1 parent 9872beb commit 19fd26c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -3,4 +3,3 @@
| Is bugfix? | ✔️/❌
| New feature? | ✔️/❌
| Breaks BC? | ✔️/❌
| Fixed issues | comma-separated list of tickets # fixed by the PR, if any
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -21,7 +21,7 @@
- Enh #94: Decrease size for string columns from 128 to 126 for PostgreSQL optimization (@arogachev)
- Enh #95: Backwards sync of changes with rbac-db package (@arogachev)
- Bug #95: Handle null result when getting access tree using MySQL 5.7 (@arogachev)
- Chg #97: Rename `getAccessTree()` to `getHierarchy()` in `ItemsStorageInterface` (@arogachev)
- Chg #97: Rename `getAccessTree()` to `getHierarchy()` in `ItemsStorageInterface` implmentations (@arogachev)

## 2.0.0 April 20, 2023

Expand Down
31 changes: 16 additions & 15 deletions README.md
Expand Up @@ -11,14 +11,23 @@ The package provides [Cycle Database](https://github.com/cycle/database) storage
[![Latest Stable Version](https://poser.pugx.org/yiisoft/rbac-cycle-db/v/stable.png)](https://packagist.org/packages/yiisoft/rbac-cycle-db)
[![Total Downloads](https://poser.pugx.org/yiisoft/rbac-cycle-db/downloads.png)](https://packagist.org/packages/yiisoft/rbac-cycle-db)
[![Build status](https://github.com/yiisoft/rbac-cycle-db/workflows/build/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Abuild)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/rbac-cycle-db/?branch=master)
[![codecov](https://codecov.io/gh/yiisoft/rbac-cycle-db/graph/badge.svg?token=OAABFCCC7A)](https://codecov.io/gh/yiisoft/rbac-cycle-db)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Frbac-cycle-db%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/rbac-cycle-db/master)
[![static analysis](https://github.com/yiisoft/rbac-cycle-db/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/rbac-cycle-db/coverage.svg)](https://shepherd.dev/github/yiisoft/rbac-cycle-db)

Detailed build statuses:

| RDBMS | Status |
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| SQLite | [![SQLite status](https://github.com/yiisoft/rbac-cycle-db/workflows/sqlite/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Asqlite) |
| MySQL | [![MYSQL status](https://github.com/yiisoft/rbac-cycle-db/workflows/mysql/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Amysql) |
| PostgreSQL | [![MYSQL status](https://github.com/yiisoft/rbac-cycle-db/workflows/pgsql/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Apgsql) |
| Microsoft SQL Server | [![MYSQL status](https://github.com/yiisoft/rbac-cycle-db/workflows/mssql/badge.svg)](https://github.com/yiisoft/rbac-cycle-db/actions?query=workflow%3Amssql) |

## Requirements

- PHP 8.0 or higher.
- PHP 8.1 or higher.
- In case of using with SQLite, minimal required version is 3.8.3.
- In case of using with SQL Server, minimal required version of PDO is 5.11.1.

Expand Down Expand Up @@ -88,18 +97,10 @@ use Cycle\Migrations\FileRepository;
use Cycle\Migrations\Migrator;

$migrationsSubfolders = ['items', 'assignments'];
$directories = [];
foreach (static::$migrationsSubfolders as $subfolder) {
$directories[] = implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 2), // Adjust this if your path is different.
'vendor',
'yiisoft',
'rbac',
'migrations',
$subfolder,
]);
}

$directories = array_map(
static fn (): string => dirname(__DIR__. 2), "/vendor/yiisoft/rbac-cycle-db/migrations/$subfolder",
$migrationsSubfolders,
);
$config = new MigrationConfig([
'directory' => $directories[0],
// "vendorDirectories" are specified because "directory" option doesn't support multiple directories. In the end, it
Expand Down
8 changes: 4 additions & 4 deletions src/ItemTreeTraversal/MysqlItemTreeTraversal.php
Expand Up @@ -61,18 +61,18 @@ public function getParentRows(string $name): array

public function getHierarchy(string $name): array
{
$sql = "SELECT item.*, access_tree_base.children FROM (
$sql = "SELECT item.*, hierarchy_base.children FROM (
SELECT
child_name,
MIN(TRIM(BOTH '$this->namesSeparator' FROM TRIM(BOTH child_name FROM raw_children))) as children
FROM (
SELECT @r AS child_name, @path := concat(@path, '$this->namesSeparator', @r) as raw_children,
(SELECT @r := parent FROM $this->childrenTableName WHERE child = child_name LIMIT 1) AS parent
FROM (SELECT @r := :name, @path := '') val, $this->childrenTableName
) raw_access_tree_base
) raw_hierarchy_base
GROUP BY child_name
) access_tree_base
LEFT JOIN $this->tableName AS item ON item.name = access_tree_base.child_name
) hierarchy_base
LEFT JOIN $this->tableName AS item ON item.name = hierarchy_base.child_name
WHERE item.name IS NOT NULL";

/** @psalm-var Hierarchy */
Expand Down
22 changes: 7 additions & 15 deletions tests/Base/ManagerTest.php
Expand Up @@ -7,15 +7,14 @@
use Yiisoft\Rbac\AssignmentsStorageInterface;
use Yiisoft\Rbac\Cycle\TransactionalManagerDecorator;
use Yiisoft\Rbac\ItemsStorageInterface;
use Yiisoft\Rbac\Manager;
use Yiisoft\Rbac\ManagerInterface;
use Yiisoft\Rbac\RuleFactoryInterface;
use Yiisoft\Rbac\Tests\Common\ManagerConfigurationTestTrait;
use Yiisoft\Rbac\Tests\Support\SimpleRuleFactory;

abstract class ManagerTest extends TestCase
{
use ManagerConfigurationTestTrait;
use ManagerConfigurationTestTrait {
createManager as protected traitCreateManager;
}

protected function tearDown(): void
{
Expand All @@ -33,18 +32,11 @@ protected function populateDatabase(): void
protected function createManager(
?ItemsStorageInterface $itemsStorage = null,
?AssignmentsStorageInterface $assignmentsStorage = null,
?RuleFactoryInterface $ruleFactory = null,
?bool $enableDirectPermissions = false
): ManagerInterface {
$arguments = [
$itemsStorage ?? $this->createItemsStorage(),
$assignmentsStorage ?? $this->createAssignmentsStorage(),
$ruleFactory ?? new SimpleRuleFactory(),
];
if ($enableDirectPermissions !== null) {
$arguments[] = $enableDirectPermissions;
}

return new TransactionalManagerDecorator(new Manager(...$arguments), $this->getDatabase());
return new TransactionalManagerDecorator(
$this->traitCreateManager($itemsStorage, $assignmentsStorage, $enableDirectPermissions),
$this->getDatabase(),
);
}
}

0 comments on commit 19fd26c

Please sign in to comment.