When I am using people object in Share Webscript received below error.
ReferenceError: people is not defined alfresco
My requirement is to display few navigation links if user is part of a group. Below is the code snippet.
var node = people.getGroup("<some_group>");
if(node)
{
var members = people.getMembers(node, true);
for(i=0; i< members.length; i++)
{
if(name.toUpperCase() == members[i].properties.userName.toUpperCase())
{
var headerMenu = widgetUtils.findObject(model.jsonModel, "id", "HEADER_APP_MENU_BAR");
if (headerMenu != null) {
headerMenu.config.widgets.push({
id: "HEADER_USER_TRASH_CAN",
name: "alfresco/menus/AlfMenuBarItem",
config: {
label: "My Trash Can",
targetUrl: "user/" + encodeURIComponent(user.name) + "/user-trashcan"
}
});
}
}
break;
}
}
Solved! Go to Solution.
Hello Jeff,
Glad you replied.
I have figured out, below is the code snippet used and is working.
var name = encodeURIComponent(user.name);
var connector = remote.connect("alfresco-api");
var data =
connector.get("/-default-/public/alfresco/versions/1/people/"name"/groups");
var isGateKeeper = false;
if(data.status == 200){
var result = eval('(' + data + ')');
var count = result.list.pagination.count;
for(i=0; i < count; i++)
{
if(result.list.entries[0].entry.id == "GROUP_gate-keeper")
{
isGateKeeper = true;
break;
}
}
}
if(isGateKeeper && !user.isAdmin){
var headerMenu = widgetUtils.findObject(model.jsonModel, "id",
"HEADER_APP_MENU_BAR");
if (headerMenu != null) {
headerMenu.config.widgets.push({
id: "HEADER_USER_TRASH_CAN",
name: "alfresco/menus/AlfMenuBarItem",
config: {
label: "My Trash Can",
targetUrl: "user/" + name + "/user-trashcan"
}
});
}
}
Alfresco share is a seperate Web-App so I think Mike Hatfields answer to Cannot access Root Scope Objects in Share dashlet Web Script also applies to your question
The web script framework has a built-in mechanism for calling other rest APIs. The root object is called "remote". The framework can connect to any system, even non-Alfresco systems, but, by default, it connects to the Alfresco repo tier.
So, you can do something like:
response = remote.call("/some/webscript");
And that will invoke a web script on the repo tier that has a URL of "/alfresco/service/some/webscript".
You can check response.status for the response code and you can parse the response into a JavaScript object as needed.
For a list of the Alfresco repository tier web scripts, take a look at http://localhost:8080/alfresco/service/index
Hello Jeff,
Glad you replied.
I have figured out, below is the code snippet used and is working.
var name = encodeURIComponent(user.name);
var connector = remote.connect("alfresco-api");
var data =
connector.get("/-default-/public/alfresco/versions/1/people/"name"/groups");
var isGateKeeper = false;
if(data.status == 200){
var result = eval('(' + data + ')');
var count = result.list.pagination.count;
for(i=0; i < count; i++)
{
if(result.list.entries[0].entry.id == "GROUP_gate-keeper")
{
isGateKeeper = true;
break;
}
}
}
if(isGateKeeper && !user.isAdmin){
var headerMenu = widgetUtils.findObject(model.jsonModel, "id",
"HEADER_APP_MENU_BAR");
if (headerMenu != null) {
headerMenu.config.widgets.push({
id: "HEADER_USER_TRASH_CAN",
name: "alfresco/menus/AlfMenuBarItem",
config: {
label: "My Trash Can",
targetUrl: "user/" + name + "/user-trashcan"
}
});
}
}
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.