How to access repo service in Share WebScript

cancel
Showing results for 
Search instead for 
Did you mean: 
mehar460
Active Member II

How to access repo service in Share WebScript

Jump to solution

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;
}
}

1 Solution

Accepted Solutions
mehar460
Active Member II

Re: How to access repo service in Share WebScript

Jump 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"

}

});

}

}

View solution in original post

3 Replies
mehe
Senior Member II

Re: How to access repo service in Share WebScript

Jump to solution

Alfresco share is a seperate Web-App so I think Mike Hatfield‌s answer to Cannot access Root Scope Objects in Share dashlet Web Script  also applies to your question

jpotts
Professional

Re: How to access repo service in Share WebScript

Jump to solution

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

mehar460
Active Member II

Re: How to access repo service in Share WebScript

Jump 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"

}

});

}

}