【问题标题】:How to set canView in Silverstripe for public website vs CMS如何在 Silverstripe 中为公共网站与 CMS 设置 canView
【发布时间】:2017-08-02 02:55:36
【问题描述】:

我们在 Silverstripe 项目中的 Member 类上有一个自定义扩展:

public function canView($member = null) {
    if ($this->Link() && $this->isPublished()) {
        return true;
    } else {
        return false;
    }
}

因此,只有通过$this->isPublished() == true 专门发布的会员详细信息才能查看。

此方法一直运行良好,但最近升级到 Silverstripe 3.6.1 似乎破坏了它。 CMS 管理员不能再创建新成员(返回 403/Forbidden 错误),除非 canView 被覆盖为“true”:

public function canView($member = null) {
   return true;
}

我该如何设置它:

  1. 在公共网站上,只有在以下情况下才能查看会员详细信息 $this->isPublished() == true
  2. 在 CMS 中,用户可以通过以下方式查看所有成员详细信息 管理员权限。

提前谢谢你。

【问题讨论】:

    标签: php silverstripe


    【解决方案1】:

    如果您在 Extensions 中实现权限方法,则可以返回:

    • true : 授予权限
    • false : 拒绝权限
    • null : 不要影响权限(例如,其他扩展或 DataObject 的基本方法将发挥作用)

    在您的情况下,返回 false 似乎是错误的,因为如果不满足第一个条件,您将拒绝查看对象。这意味着,在这些情况下,管理员将无法看到 CMS 中的对象,而他显然应该这样做。

    实现这一点的正确方法是:

    public function canView($member = null) {
        if ($this->Link() && $this->isPublished()) {
            return true;
        } else {
            // fall back to default permissions
            return null;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多