如何在 Silverstripe 中为 public 网站和 CMS 设置 canView
How to set canView in Silverstripe for public website vs CMS
我们在 Silverstripe 项目中对我们的成员 class 进行了自定义扩展:
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
return false;
}
}
只有通过 $this->isPublished() == true
.
专门发布的会员详细信息才能查看
此方法一直运行良好,但最近升级到 Silverstripe 3.6.1 似乎已损坏。 CMS 管理员不能再创建新成员(returns 403/禁止错误)除非 canView 被覆盖为 "true":
public function canView($member = null) {
return true;
}
如何设置:
- 在public网站中会员详情只有在以下情况下才能查看
$this->isPublished() == true
- 在 CMS 中,用户可以查看所有会员详细信息
管理员权限。
提前致谢。
如果您在扩展程序中实现权限方法,您可以return以下任一方法:
true
: 授予权限
false
: 拒绝权限
null
:不影响权限(例如,其他扩展或 DataObject 的基本方法将发挥作用)
在您的情况下,returning false
似乎是错误的,因为如果不满足第一个条件,您将拒绝查看对象。这意味着,在这些情况下,管理员将无法看到 CMS 中的对象,而他显然应该看到。
正确的实现方式如下:
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
// fall back to default permissions
return null;
}
}
我们在 Silverstripe 项目中对我们的成员 class 进行了自定义扩展:
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
return false;
}
}
只有通过 $this->isPublished() == true
.
此方法一直运行良好,但最近升级到 Silverstripe 3.6.1 似乎已损坏。 CMS 管理员不能再创建新成员(returns 403/禁止错误)除非 canView 被覆盖为 "true":
public function canView($member = null) {
return true;
}
如何设置:
- 在public网站中会员详情只有在以下情况下才能查看
$this->isPublished() == true
- 在 CMS 中,用户可以查看所有会员详细信息 管理员权限。
提前致谢。
如果您在扩展程序中实现权限方法,您可以return以下任一方法:
true
: 授予权限false
: 拒绝权限null
:不影响权限(例如,其他扩展或 DataObject 的基本方法将发挥作用)
在您的情况下,returning false
似乎是错误的,因为如果不满足第一个条件,您将拒绝查看对象。这意味着,在这些情况下,管理员将无法看到 CMS 中的对象,而他显然应该看到。
正确的实现方式如下:
public function canView($member = null) {
if ($this->Link() && $this->isPublished()) {
return true;
} else {
// fall back to default permissions
return null;
}
}