如何使用 Alfresco Javascript API 检索每个用户的组列表
我对 Alfresco 及其 Javascript API 完全陌生,所以请记住这一点...
我希望能够查看 Alfresco 存储库中每个用户的组列表。
这是我目前的代码:
var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
var logFile = space.childByNamePath("log_user_groups.csv");
if (logFile == null) {
logFile = space.createFile("log_user_groups.csv");
}
logFile.content = "";
for (var i=0; i<gens.length;i++) {
logFile.content += gens[i].properties["cm:userName"]+"\n";
var groupes= people.getContainerGroups(gens[i]);
for (var j=0; j<groupes.length;j++) {
logFile.content += "\t"+groupes[j].properties.shortName +"\t";
logFile.content += "\t"+groupes[j].properties.fullName +"\t";
logFile.content += "\t"+groupes[j].properties.displayName +"\n";
}
}
该文件是使用正确显示的用户名创建的。但是,组属性“shortName”、“fullName”和“displayName”均为空。事实上,我打印出了“groupes”对象的所有属性,并且该对象的每个字段都是“未定义”的。
有人知道我做错了什么吗?
任何帮助将不胜感激。
规范。
I'm totally new to Alfresco and their Javascript API so please bear that in mind...
I want to be able to view a list of groups for every user in Alfresco repository.
This is the code I have at the moment:
var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
var logFile = space.childByNamePath("log_user_groups.csv");
if (logFile == null) {
logFile = space.createFile("log_user_groups.csv");
}
logFile.content = "";
for (var i=0; i<gens.length;i++) {
logFile.content += gens[i].properties["cm:userName"]+"\n";
var groupes= people.getContainerGroups(gens[i]);
for (var j=0; j<groupes.length;j++) {
logFile.content += "\t"+groupes[j].properties.shortName +"\t";
logFile.content += "\t"+groupes[j].properties.fullName +"\t";
logFile.content += "\t"+groupes[j].properties.displayName +"\n";
}
}
The file is created with the user name shown correctly. However the group properties 'shortName', 'fullName' and 'displayName' are all null. In fact I printed out all the properties of the 'groupes' object and every field of the object is 'undefined'.
Does any body know what I am doing wrong?
Any help would be greatly appreciated.
Norm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法就是彻底改变它。相反,对于每个组,询问它包含哪些组和哪些用户。最后,将其翻转。
您需要从根组开始。 Alfresco 中的
groups
JS 对象将为您提供这些以及其他内容。它由 ScriptAuthorityService 实现,因此您可能需要查看 JavaDocs首先,获取根组
对于每个组,获取该组中的所有用户(直接用户和继承用户)
getAllUsers()
,并将它们存储在某处。现在,使用getChildGroups()
获取所有子组。以相同的方式处理每一个,并根据需要进行递归。The easiest way would be to turn it on its head. Instead, for each group ask what groups and what users it contains. At the end, invert it.
You'll want to start with the Root Groups. The
groups
JS object in Alfresco will give you these, and others. It's implemented byScriptAuthorityService
, so you'll likely want to look at the JavaDocsFirst up, get the root groups
For each group, get all the users in the group (direct and inherited) with
getAllUsers()
, and store those somewhere. Now, get all the child groups withgetChildGroups()
. Process each of these in the same way, recursing as needed.我需要类似的东西(完整的组列表),所以我这样做了:
这在一定程度上有效。问题是 getDisplayName() 返回一个非常不漂亮的组名称。通常,在处理文档并显示与用户关联的组名称时,我会执行 people.getContainerGroups() 并使用 group.properties["cm:authorityName"] 来获取可显示的名称(如上所述),但是我收到的组getAllRootGroups() 没有属性(group.properties 未定义)。
有谁知道为什么以这种方式返回的组列表不会具有与 people.getContainerGroups() 返回的属性相同的属性?
I needed something similar (a complete list of groups) so I did this:
This works to a point. The problem is that getDisplayName() returns a very non-pretty group name. Normally when dealing with documents and displaying a group name associated with a user I would do people.getContainerGroups() and use group.properties["cm:authorityName"] to get a displayable name (as mentioned above), however the groups I receive from getAllRootGroups() do not have properties (group.properties is undefined).
Does anyone have any idea why the group list returned this way wouldn't have the same properties as those returned by people.getContainerGroups()?
我猜您使用了错误的属性名称。
您需要以下信息:
groupes[j].properties["usr:authorityName"]
groupes[j].properties["usr:authorityDisplayName"]
groupes[j].properties["usr:authorityShortName"]
您也可以只获取 NodeRef id。
然后登录 Alfresco 浏览器。然后进入管理控制台-->节点浏览器
粘贴 id(它应该类似于
workspace://spacesStore //biglongUUID
)。在那里您可以看到与该组相关的所有属性。或者您可以循环
groupes[k].properties
映射并打印所有属性。I guess you're using the wrong properties name.
You need the following:
groupes[j].properties["usr:authorityName"]
groupes[j].properties["usr:authorityDisplayName"]
groupes[j].properties["usr:authorityShortName"]
You can also just get the NodeRef id.
Then login to Alfresco explorer. Then go to the administration console --> Node Browser
Paste the id (it should be something like
workspace://spacesStore//biglongUUID
).There you can see al the properties related to the group.Or you could just loop the
groupes[k].properties
map and print all the properties.