Skip to content

Commit

Permalink
allow isAdmin when its a module (#2027)
Browse files Browse the repository at this point in the history
* allow isAdmin when its a module

* allow module names only

* add see

* add changelog and version nuber
  • Loading branch information
nadar authored Jun 4, 2020
1 parent 937795a commit d3e0418
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
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

0 comments on commit d3e0418

Please sign in to comment.