Lucene 查询过滤器不起作用
lucene query filter not working
我在 Auth0 Delegated Administration Extension.
中使用这个 filter hook
function(ctx, callback) {
// Get the company from the current user's metadata.
var company = ctx.request.user.app_metadata && ctx.request.user.app_metadata.company;
if (!company || !company.length) {
return callback(new Error('The current user is not part of any company.'));
}
// The GREEN company can see all users.
if (company === 'GREEN') {
return callback();
}
// Return the lucene query.
return callback(null, 'app_metadata.company:"' + company + '"');
}
公司为GREEN
的用户登录后可以看到所有用户。但是当公司为RED
的用户登录时,看不到任何公司为RED
的用户。
我需要在用户登录时做这个,用户应该只能访问他公司内的用户。 (GREEN公司用户除外)
但是上面的代码没有给出预期的结果。可能是什么问题?
这可能与 User Search documentation page
上的一个小警告说明有关
基本上他们不再让您在 app_metadata
字段中搜索属性。不幸的是,此更改是中断的且未经宣布。
我们必须对 API 进行更改,以便我们在单独的数据库中保留 app_metadata
的副本并将 lucene 语法转换为 MongoDB 查询,这样我们可以通过 user_id:"<>" OR user_id:"<>" OR ...
.
链查询
但请注意,您不能传递超过 72 user_id
秒的查询。这个数字到目前为止没有记录并且是根据经验获得的。
此外,您不能依赖 Auth0 的挂钩将新用户添加到您的数据库,因为这些挂钩不会针对社交登录触发,只会针对 Username-Password-Authentication
连接。
我希望这能给您一些解释,说明为什么它不起作用以及可能的解决方案。
如果我是你,我会寻找 Auth0 的替代品,这就是我们目前正在做的事情。
我终于找到了这个解决方案。
使用搜索功能来过滤用户。我不得不更改以下两个文件。
fetchUsers
client\actions\user.js
函数
已更改
export function fetchUsers(search = '', reset = false, page = 0)
至
export function fetchUsers(search = '@red.com', reset = false,
page = 0)
和
onReset
client\containers\Users\Users.jsx
中的函数
已更改
onReset = () => { this.props.fetchUsers('', true); }
至
onReset = () => { this.props.fetchUsers('@red.com', true); }
我在 Auth0 Delegated Administration Extension.
中使用这个filter hook
function(ctx, callback) {
// Get the company from the current user's metadata.
var company = ctx.request.user.app_metadata && ctx.request.user.app_metadata.company;
if (!company || !company.length) {
return callback(new Error('The current user is not part of any company.'));
}
// The GREEN company can see all users.
if (company === 'GREEN') {
return callback();
}
// Return the lucene query.
return callback(null, 'app_metadata.company:"' + company + '"');
}
公司为GREEN
的用户登录后可以看到所有用户。但是当公司为RED
的用户登录时,看不到任何公司为RED
的用户。
我需要在用户登录时做这个,用户应该只能访问他公司内的用户。 (GREEN公司用户除外)
但是上面的代码没有给出预期的结果。可能是什么问题?
这可能与 User Search documentation page
上的一个小警告说明有关基本上他们不再让您在 app_metadata
字段中搜索属性。不幸的是,此更改是中断的且未经宣布。
我们必须对 API 进行更改,以便我们在单独的数据库中保留 app_metadata
的副本并将 lucene 语法转换为 MongoDB 查询,这样我们可以通过 user_id:"<>" OR user_id:"<>" OR ...
.
但请注意,您不能传递超过 72 user_id
秒的查询。这个数字到目前为止没有记录并且是根据经验获得的。
此外,您不能依赖 Auth0 的挂钩将新用户添加到您的数据库,因为这些挂钩不会针对社交登录触发,只会针对 Username-Password-Authentication
连接。
我希望这能给您一些解释,说明为什么它不起作用以及可能的解决方案。
如果我是你,我会寻找 Auth0 的替代品,这就是我们目前正在做的事情。
我终于找到了这个解决方案。
使用搜索功能来过滤用户。我不得不更改以下两个文件。
fetchUsers
client\actions\user.js
已更改
export function fetchUsers(search = '', reset = false, page = 0)
至
export function fetchUsers(search = '@red.com', reset = false, page = 0)
和
onReset
client\containers\Users\Users.jsx
已更改
onReset = () => { this.props.fetchUsers('', true); }
至
onReset = () => { this.props.fetchUsers('@red.com', true); }