apostrophe-cms - 模板数据权限

标签 apostrophe-cms

我一直在将事件注册者功能添加到我的撇号网站中。我创建了一个新的“领导者”组,如果用户属于该组,则事件页面应显示一个包含当前注册人数/基本信息的表格:

{% for reg in data.piece.registrants %}
    {% set count = count + reg.attendeeCount %}
      <tr>
        <td>{{reg._user.firstName}} {{reg._user.lastName}}</td>
        <td>{{reg.attendeeCount}}</td>
      </tr>
    {% endfor %}
    <tr class="total-registrant-row">
      <td>Total</td>
      <td></td>
      <td></td>
      <td>{{count}}</td>

我已向 apostrope-events 添加了一个 Registrants 数组,该数组本身包含对用户的单个连接:

addFields: [
    {
      name: 'registrants',
      label: 'Registrants',
      type: 'array',
      schema: [
          {
              name: '_user',
              withType: 'apostrophe-user',
              type: 'joinByOne',
              idField: 'userId',
              filters: {
                  // Fetch only basic information to show in table:
                  projection: {
                      id: 1,
                      username: 1,
                      firstName: 1,
                      lastName: 1,
                      email: 1
                  }
              }
          },
          {
              name: 'registrationDate',
              label: 'Registration Date',
              contextual: true,
              type: 'string'
          },
          {
              name: 'attendeeCount',
              label: 'Total Attendees',
              type: 'integer'
          }
       ]
    }
]

我注意到,当我以管理员身份登录时,这可以正常工作,但如果我以领导组中的用户(不是管理员)身份登录,则会显示计数,但不会显示用户信息。我假设这是因为领导组没有获得任何用户的权限。我该如何设置,以便模板在这种情况下绕过权限,或者授予领导者查看注册事件用户信息的权限?

谢谢!

最佳答案

您可以使用联接的 filters 属性来调用任何游标方法,包括 permission,您可以将其设置为 false 以允许不考虑当前用户的权限来获取用户:

filters: {
  // Fetch only basic information to show in table:
  projection: {
    id: 1,
    username: 1,
    firstName: 1,
    lastName: 1,
    email: 1
  },
  // Ignore permissions for this join:
  permission: false
}

```

关于apostrophe-cms - 模板数据权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45394938/

相关文章:

javascript - 从本地 Apostrope cms 代码连接到 Mongo Atlas

javascript - apostrope-images-widgets 自定义小部件调用 apos.attachments.url 两次

javascript - ApostropeCMS - 在快速 route 渲染完整的 HTML 页面

javascript - 撇号CKEditor表格单元格合并问题

node.js - 撇号 cms 中图像的默认值?

apostrophe-cms - 将后端数据注入(inject) View 以在客户端 JS 中使用

css - 通过管理 UI 显示 flex 小部件样式干扰

javascript - Apostrophe-pieces-pages 无法注册页面类型

apostrophe-cms - ApostropeJS 获取循环索引

javascript - 撇号 cms - 自定义页面设置