10-05-2018 04:24 PM
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;
}
}
10-10-2018 04:38 PM
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"
}
});
}
}
10-07-2018 09:06 AM
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
10-10-2018 04:12 PM
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
10-10-2018 04:38 PM
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"
}
});
}
}
Explore our Alfresco products with the links below. Use labels to filter content by product module.