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