removePermission for all users/groups workaround

I take an ugly bug in removePermission JavaScript function of Alfresco 4.0.d Community Edition.

You can reproduce by this sample script:

var node = companyhome.childByNamePath("User Homes/louise");

permissions = node.getPermissions();
print("Before removePermission:");
print(permissions);

node.removePermission("Coordinator");

permissions = node.getPermissions();
print("After removePermission:");
print(permissions);

Results should be:

Before removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All
2 : ALLOWED;abeecher;Coordinator

After removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All
2 : ALLOWED;abeecher;Coordinator

Ok, don’t wait for 4.1, let see the workaround (removePermissionFromAll function):

var node = companyhome.childByNamePath("User Homes/louise");

permissions = node.getPermissions();
print("Before removePermission:");
print(permissions);

removePermissionFromAll(node, "Coordinator");
  
permissions = node.getPermissions();
print("After removePermission:");
print(permissions);

function removePermissionFromAll(node, roleName) {
    permissions = node.getPermissions();
    for(rpi=0;rpi

... and the better result:

Before removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All
2 : ALLOWED;abeecher;Coordinator

After removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All

And as a bonus track, see a simple script to remove "All" permissions in user home folders:

var node = companyhome.childByNamePath("User Homes");

var foldersInUserHomes = node.children;

for(i=0; i

Enable “remote” root object in Alfresco 3.4+

From the 3.3 version Alfresco is overriding the Spring Surf webscripts container bean removing the remote definition.

This modification also affects number of custom webscripts developed with previous releases. Let see, how to enable “remote” root object in current Alfresco installation;

1. Find your “web-scripts-application-context.xml” configuration file in alfresco webapp, or in shared classes.
2. Search for “webscripts.container”, and update “map” contents like this:


      Repository
      
         
           
              
           

           
           

         
      
...

3. Restart Alfresco server
4. Check custom configuration with following code:

var serviceUrl = (args.service === null) ? "/api/repository" : args.service;
var conn = remote.connect("alfresco");
var result = conn.get(stringUtils.urlEncodeComponent(serviceUrl));

Just another, non-remote solution: Nathan McMinn: Calling Web Services from the Alfresco Javascript API

ExtJS grid megjelenítési sebesség

Éppen egy jó kis dokumentum kezelő szoftveren dolgozunk és az ahhoz készült repository browser (azaz a tárolt node-ok megtekintéséhez készült általános felület) sebességét lestem meg több böngészőben.

A gép egy 2.4GHz-es Apple MacBook Pro, 4GB memóriával, a versenyzők pedig:

  • Mozilla FireFox v3.6.9
  • Apple Safari v5.0.2
  • Google Chrome v5.0.375

Ahogy a bal alsó sarokban látható, az 1000 rekord méretű JavaScript grid megjelenésében – a mért időben a request/response is benne van, az nagyjából megegyezik minden böngészőnél, kb. 900ms – a Safari a leggyorsabb (3586ms), a második a Chrome (4004ms) és leghátul a Firefox (5826ms) kullog. A méréseket többször elvégeztem egymás után a különbségek szinte minden esetben ugyanekkorák voltak.

Content transform webscript for Alfresco

You can find a simple content transform webscript for Alfresco here.

It’s looks like a working example, but points some shameless Alfresco bugs:

  • – an unhandled DuplicateChildNodeNameException received when a target node name already exists, not just a null return
  • – when a transformation error presents – transformDocument or transformImage returns with null – output node with new name already created, and contains the content of the source node
  • – transformation requires an installed, and configured OpenOffice.org in Alfresco;
    INFO [alfresco.util.OpenOfficeConnectionTester] The OpenOffice connection was re-established.
    but the relaunch of – an exited – OOo is not works, just avoid upcoming transformation processes;
    ERROR [alfresco.util.OpenOfficeConnectionTester] The OpenOffice connection has been lost.

Content transform GUI

Source code for the content transform webscript

transform.get.desc.xml (descriptor):


  Transform and get content as an URL
  Transform and get transformed content as a downloadable URL
  /extalf/transform?{nodeRef=nodeRef}&{mimetype=mimetype}
  argument
  user
  required

transform.get.js (javascript runtime code):

/*
 Content transform and presents it's URL to download
 @author: louise@louise.hu
 
 Parameters:
  - nodeRef: nodeRef of the source content node
  - mimetype: mimetype to transform source content
 */

var node = search.findNode(args.nodeRef);
var outputFolder = node.parent;

if (node == null) {
	model.errorCode = "1";
	model.errorMessage = "The content node could not be found";
}
else {
	// Transform content
	var m = node.mimetype;
	if (m.substr(0, 5) == "image") {
		// transform an image
		var transformed = node.transformImage(args.mimetype, outputFolder);
	} else {
		// transform a document
		var transformed = node.transformDocument(args.mimetype, outputFolder);
	}
	
	if (transformed == null) {
		model.errorCode = "2";
		model.errorMessage = "Unable to transform content";
		
		// TODO: alfresco 3.0 bug exists here, the target node already
		// created, but contains the source node's content :(
	}
	else {
		// return with the transformed node
		model.node = transformed;
	}
}

transform.get.json.ftl (FreeMarker template for output):

<#setting locale="en_US">
[
<#if node?? >
{
"success":"true",
"name":"${node.name?js_string}",
"nodeRef":"${node.nodeRef}",
"qnamePath":"${node.qnamePath}",
"store_type":"${node.nodeRef.storeRef.protocol}",
"store_id":"${node.nodeRef.storeRef.identifier}",
"id":"${node.nodeRef.id}",
"downloadUrl":"${node.downloadUrl}"
}
<#else>
{
"success":"false"
<#if errorCode?? >
, "error":"${errorCode}"

<#if errorMessage?? >
, "message":"${errorMessage?js_string}"

}

]

Alfresco forum: Transform content bugs

Collaborative Editor for Alfresco

I’m working on a new, unique collaborative editor for Alfresco (ExtJS interface), with following features:
   – task/workflow based editing trigger
   – individual chapter based editing
   – automatic chapter content creation
   – WYSWYG and form based editor
   – one click version change (back for previous version of chapter)
   – one click task close process update and forward to another user
   – preview support for all chapters and complete document
   – automatic versioning (checkin, checkout, cancel)
   – multi-user editing support
   – forum support for document changes and discussion

This editor is part of TenderWorks (eProcurement, eTendering engine) development project.

Simple browser for Alfresco

I’ve made a simple content and hierarchy browser for Alfresco – using the WebScript interface – inspired by Dr. Q’s Dead Simple UI (just try the iPhone Navigator too). This is a really quick browser, but has got a quick search input on the left-top corner. That’s all, no more.

Installation:
1. Download louise-folder.zip to your local storage
2. Login to Alfresco, navigate into Company Home/Data Dictionary/Web Scripts Extensions space and select Import from Administration Console menu
3. Import the downloaded zip file (import script will unpack into the space)
4. Load the service browser by link http://127.0.0.1:8080/alfresco/service/
5. Click on Refresh list of Web Script button to register new service
6. Start browsing on this startup URL: http://127.0.0.1:8080/alfresco/service/louise/folder/Company%20Home/

Download: louise-folder.zip