mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 11:33:55 +09:00
Remove member directive, and extend auth directive to look at grants
This commit is contained in:
parent
e044e11c5f
commit
d4654eb5cf
3 changed files with 25 additions and 8 deletions
|
|
@ -733,4 +733,22 @@ class Template
|
||||||
|
|
||||||
return sprintf(' %s="%s"', $attribute, escape(implode($delimiters[$attribute], $values), false));
|
return sprintf(' %s="%s"', $attribute, escape(implode($delimiters[$attribute], $values), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auth checker for v2.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function _v2_checkAuth(string $type = 'member'): bool
|
||||||
|
{
|
||||||
|
$grant = \Context::get('grant');
|
||||||
|
switch ($type)
|
||||||
|
{
|
||||||
|
case 'admin': return $this->user->isAdmin();
|
||||||
|
case 'manager': return $grant->manager ?? false;
|
||||||
|
case 'member': return $this->user->isMember();
|
||||||
|
default: return $grant->$type ?? false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,7 @@ class TemplateParser_v2
|
||||||
'unset' => ['if (!isset(%s)):', 'endif;'],
|
'unset' => ['if (!isset(%s)):', 'endif;'],
|
||||||
'empty' => ['if (empty(%s)):', 'endif;'],
|
'empty' => ['if (empty(%s)):', 'endif;'],
|
||||||
'admin' => ['if ($this->user->isAdmin()):', 'endif;'],
|
'admin' => ['if ($this->user->isAdmin()):', 'endif;'],
|
||||||
'auth' => ['if ($this->user->isMember()):', 'endif;'],
|
'auth' => ['if ($this->_v2_checkAuth(%s)):', 'endif;'],
|
||||||
'member' => ['if ($this->user->isMember()):', 'endif;'],
|
|
||||||
'guest' => ['if (!$this->user->isMember()):', 'endif;'],
|
'guest' => ['if (!$this->user->isMember()):', 'endif;'],
|
||||||
'desktop' => ['if (!$__Context->m):', 'endif;'],
|
'desktop' => ['if (!$__Context->m):', 'endif;'],
|
||||||
'mobile' => ['if ($__Context->m):', 'endif;'],
|
'mobile' => ['if ($__Context->m):', 'endif;'],
|
||||||
|
|
@ -495,7 +494,7 @@ class TemplateParser_v2
|
||||||
if (preg_match('#^end(.*)$#', $directive, $m))
|
if (preg_match('#^end(.*)$#', $directive, $m))
|
||||||
{
|
{
|
||||||
$stack = array_pop($this->_stack);
|
$stack = array_pop($this->_stack);
|
||||||
$directive = $m[1] ?: $stack['directive'];
|
$directive = $m[1] ?: ($stack ? $stack['directive'] : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle intermediate directives first.
|
// Handle intermediate directives first.
|
||||||
|
|
|
||||||
|
|
@ -746,20 +746,20 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
|
||||||
]);
|
]);
|
||||||
$this->assertEquals($target, $this->_parse($source));
|
$this->assertEquals($target, $this->_parse($source));
|
||||||
|
|
||||||
// @auth, @member and @guest
|
// @auth and @guest
|
||||||
$source = implode("\n", [
|
$source = implode("\n", [
|
||||||
'@auth',
|
'@auth',
|
||||||
'@member',
|
'@auth(\'manager\')',
|
||||||
'<p>Welcome back!</p>',
|
'<p>Welcome back!</p>',
|
||||||
'@endmember',
|
'@endauth',
|
||||||
'@end',
|
'@end',
|
||||||
'@guest',
|
'@guest',
|
||||||
'<p>Please join!</p>',
|
'<p>Please join!</p>',
|
||||||
'@endguest',
|
'@endguest',
|
||||||
]);
|
]);
|
||||||
$target = implode("\n", [
|
$target = implode("\n", [
|
||||||
'<?php if ($this->user->isMember()): ?>',
|
'<?php if ($this->_v2_checkAuth()): ?>',
|
||||||
'<?php if ($this->user->isMember()): ?>',
|
'<?php if ($this->_v2_checkAuth(\'manager\')): ?>',
|
||||||
'<p>Welcome back!</p>',
|
'<p>Welcome back!</p>',
|
||||||
'<?php endif; ?>',
|
'<?php endif; ?>',
|
||||||
'<?php endif; ?>',
|
'<?php endif; ?>',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue