Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow isAdmin when its a module #2027

Merged
merged 5 commits into from
Jun 4, 2020
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
4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 1.4.1 (4. June 2020)

+ [#2027](https://github.com/luyadev/luya/pull/2027) Fixed regression with `luya\web\Request::$isAdmin` when working with admin module names like `newsadmin/default/index` (introduced in [#2019](https://github.com/luyadev/luya/issues/2019)).

## 1.4.0 (2. June 2020)

+ [#2019](https://github.com/luyadev/luya/issues/2019) The property `luya\web\Request::$isAdmin` is now more restrict and won't match admin modules like `newsadmin` which would have been evaulated as true before this change.
Expand Down
2 changes: 1 addition & 1 deletion core/base/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class Boot
/**
* @var string The current LUYA version (see: https://github.com/luyadev/luya/blob/master/core/CHANGELOG.md)
*/
const VERSION = '1.4.0';
const VERSION = '1.4.1';

/**
* @var string The path to the config file, which returns an array containing you configuration.
Expand Down
7 changes: 6 additions & 1 deletion core/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public function getIsAdmin()
$resolver = Yii::$app->composition->getResolvedPathInfo($this);
$parts = explode('/', $resolver->resolvedPath);
$first = reset($parts);
if (StringHelper::startsWith($first, 'admin')) {

// Check for a full route path where the module ends with admin like `newsadmin` and this module is loaded in the list of modules.
// @see https://github.com/luyadev/luya/pull/2027
if (count($parts) > 0 && StringHelper::endsWith($first, 'admin') && Yii::$app->hasModule($first))
$this->_isAdmin = true;
elseif (StringHelper::startsWith($first, 'admin')) {
$this->_isAdmin = true;
} else {
$this->_isAdmin = false;
Expand Down
4 changes: 3 additions & 1 deletion tests/core/web/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace luyatests\core\web;

use luya\admin\Module;
use Yii;
use luya\web\Request;

class RequestTest extends \luyatests\LuyaWebTestCase
{
public function testisAdmin()
{
$this->app->setModule('newsadmin', ['class' => Module::class]);
$request = new Request();
$request->forceWebRequest = true;
$request->pathInfo = 'admin/test/';
Expand All @@ -27,7 +29,7 @@ public function testisAdmin()
$request = new Request();
$request->forceWebRequest = true;
$request->pathInfo = 'newsadmin/foo/test/';
$this->assertEquals(false, $request->isAdmin);
$this->assertEquals(true, $request->isAdmin);

$request = new Request();
$request->forceWebRequest = true;
Expand Down