【发布时间】:2021-06-05 02:49:51
【问题描述】:
我想创建一个用户个人资料片段,它加入撇号用户,以便管理员可以为特定用户制作公开个人资料。我知道不建议这样做,但我认为这是让这一方的人有可能拥有公共个人资料并能够登录和编辑他们的个人资料的唯一选择。否则,管理员需要为数百人更改用户配置文件,这将导致全职工作。现在不需要用户注册,但将来可能需要,所以我的模块应该与 apsotrophe-signup 兼容。
开头很简单:
// lib/modules/profiles/index.js
module.exports = {
extend: 'apostrophe-pieces',
name: 'profile',
label: 'Profile',
pluralLabel: 'Profiles',
slugPrefix: 'profile-',
addFields: [
{
name: '_user',
label: 'User',
type: 'joinByOne',
withType: 'apostrophe-user',
idField: 'userId',
withJoins: true
}
]
};
这是碎片小部件:
// lib/modules/profiles-widgets/views/widget.html
{% for piece in data.widget._pieces %}
<li class="collection-item avatar">
{{ piece._user.username }}
{{ piece._user.title }}
{{ piece._user.firstName }}
{{ piece._user.lastName }}
{{ piece._user.email }}
<img class="circle grey"
src="{{ apos.attachments.url(piece._user._thumbnail.attachment, { size: data.options.size or 'one-sixth' }) }}"
srcset="{{ apos.images.srcset(piece._user._thumbnail.attachment) }}"
sizes="{{ '8vw' }}"
alt="{{ piece._user._thumbnail.title }}"
>
{{ apos.area(piece._user, 'bio', { edit: false }) }}
</li>
{% endfor %}
我添加到apostrophe-user的字段_thumbnail和bio:
// lib/modules/apostrophe-users/index.js
module.exports = {
beforeConstruct: function(self, options) {
options.addFields = [
{
name: '_thumbnail',
type: 'joinByOne',
withType: 'apostrophe-image',
label: 'Profile Picture',
help: 'Choose profile picture',
filters: {
projection: {
attachment: true,
description: true,
title: true
}
}
},
{
name: 'bio',
label: 'Biography',
type: 'area',
help: 'Choose Biography',
options: {
limit: 1,
widgets: {
'apostrophe-rich-text': {
toolbar: [ 'Bold' ],
controls: {
movable: false,
cloneable: false,
removable: true,
position: 'top-right'
}
}
}
}
}
].concat(options.addFields || []);
}
};
登录后,我可以看到widget.html 中定义的所有字段,但是如果我退出,我什么也看不到。我预计这个原因 apostrophe-users 未由 default 发布。
我尝试将published 字段添加到apostrophe-user,但这没有成功。
// lib/modules/apostrophe-users/index.js
...
{
type: 'boolean',
name: 'published',
label: 'Published',
def: true,
},
...
我做错了什么?
作为第二个问题,我想知道是否可以允许登录用户编辑他自己的个人资料?
【问题讨论】:
标签: apostrophe-cms